updated on Wed Jan 18 08:00:29 UTC 2012
[aur-mirror.git] / groovepwn / mp3Handler.py
blob860270b1a1e2f0bc688ed108ade08919c5b119d5
1 #!/usr/bin/python2
3 import os, shutil, errno
4 from pyid3lib import tag
6 def organiseMP3(tempFileName):
7 try:
8 id3tag = tag(tempFileName)
9 try:
10 title = id3tag.title
11 except:
12 title = 'Unknown Title'
13 try:
14 artist = id3tag.artist
15 except:
16 artist = 'Unknown Artist'
17 try:
18 album = id3tag.album
19 except:
20 album = 'Unknown Album'
21 fileName = "%s.mp3" % (title)
22 songDir = os.path.join('/tmp', artist, album)
23 try:
24 os.makedirs(songDir)
25 except OSError, e:
26 if e.errno != errno.EEXIST:
27 raise e
28 target = os.path.join(songDir, fileName)
29 shutil.move(tempFileName, target)
30 print "Pwn'd an MP3 file: %s" % (target)
31 except Exception, e:
32 print "Encoding/identification errors have occurred, but a temp file was stored.", e
33 shutil.move(tempFileName, "./")