def _audio_tit1(atuple): audio, atag, advanced, _, _ = atuple if advanced: param = ast.literal_eval(atag) audio.add(TIT1(3, param[1])) else: audio.add(TIT1(3, atag))
def test_save_tags(self): from mutagen.id3 import TIT1 tags = self.aiff_tmp_id3.tags tags.add(TIT1(encoding=3, text="foobar")) tags.save() new = AIFF(self.aiff_tmp_id3.filename) self.failUnlessEqual(new["TIT1"], ["foobar"])
def test_save_tags(self): from mutagen.id3 import TIT1 tags = self.tmp_wav_pcm_2s_16000_08_ID3v23.tags tags.add(TIT1(encoding=3, text="foobar")) tags.save() new = WAVE(self.tmp_wav_pcm_2s_16000_08_ID3v23.filename) self.failUnlessEqual(new["TIT1"], ["foobar"])
def test_save_tags(self): from mutagen.id3 import TIT1 self.dff_no_id3.add_tags() tags = self.dff_no_id3.tags tags.add(TIT1(encoding=3, text="foobar")) tags.save(self.dff_no_id3.filename) new = DSDIFF(self.dff_no_id3.filename) self.failUnlessEqual(new["TIT1"], ["foobar"])
def setUp(self): original = os.path.join(DATA_DIR, "adif.aac") self.filename = get_temp_copy(original) tag = ID3() tag.add(TIT1(text=[u"a" * 5000], encoding=3)) tag.save(self.filename) self.aac = AAC(original) self.aac_id3 = AAC(self.filename)
def test_save_reload(self): filename = get_temp_copy(self.audio.filename) try: audio = TrueAudio(filename) audio.add_tags() audio.tags.add(TIT1(encoding=0, text="A Title")) audio.save() audio = TrueAudio(filename) self.failUnlessEqual(audio["TIT1"], "A Title") finally: os.unlink(filename)
def test_save_reload(self): try: fd, filename = mkstemp(suffix='.tta') os.close(fd) shutil.copy(self.audio.filename, filename) audio = TrueAudio(filename) audio.add_tags() audio.tags.add(TIT1(encoding=0, text="A Title")) audio.save() audio = TrueAudio(filename) self.failUnlessEqual(audio["TIT1"], "A Title") finally: os.unlink(filename)
def test_save_without_ID3_chunk(self): from mutagen.id3 import TIT1 self.aiff_tmp_no_id3["TIT1"] = TIT1(encoding=3, text="foobar") self.aiff_tmp_no_id3.save() self.failUnless(AIFF(self.filename_2)["TIT1"] == "foobar")
def setID3(baseDIR, filename, artist, title, lyric, albumID, cover_img_path): file_path = os.path.join(baseDIR, filename) audio_file = MP3(file_path, ID3=ID3) encoding=3 # 3 is for utf-8 # add CoverPicture audio_file.tags.add( APIC( encoding=encoding, mime='image/jpg', # image/jpeg or image/png type=3, # 3 is for the cover image desc=u'Cover', data=open(cover_img_path, 'rb').read() ) ) audio_file.tags.add( USLT( encoding=encoding, desc=u'Lyric', text=lyric ) ) audio_file.tags.add( TOPE( encoding=encoding, text=artist ) ) audio_file.tags.add( TPE1( encoding=encoding, text=artist ) ) audio_file.tags.add( TIT1( encoding=encoding, text=title ) ) audio_file.tags.add( TIT2( encoding=encoding, text=title ) ) audio_file.tags.add( TIPL( encoding=encoding, text=[artist] ) ) albumInfo = cc.getAlbumInfoFromMelon(albumID) if not albumInfo == None: audio_file.tags.add( TALB( encoding=encoding, text=[albumInfo['album_name']] ) ) audio_file.tags.add( TPRO( encoding=encoding, text=[albumInfo['copyright']] ) ) audio_file.tags.add( TCON( encoding=encoding, text=[albumInfo['genre']] ) ) audio_file.tags.add( TPUB( encoding=encoding, text=[albumInfo['publisher']] ) ) audio_file.tags.add( TDOR( encoding=encoding, text=[albumInfo['pub_date']] ) ) audio_file.tags.add( TDRL( encoding=encoding, text=[albumInfo['pub_date']] ) ) audio_file.save()
def test_frame(self): from mutagen.id3 import TIT1 self.failUnlessRaises( TypeError, {}.__setitem__, TIT1(encoding=0, text="foo"), None)
class MediaHelper: config = None tagSep = None maxTags = None overwriteFields = None forceOverwriteFields = None id3v1Handling = None useBothArtistFields = False artistFieldPref = [] formatFieldMap = dict(id3=dict(genre='TCON', grouping='TIT1', comment="COMM::'eng'", artist='TPE1', albumartist='TPE2', album='TALB', track='TIT2'), mp4=dict(genre='\xa9gen', grouping='\xa9grp', comment='\xa9cmt', artist='\xa9ART', albumartist='aART', album='\xa9alb', track='\xa9nam'), oggvorbis=dict(genre='genre', grouping='grouping', comment='comment', artist='artist', albumartist='album artist', album='album', track='title'), flac=dict(genre='genre', grouping='grouping', comment='comment', artist='artist', albumartist='album artist', album='album', track='title')) id3FuncMap = dict( genre=lambda val: TCON(encoding=3, text=val), grouping=lambda val: TIT1(encoding=3, text=val), comment=lambda val: COMM(encoding=3, lang='eng', desc='', text=val), artist=lambda val: TPE1(encoding=3, text=val), albumartist=lambda val: TPE2(encoding=3, text=val), album=lambda val: TALB(encoding=3, text=val), track=lambda val: TIT2(encoding=3, text=val)) meaninglessArtists = frozenset([ 'various artists', 'soundtrack', 'soundtracks', 'original soundtrack', 'ost', 'compilation' ]) def __init__(self, config): self.config = config self.tagSep = self.config.get('tagSep') if (len(self.tagSep.strip()) > 0): self.tagSep += ' ' self.maxTags = dict(genre=self.config.getint('genreMaxTags'), grouping=self.config.getint('groupingMaxTags'), comment=self.config.getint('commentMaxTags')) self.overwriteFields = set( map(string.strip, self.config.get('overwriteFields').lower().split(','))) self.forceOverwriteFields = set( map(string.strip, self.config.get('forceOverwriteFields').lower().split(','))) self.id3v1Handling = self.config.getint('id3v1Handling') self.artistFieldPref = ['albumartist', 'artist'] if (self.config.get('artistField').lower() == 'both'): self.useBothArtistFields = True elif (self.config.get('artistField').lower() == 'artist'): self.artistFieldPref.reverse() def getMediawrapper(self, filename): root, ext = os.path.splitext(filename.lower()) if (ext == '.mp3'): mediawrapper = ID3(filename) elif (ext == '.m4a'): mediawrapper = MP4(filename) elif (ext == '.ogg'): mediawrapper = OggVorbis(filename) elif (ext == '.flac'): mediawrapper = FLAC(filename) else: mediawrapper = mutagen.File(filename) return mediawrapper def extractMetadata(self, filename): try: mediawrapper = self.getMediawrapper(filename) if (isinstance(mediawrapper, ID3)): return self.extractMetadataHelper(mediawrapper, self.formatFieldMap['id3'], filename) elif (isinstance(mediawrapper, MP4)): return self.extractMetadataHelper(mediawrapper, self.formatFieldMap['mp4'], filename) elif (isinstance(mediawrapper, OggVorbis)): return self.extractMetadataHelper( mediawrapper, self.formatFieldMap['oggvorbis'], filename) elif (isinstance(mediawrapper, FLAC)): return self.extractMetadataHelper(mediawrapper, self.formatFieldMap['flac'], filename) else: if (self.config.getboolean('verbose')): common.safeStdout( '\tSkipping unknown/incompatible media file type [' + filename + ']') except Exception, err: common.safeStderr('Error seen during media reading: ' + str(err)) return None