Skip to content
Browse files

first code dump

  • Loading branch information...
0 parents commit b22513734a8e0ccf5f88e407cfdc46427cfb9983 @cyberdelia committed Feb 7, 2012
Showing with 108 additions and 0 deletions.
  1. +21 −0 LICENSE
  2. +24 −0 README.md
  3. +35 −0 metadata.py
  4. +28 −0 setup.py
21 LICENSE
@@ -0,0 +1,21 @@
+Metadata
+--------
+Copyright (©) 2012 Timothée Peignier <timothee.peignier@tryphon.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
24 README.md
@@ -0,0 +1,24 @@
+# Metadata for humans
+
+Metadata extract metadata from files, without having to deal with exotic library compilation, complex API or multiple libraries. Give Metadata a file and it will return a dictionnary with your precious metadata.
+
+ >>> from metadata import extract
+ >>> metadata = extract(file)
+ >>> metadata.get('creation_date')
+ datetime.datetime(2010, 9, 28, 7, 51, 8)
+ >>> metadata.get('title')
+
+
+## Features
+
+Extract metadata from almost any kind of files : video, music and other.
+
+## Installation
+
+To install metadata, use pip :
+
+ $ pip install metadata
+
+## Acknowledgement
+
+Metadata uses [hachoir](http://hachoir.org) behind the scenes.
35 metadata.py
@@ -0,0 +1,35 @@
+from hachoir_core.cmd_line import unicodeFilename
+from hachoir_core.error import HachoirError
+from hachoir_core.stream import InputIOStream
+from hachoir_metadata import extractMetadata
+from hachoir_parser import guessParser
+
+
+__all__ = ['MetadataException', 'extract']
+
+
+class MetadataException(Exception):
+ pass
+
+
+class Metadata(dict):
+ def __init__(self, file):
+ data = dict([
+ (data.key, data.values[0].value)
+ for data in self.extract_metadata(file)
+ if data.values
+ ])
+ super(Metadata, self).__init__(data)
+
+ def extract_metadata(self, file):
+ try:
+ filename = unicodeFilename(file.name)
+ stream = InputIOStream(file, source="file:%s" % filename, tags=[], filename=filename)
+ parser = guessParser(stream)
+ return extractMetadata(parser)
+ except (HachoirError, TypeError) as e:
+ raise MetadataException(e)
+
+
+def extract(file):
+ return Metadata(file)
28 setup.py
@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+from setuptools import setup, find_packages
+
+
+setup(
+ name='metadata',
+ version='0.1',
+ description='Metadata for Humans',
+ long_description="""Metadata extract metadatas from files.""",
+ author='Timothée Peignier',
+ author_email='timothee.peignier@tryphon.org',
+ url='https://github.com/cyberdelia/metadata',
+ packages=find_packages(),
+ install_requires=[
+ 'hachoir-core==1.3.3',
+ 'hachoir-metadata==1.3.3',
+ 'hachoir-parser==1.3.4',
+ ],
+ zip_safe=False,
+ include_package_data=True,
+ classifiers=[
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: MIT License',
+ 'Operating System :: OS Independent',
+ 'Programming Language :: Python',
+ 'Topic :: Utilities',
+ ]
+)

0 comments on commit b225137

Please sign in to comment.
Something went wrong with that request. Please try again.