def test_normalized_metadata(self): #Recorded show test first orig = Metadata.airtime_dict({ 'date' : [u'2012-08-21'], 'tracknumber' : [u'2'], 'title' : [u'record-2012-08-21-11:29:00'], 'artist' : [u'Airtime Show Recorder'] }) orga = Metadata.airtime_dict({ 'date' : [u'2012-08-21'], 'tracknumber' : [u'2'], 'artist' : [u'Airtime Show Recorder'], 'title' : [u'record-2012-08-21-11:29:00'] }) orga['MDATA_KEY_FTYPE'] = u'audioclip' orig['MDATA_KEY_BITRATE'] = u'256000' orga['MDATA_KEY_BITRATE'] = u'256000' old_path = "/home/rudi/recorded/2012-08-21-11:29:00.ogg" normalized = mmp.normalized_metadata(orig, old_path) normalized['MDATA_KEY_BITRATE'] = u'256000' self.assertEqual( orga, normalized ) organized_base_name = "11:29:00-record-256kbps.ogg" base = "/srv/airtime/stor/" organized_path = mmp.organized_path(old_path,base, normalized) self.assertEqual(os.path.basename(organized_path), organized_base_name)
def test_normalized_metadata3(self): """ Test the case where the metadata is empty """ orig = Metadata.airtime_dict({}) paths_unknown_title = [ ("/testin/unknown-unknown-unknown.mp3",""), ("/testin/01-unknown-123kbps.mp3",""), ("/testin/02-unknown-140kbps.mp3",""), ("/testin/unknown-unknown-123kbps.mp3",""), ("/testin/unknown-bibimbop-unknown.mp3","bibimbop"), ] for p,res in paths_unknown_title: normalized = mmp.normalized_metadata(orig, p) self.assertEqual( normalized['MDATA_KEY_TITLE'], res)
def test_normalized_metadata2(self): """ cc-4305 """ orig = Metadata.airtime_dict({ 'date' : [u'2012-08-27'], 'tracknumber' : [u'3'], 'title' : [u'18-11-00-Untitled Show'], 'artist' : [u'Airtime Show Recorder'] }) old_path = "/home/rudi/recorded/doesnt_really_matter.ogg" normalized = mmp.normalized_metadata(orig, old_path) normalized['MDATA_KEY_BITRATE'] = u'256000' opath = mmp.organized_path(old_path, "/srv/airtime/stor/", normalized) # TODO : add a better test than this... self.assertTrue( len(opath) > 0 )
def __init__(self, fpath): # Forcing the unicode through try : fpath = fpath.decode("utf-8") except : pass if not mmp.file_playable(fpath): raise BadSongFile(fpath) try : full_mutagen = mutagen.File(fpath, easy=True) except Exception : raise BadSongFile(fpath) self.path = fpath if not os.path.exists(self.path): self.logger.info("Attempting to read metadata of file \ that does not exist. Setting metadata to {}") self.__metadata = {} return # TODO : Simplify the way all of these rules are handled right now it's # extremely unclear and needs to be refactored. #if full_mutagen is None: raise BadSongFile(fpath) if full_mutagen is None: full_mutagen = FakeMutagen(fpath) self.__metadata = Metadata.airtime_dict(full_mutagen) # Now we extra the special values that are calculated from the mutagen # object itself: if mmp.extension(fpath) == 'wav': full_mutagen.set_length(mmp.read_wave_duration(fpath)) for special_key,f in airtime_special.iteritems(): try: new_val = f(full_mutagen) if new_val is not None: self.__metadata[special_key] = new_val except Exception as e: self.logger.info("Could not get special key %s for %s" % (special_key, fpath)) self.logger.info(str(e)) # Finally, we "normalize" all the metadata here: self.__metadata = mmp.normalized_metadata(self.__metadata, fpath) # Now we must load the md5: # TODO : perhaps we shouldn't hard code how many bytes we're reading # from the file? self.__metadata['MDATA_KEY_MD5'] = mmp.file_md5(fpath,max_length=100)