For Ubuntu:
sudo apt-get -y install build-essential python-dev libevent-dev python-pip liblzma-dev
Showing posts with label python. Show all posts
Showing posts with label python. Show all posts
Monday, December 8, 2014
Tuesday, December 2, 2014
python hachoir Library for Media Metadata Extraction
In case if you want to extract metadata from a media file, python's hachoir library will be a handy tool for same. You may find the initial start-up material from here
You need to download following three packages:
running "setup.py install" command on windows will automatically put these libraries inside python Libs site-packages folder so that they immediately become available and you may run the command like "from hachoir_core.error import HachoirError" on python terminal
Download and install everything from here:
Copy following code in a python file and run it to see in action:
from hachoir_core.error import HachoirError
from hachoir_core.cmd_line import unicodeFilename
from hachoir_parser import createParser
from hachoir_core.tools import makePrintable
from hachoir_metadata import extractMetadata
from hachoir_core.i18n import getTerminalCharset
from sys import argv, stderr, exit
if len(argv) != 2:
print >>stderr, "usage: %s filename" % argv[0]
exit(1)
filename = argv[1]
filename, realname = unicodeFilename(filename), filename
parser = createParser(filename, realname)
if not parser:
print >>stderr, "Unable to parse file"
exit(1)
try:
metadata = extractMetadata(parser)
except HachoirError, err:
print "Metadata extraction error: %s" % unicode(err)
metadata = None
if not metadata:
print "Unable to extract metadata"
exit(1)
text = metadata.exportPlaintext()
charset = getTerminalCharset()
for line in text:
print makePrintable(line, charset)
Result:
- https://pypi.python.org/pypi/hachoir-metadata/1.3.3
- https://bitbucket.org/haypo/hachoir/wiki/hachoir-metadata
You need to download following three packages:
- hachoir_core
- hachoir_parser
- hachoir_metadata
running "setup.py install" command on windows will automatically put these libraries inside python Libs site-packages folder so that they immediately become available and you may run the command like "from hachoir_core.error import HachoirError" on python terminal
Download and install everything from here:
Copy following code in a python file and run it to see in action:
from hachoir_core.error import HachoirError
from hachoir_core.cmd_line import unicodeFilename
from hachoir_parser import createParser
from hachoir_core.tools import makePrintable
from hachoir_metadata import extractMetadata
from hachoir_core.i18n import getTerminalCharset
from sys import argv, stderr, exit
if len(argv) != 2:
print >>stderr, "usage: %s filename" % argv[0]
exit(1)
filename = argv[1]
filename, realname = unicodeFilename(filename), filename
parser = createParser(filename, realname)
if not parser:
print >>stderr, "Unable to parse file"
exit(1)
try:
metadata = extractMetadata(parser)
except HachoirError, err:
print "Metadata extraction error: %s" % unicode(err)
metadata = None
if not metadata:
print "Unable to extract metadata"
exit(1)
text = metadata.exportPlaintext()
charset = getTerminalCharset()
for line in text:
print makePrintable(line, charset)
Result:
Monday, December 1, 2014
python built-in Web Server
The SimpleHTTPServer module that comes with Python is a simple HTTP server that
provides standard GET and HEAD request handlers.
To start a HTTP server on port 8000 (which is the default port), simply type:
python -m SimpleHTTPServer [port]
An advantage with the built-in HTTP server is that you don't have to install and configure anything. The only thing that you need, is to have Python installed. That makes it perfect to use when you need a quick web server running and you don't want to mess with setting up apache. You can use this to turn any directory in your system into your web server directory.
As long as the HTTP server is running, the terminal will update as data are loaded from the Python web server. You should see standard http logging information (GET and PUSH), 404 errors, IP addresses, dates, times, and all that you would expect from a standard http log as if you were tailing an apache access log file.
provides standard GET and HEAD request handlers.
To start a HTTP server on port 8000 (which is the default port), simply type:
python -m SimpleHTTPServer [port]
An advantage with the built-in HTTP server is that you don't have to install and configure anything. The only thing that you need, is to have Python installed. That makes it perfect to use when you need a quick web server running and you don't want to mess with setting up apache. You can use this to turn any directory in your system into your web server directory.
As long as the HTTP server is running, the terminal will update as data are loaded from the Python web server. You should see standard http logging information (GET and PUSH), 404 errors, IP addresses, dates, times, and all that you would expect from a standard http log as if you were tailing an apache access log file.
Sunday, November 30, 2014
Installing Mutagen
As you have seen in previous post that it has used mutagen library for parsing mp3 and reading ID3 tags. Another powerful library for same purpose is eyed3 but relatively difficult to use in a Windows environment therefore mutagen was obvious choice.
I performed following steps to use mutagen in my python codes:
1. Downloaded latest tarball from lazka
2. Unzipped it and went inside to the folder ..\mutagen-1.27\dist\mutagen-1.27\mutagen-1.27 where I found setup.py
3. Made sure that python is available in system path env variable in windows
4. Build it with the command = python setup.py build
5. After build it created a build folder under ..\mutagen-1.27\dist\mutagen-1.27\mutagen-1.27 directory, inside which there was a lib folder and inside which I found the compiled mutagen folder structure.
6. Copied this mutagen folder structure inside ../build/libs directly into c:\python27 directory
7. Tried to execute the following code that went successful after the steps above:
from mutagen.id3 import ID3
audio_file_location = "audioFiles/Sleep Away.mp3"
audio_handler = ID3(audio_file_location)
print (audio_handler['TIT2'][0] )
Resources:
I performed following steps to use mutagen in my python codes:
1. Downloaded latest tarball from lazka
2. Unzipped it and went inside to the folder ..\mutagen-1.27\dist\mutagen-1.27\mutagen-1.27 where I found setup.py
3. Made sure that python is available in system path env variable in windows
4. Build it with the command = python setup.py build
5. After build it created a build folder under ..\mutagen-1.27\dist\mutagen-1.27\mutagen-1.27 directory, inside which there was a lib folder and inside which I found the compiled mutagen folder structure.
6. Copied this mutagen folder structure inside ../build/libs directly into c:\python27 directory
7. Tried to execute the following code that went successful after the steps above:
from mutagen.id3 import ID3
audio_file_location = "audioFiles/Sleep Away.mp3"
audio_handler = ID3(audio_file_location)
print (audio_handler['TIT2'][0] )
Resources:
- https://wiki.python.org/moin/UsefulModules
- https://mutagen.readthedocs.org/en/latest/api/id3.html
- https://mutagen.readthedocs.org/en/latest/tutorial.html
- http://pymedia.org/tut/
- http://id3.org/id3v2.4.0-structure
- http://id3.org/id3guide
Subscribe to:
Posts (Atom)


