CC-1799: Live Studio Playout from media library (pytagsfs)

using mutagen to get audio tags
This commit is contained in:
naomiaro 2011-04-27 20:19:41 -04:00 committed by martin
parent 75d0229d39
commit dbcfabfb76
1 changed files with 31 additions and 9 deletions

View File

@ -33,6 +33,11 @@ except Exception, e:
print 'Error loading config file: ', e
sys.exit()
"""
list of supported easy tags in mutagen version 1.20
['albumartistsort', 'musicbrainz_albumstatus', 'lyricist', 'releasecountry', 'date', 'performer', 'musicbrainz_albumartistid', 'composer', 'encodedby', 'tracknumber', 'musicbrainz_albumid', 'album', 'asin', 'musicbrainz_artistid', 'mood', 'copyright', 'author', 'media', 'length', 'version', 'artistsort', 'titlesort', 'discsubtitle', 'website', 'musicip_fingerprint', 'conductor', 'compilation', 'barcode', 'performer:*', 'composersort', 'musicbrainz_discid', 'musicbrainz_albumtype', 'genre', 'isrc', 'discnumber', 'musicbrainz_trmid', 'replaygain_*_gain', 'musicip_puid', 'artist', 'title', 'bpm', 'musicbrainz_trackid', 'arranger', 'albumsort', 'replaygain_*_peak', 'organization']
"""
class MediaMonitor(ProcessEvent):
def my_init(self):
@ -43,20 +48,34 @@ class MediaMonitor(ProcessEvent):
"""
self.api_client = api_client.api_client_factory(config)
self.mutagen2airtime = {\
"title": "track_title",\
"artist": "artist_name",\
"album": "album_title",\
"genre": "genre",\
"mood": "mood",\
"tracknumber": "track_number",\
"bpm": "bpm",\
"organization": "label",\
"composer": "composer",\
"encodedby": "encoded_by",\
"conductor": "conductor",\
"date": "year",\
"website": "info_url",\
"isrc": "isrc_number",\
"copyright": "copyright",\
}
def process_IN_CREATE(self, event):
if not event.dir :
#This is a newly imported file.
print "%s: %s" % (event.maskname, os.path.join(event.path, event.name))
print "%s: %s%s" % (event.maskname, event.path, event.name)
#event.path : /srv/airtime/stor/bd2
#event.name : bd2aa73b58d9c8abcced989621846e99.mp3
#event.pathname : /srv/airtime/stor/bd2/bd2aa73b58d9c8abcced989621846e99.mp3
def process_IN_MODIFY(self, event):
if not event.dir :
p = Popen(["pytags", event.pathname], stdout=PIPE, stderr=STDOUT)
output = p.stdout.read().decode("utf-8").strip()
#get md5, most likely different
f = file(event.pathname, 'rb')
m = hashlib.md5()
m.update(f.read())
@ -65,9 +84,12 @@ class MediaMonitor(ProcessEvent):
gunid = event.name.split('.')[0]
md = {'gunid':gunid, 'md5':md5}
for tag in output.split("\n")[2:] :
key,value = tag.split("=")
md[key] = value
file_info = mutagen.File(event.pathname, easy=True)
attrs = self.mutagen2airtime
for key in file_info.keys() :
if key in attrs :
md[attrs[key]] = file_info[key]
data = {'md': md}
@ -76,7 +98,7 @@ class MediaMonitor(ProcessEvent):
print "%s: path: %s name: %s" % (event.maskname, event.path, event.name)
def process_default(self, event):
print "%s: %s" % (event.maskname, os.path.join(event.path, event.name))
print "%s: %s%s" % (event.maskname, event.path, event.name)
if __name__ == '__main__':