I am looking forward to the solution for following problems:
1. How to read an audio file and determine what all metadata is available in what all standard and non-standard metadata formats like determining whether ID3 metadata is present or not, FLAC is present or not. I have seen that mediaInfo tool brings lot of information and I was not sure how it is pulling information like bit-rate , audio tracks resolution etc.
2. How do I know what all ID3 metadata frames are available in an audio file. My previous code just randomly check for few standard metadata and confirm the presence of same, but what if there are more metadata is available in the audio file. Also need to learn the name of all different id3 frames.
3. There are visual ID3 tools are available like:
ID3 sync - http://id3.software.informer.com/download-id3-tag-browser/
Perry's ID3 Tag Viewer - http://glassocean.net/perrys-id3-tag-viewer/
4. Apart from python, a great php code is available here
http://www.script-tutorials.com/id3-tags-reader-with-php/
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
Reading ID3 tags using python
A server-side python code that is still under progress:
#! "C:/Python27/python.exe"
# -*- coding: UTF-8 -*-
# enable debugging
from mutagen.id3 import ID3, TIT2
print """Content-Type: text/html\n\n"""
print """<!DOCTYPE html><html><head><title>Python Programming on Server-side</title></head><body><h1>Music Album Details</h1>"""
audio_file_location = "audioFiles/Sleep Away.mp3"
audio_handler = ID3(audio_file_location)
print ("Work Title : " + audio_handler['TIT2'][0] + "\n" )
print """<br />"""
print ("Track Number : " + audio_handler['TRCK'][0] +"\n")
print """<br />"""
print ("Album Name 1: " +audio_handler['TALB'][0] +"\n")
print """<br />"""
print ("Year of Recording : " +audio_handler['TDRC'][0] +"\n")
print """<br />"""
print ("DDMM Recording: " +audio_handler['TDAT'][0] +"\n")
print """<br />"""
print ("Encoded By : " +audio_handler['TENC'][0] +"\n")
print """<br />"""
print ("Comments : " +audio_handler['COMM'][0] +"\n")
print """<br />"""
print ("Artist Name : " + audio_handler['TPE1'][0] + "\n")
print """<br />"""
print ("Genre Name : " +audio_handler['TCON'][0] +"\n")
print """<br />"""
print ("Copyright : " +audio_handler['TCOM'][0] +"\n")
audio_handler.add(TIT2(encoding=3, text=u"test"))
audio_handler.add(TPE1(text=u"test"))
audio_handler.save()
print """</body></html>"""
#! "C:/Python27/python.exe"
# -*- coding: UTF-8 -*-
# enable debugging
from mutagen.id3 import ID3, TIT2
print """Content-Type: text/html\n\n"""
print """<!DOCTYPE html><html><head><title>Python Programming on Server-side</title></head><body><h1>Music Album Details</h1>"""
audio_file_location = "audioFiles/Sleep Away.mp3"
audio_handler = ID3(audio_file_location)
print ("Work Title : " + audio_handler['TIT2'][0] + "\n" )
print """<br />"""
print ("Track Number : " + audio_handler['TRCK'][0] +"\n")
print """<br />"""
print ("Album Name 1: " +audio_handler['TALB'][0] +"\n")
print """<br />"""
print ("Year of Recording : " +audio_handler['TDRC'][0] +"\n")
print """<br />"""
print ("DDMM Recording: " +audio_handler['TDAT'][0] +"\n")
print """<br />"""
print ("Encoded By : " +audio_handler['TENC'][0] +"\n")
print """<br />"""
print ("Comments : " +audio_handler['COMM'][0] +"\n")
print """<br />"""
print ("Artist Name : " + audio_handler['TPE1'][0] + "\n")
print """<br />"""
print ("Genre Name : " +audio_handler['TCON'][0] +"\n")
print """<br />"""
print ("Copyright : " +audio_handler['TCOM'][0] +"\n")
audio_handler.add(TIT2(encoding=3, text=u"test"))
audio_handler.add(TPE1(text=u"test"))
audio_handler.save()
print """</body></html>"""
Following resources were useful while writing this code:
A python file that executes on the server-side
#! "C:/Python27/python.exe"
print "Content-Type: text/html\n"
print "Hello cgi!"
Note that :
1. shebang operator pointing to the python installation is necessary, if not provided you will see error something like shown below in Apache logs
[Mon Dec 01 01:00:56.068334 2014] [win32:error] [pid 1536:tid 840] [client 127.0.0.1:49361] AH02102: C:/wamp/www/python/test2.py is not executable; ensure interpreted scripts have "#!" or "'!" first line
[Mon Dec 01 01:00:56.068334 2014] [cgi:error] [pid 1536:tid 840] (9)Bad file descriptor: [client 127.0.0.1:49361] AH01222: don't know how to spawn child process: C:/wamp/www/python/test2.py
2. \n in the content type declaration, if not provided you will see an error like below in Apache logs
[Mon Dec 01 00:54:34.997014 2014] [cgi:error] [pid 1536:tid 840] [client 127.0.0.1:49210] malformed header from script 'test2.py': Bad header: Hello cgi!
3. Note that this file need to be placed in the same directory that you have enabled for cgi execution in previous blog post and it need to be called with the URL as: http://localhost/python/testing.py
print "Content-Type: text/html\n"
print "Hello cgi!"
Note that :
1. shebang operator pointing to the python installation is necessary, if not provided you will see error something like shown below in Apache logs
[Mon Dec 01 01:00:56.068334 2014] [win32:error] [pid 1536:tid 840] [client 127.0.0.1:49361] AH02102: C:/wamp/www/python/test2.py is not executable; ensure interpreted scripts have "#!" or "'!" first line
[Mon Dec 01 01:00:56.068334 2014] [cgi:error] [pid 1536:tid 840] (9)Bad file descriptor: [client 127.0.0.1:49361] AH01222: don't know how to spawn child process: C:/wamp/www/python/test2.py
2. \n in the content type declaration, if not provided you will see an error like below in Apache logs
[Mon Dec 01 00:54:34.997014 2014] [cgi:error] [pid 1536:tid 840] [client 127.0.0.1:49210] malformed header from script 'test2.py': Bad header: Hello cgi!
3. Note that this file need to be placed in the same directory that you have enabled for cgi execution in previous blog post and it need to be called with the URL as: http://localhost/python/testing.py
Executing Python Code on Server-Side
Just like php, or perl , python can also be executed on the server-side.
Install Apache (I generally use WAMP for Apache), install python, find the correct mod_wsgi depending upon your Python version, apache version and OS arch from here
Now, you need to insert following configuration in your httpd.conf file of Apache and restart the apache
## Following change need to be done after all LoadModule
LoadModule wsgi_module modules/mod_wsgi.so
#at the end of the file add following directive
<Directory "C:/wamp/www/python/">
Options ExecCGI
SetHandler cgi-script
</Directory>
this directive will tell Apache to consider the given directory for cgi execution, all python files need to be present in this directory in order to be executed rather than being spit out by the web-server.
Install Apache (I generally use WAMP for Apache), install python, find the correct mod_wsgi depending upon your Python version, apache version and OS arch from here
Now, you need to insert following configuration in your httpd.conf file of Apache and restart the apache
## Following change need to be done after all LoadModule
LoadModule wsgi_module modules/mod_wsgi.so
#at the end of the file add following directive
<Directory "C:/wamp/www/python/">
Options ExecCGI
SetHandler cgi-script
</Directory>
this directive will tell Apache to consider the given directory for cgi execution, all python files need to be present in this directory in order to be executed rather than being spit out by the web-server.
Tuesday, November 25, 2014
Docker Issue - Cannot Start Container
While working with Docker have stuck on a machine where following message was encountered -
Error response from daemon: Cannot start container 1fd512be54352c4c14c49d01e910b5e71f523265e9117efaa4eff7f633b919b9: write /cgroup/cpu/docker/1fd512be54352c4c14c49d01e910b5e71f523265e9117efaa4eff7f633b919b9/cgroup.procs: invalid argument
Steps that we were trying while got this error:
1. docker pull busybox
2. docker run -i -t busybox echo Hello
resulted into the error quoted above
Tried on another CentOS 6.6 machine where on executing the same steps we didn't get this error.
Only difference that we were able to spot was the difference of Kernel version.
Kernel version where the issue was seen = Linux gsehgal-centos 2.6.32-279.el6.x86_64 #1 SMP Fri Jun 22 12:19:21 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
Kernel version where this issue was not seen = Linux no1010042129196.corp.adobe.com 2.6.32-504.1.3.el6.x86_64 #1 SMP Tue Nov 11 17:57:25 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
Error response from daemon: Cannot start container 1fd512be54352c4c14c49d01e910b5e71f523265e9117efaa4eff7f633b919b9: write /cgroup/cpu/docker/1fd512be54352c4c14c49d01e910b5e71f523265e9117efaa4eff7f633b919b9/cgroup.procs: invalid argument
Steps that we were trying while got this error:
1. docker pull busybox
2. docker run -i -t busybox echo Hello
resulted into the error quoted above
Tried on another CentOS 6.6 machine where on executing the same steps we didn't get this error.
Only difference that we were able to spot was the difference of Kernel version.
Kernel version where the issue was seen = Linux gsehgal-centos 2.6.32-279.el6.x86_64 #1 SMP Fri Jun 22 12:19:21 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
Kernel version where this issue was not seen = Linux no1010042129196.corp.adobe.com 2.6.32-504.1.3.el6.x86_64 #1 SMP Tue Nov 11 17:57:25 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
Creating and Posting Docker Images
Easy Steps to follow:
I performed these steps to download a CentOS image - > Installed Cassandra -> Posted to my public repository after tagging -
1. Execute - "docker images" - to check what all images you have available in your local docker repository
2. Now, pull or download the docker repository for your base OS
docker pull centos:latest
docker pull centos:centos6 (in case you need version 6)
3. again run the docker images command and check that the image is now available locally, note down the image-ID
4. Create the Docker container with the run command and specify the bash shell to be executed on completion. This will leave us with a bash session which we can use the customise the image.
5. Replace the ad892dd21d60 ID with the ID of the image we downloaded in the previous step.
- $ docker run -i -t ad892dd21d60 /bin/bash
- root@3a09b2588478:/#
6. docker ps -a will show all the available container in your local docker repo
7. Let's use container ID 3a09b2588478 for the rest of this example but yours will be a different ID.
$ docker start 3a09b2588478
We can now attach to the container to create a shell where we can make our modifications.
$ docker attach 3a09b2588478
You now have a shell running on the container which you can use to make your changes to the container.
8. Now install Cassandra using the steps mentioned in the two post back.
9. After installation commit and then push
note that I have committed it to my repository that I have made it available publicly on docker website. My repository is my <user_name>/<repository_Name> i.e. mdshiraz/mdshiraz_adobe_test
10. Later push it:
11. After pushing your image will be visible in the docker repo
12. now, go to any other centos machine, pull this docker image using docker pull mdshiraz/mdshiraz_adobe_test:centos6-cassandra
Subscribe to:
Posts (Atom)