def _audio_tipl(atuple): audio, atag, advanced, _, _ = atuple if advanced: param = ast.literal_eval(atag) audio.add(TIPL(3, param[1])) else: audio.add(TIPL(3, atag))
def tag(self, flac_filename, mp3_filename): flac = FLAC(flac_filename) id3 = ID3() involved_people = [] for tag, value in flac.iteritems(): if tag in self.tag_map: id3.add(self.tag_map[tag](encoding=3, text=value)) elif tag in self.text_tag_map: id3.add( TXXX(encoding=3, desc=self.text_tag_map[tag], text=value)) elif tag == 'tracknumber': value[0] += self._total(flac, ['tracktotal', 'totaltracks']) id3.add(TRCK(encoding=3, text=value)) elif tag == 'discnumber': value[0] += self._total(flac, ['disctotal', 'totaldiscs']) id3.add(TPOS(encoding=3, text=value)) elif tag == 'musicbrainz_trackid': id3.add(UFID(u'http://musicbrainz.org', value[0])) elif tag in ('producer', 'engineer', 'arranger'): involved_people.extend((unicode(tag), v) for v in value) elif tag == 'mixer': involved_people.extend((u'mix', v) for v in value) elif tag == 'performer': id3.add(TMCL(encoding=3, people=self._performers(value))) elif tag not in [ 'tracktotal', 'totaltracks', 'disctotal', 'totaldiscs', 'replaygain_album_gain', 'replaygain_album_peak', 'replaygain_track_gain', 'replaygain_track_peak', # Don't know what to do with reference loudness - ignore it 'replaygain_reference_loudness', # No mapping for mp3 - https://picard.musicbrainz.org/docs/mappings/ 'originalyear', # Drop CDDB disc id 'discid' ]: raise UnknownTag("%s=%s" % (tag, value)) if involved_people: id3.add(TIPL(encoding=3, people=involved_people)) self._replaygain(flac, id3, 'album') self._replaygain(flac, id3, 'track') for pic in flac.pictures: tag = APIC(encoding=3, mime=pic.mime, type=pic.type, desc=pic.desc, data=pic.data) id3.add(tag) id3.save(mp3_filename)
def test_save_off_spec_frames(self): # These are not defined in v2.3 and shouldn't be written. # Still make sure reading them again works and the encoding # is at least changed audio = ID3(self.filename) dates = ["2013", "2014"] frame = TDEN(text=dates, encoding=3) audio.add(frame) tipl_frame = TIPL(people=[("a", "b"), ("c", "d")], encoding=2) audio.add(tipl_frame) audio.save(v2_version=3) id3 = ID3(self.filename, translate=False) self.assertEqual(id3.version, (2, 3, 0)) self.assertEqual([stamp.text for stamp in id3["TDEN"].text], dates) self.assertEqual(id3["TDEN"].encoding, 1) self.assertEqual(id3["TIPL"].people, tipl_frame.people) self.assertEqual(id3["TIPL"].encoding, 1)
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()