def _audio_tory(atuple): audio, atag, advanced, _, _ = atuple if advanced: param = ast.literal_eval(atag) audio.add(TORY(3, param[1])) else: audio.add(TORY(3, atag))
def set_file_tags(filename, tags): try: default_tags = ID3(filename) except ID3NoHeaderError: # Adding ID3 header default_tags = ID3() # Tag Breakdown # Track: TIT2 # OG Filename: TOFN # Artist - Song Title.MP3 # Artist: TOPE, TPE1, WOAR(official), TSO2(itunes), TPE2(band) # Lyrics: TEXT # Album: TOAL(original), TSO2(itunes), TSOA(sort), TALB # Genres: TCON # Year: TORY(release), TYER(record) # Publisher: TPUB, WPUB(info) default_tags["TOFN"] = TOFN(encoding=3, text=os.path.split(filename[0])[1]) # Original Filename default_tags["TIT2"] = TIT2(encoding=3, text=tags.song) # Title default_tags["TRCK"] = TRCK(encoding=3, text=tags.track_number) # Track Number # Artist tags default_tags["TOPE"] = TOPE(encoding=3, text=tags.artist) # Original Artist/Performer default_tags["TPE1"] = TPE1(encoding=3, text=tags.artist) # Lead Artist/Performer/Soloist/Group default_tags["TPE2"] = TPE2(encoding=3, text=tags.album_artist) # Band/Orchestra/Accompaniment # Album tags default_tags["TOAL"] = TOAL(encoding=3, text=tags.album) # Original Album default_tags["TALB"] = TALB(encoding=3, text=tags.album) # Album Name default_tags["TSO2"] = TSO2(encoding=3, text=tags.album) # iTunes Album Artist Sort # tags["TSOA"] = TSOA(encoding=3, text=tags.album[0]) # Album Sort Order key default_tags["TCON"] = TCON(encoding=3, text=tags.genres) # Genre default_tags["TDOR"] = TORY(encoding=3, text=str(tags.year)) # Original Release Year default_tags["TDRC"] = TYER(encoding=3, text=str(tags.year)) # Year of recording default_tags["USLT"] = USLT(encoding=3, text=tags.lyrics) # Lyrics default_tags.save(v2_version=3) # Album Cover if type(tags.album_cover) == str: r = requests.get(tags.album_cover, stream=True) r.raise_for_status() r.raw.decode_content = True with open('img.jpg', 'wb') as out_file: shutil.copyfileobj(r.raw, out_file) del r with open('img.jpg', 'rb') as albumart: default_tags.add(APIC( encoding=3, mime="image/jpg", type=3, desc='Cover', data=albumart.read())) elif type(tags.album_cover) == bytes: default_tags.add(APIC( encoding=3, mime="image/jpg", type=3, desc='Cover', data=tags.album_cover)) default_tags.save(v2_version=3)
def as_mp3(self): """ Embed metadata to MP3 files. """ music_file = self.music_file #print(music_file) meta_tags = self.meta_tags #print(meta_tags) # EasyID3 is fun to use ;) # For supported easyid3 tags: # https://github.com/quodlibet/mutagen/blob/master/mutagen/easyid3.py # Check out somewhere at end of above linked file ''' mera code adding dummy tags''' try: tags = ID3(music_file) except ID3NoHeaderError: tags = ID3() tags.save(music_file) audiofile = EasyID3(music_file) self._embed_basic_metadata(audiofile, preset=TAG_PRESET) audiofile['media'] = meta_tags['type'] audiofile['author'] = meta_tags['artists'][0]['name'] audiofile['lyricist'] = meta_tags['artists'][0]['name'] audiofile['arranger'] = meta_tags['artists'][0]['name'] audiofile['performer'] = meta_tags['artists'][0]['name'] audiofile['website'] = meta_tags['external_urls']['spotify'] audiofile['length'] = str(meta_tags['duration']) if meta_tags['publisher']: audiofile['encodedby'] = meta_tags['publisher'] if meta_tags['external_ids']['isrc']: audiofile['isrc'] = meta_tags['external_ids']['isrc'] audiofile.save(v2_version=3) # For supported id3 tags: # https://github.com/quodlibet/mutagen/blob/master/mutagen/id3/_frames.py # Each class represents an id3 tag audiofile = ID3(music_file) audiofile['TORY'] = TORY(encoding=3, text=meta_tags['year']) audiofile['TYER'] = TYER(encoding=3, text=meta_tags['year']) audiofile['TPUB'] = TPUB(encoding=3, text=meta_tags['publisher']) audiofile['COMM'] = COMM(encoding=3, text=meta_tags['external_urls']['spotify']) if meta_tags['lyrics']: audiofile['USLT'] = USLT(encoding=3, desc=u'Lyrics', text=meta_tags['lyrics']) try: albumart = urllib.request.urlopen( meta_tags['album']['images'][0]['url']) audiofile['APIC'] = APIC(encoding=3, mime='image/jpeg', type=3, desc=u'Cover', data=albumart.read()) albumart.close() except IndexError: pass audiofile.save(v2_version=3) return True
def as_mp3(self, path, metadata, cached_albumart=None): """ Embed metadata to MP3 files. """ logger.debug('Writing MP3 metadata to "{path}".'.format(path=path)) # EasyID3 is fun to use ;) # For supported easyid3 tags: # https://github.com/quodlibet/mutagen/blob/master/mutagen/easyid3.py # Check out somewhere at end of above linked file audiofile = EasyID3(path) self._embed_basic_metadata(audiofile, metadata, "mp3", preset=TAG_PRESET) audiofile["media"] = metadata["type"] audiofile["author"] = metadata["artists"][0]["name"] audiofile["lyricist"] = metadata["artists"][0]["name"] audiofile["arranger"] = metadata["artists"][0]["name"] audiofile["performer"] = metadata["artists"][0]["name"] provider = metadata["provider"] audiofile["website"] = metadata["external_urls"][provider] audiofile["length"] = str(metadata["duration"]) if metadata["publisher"]: audiofile["encodedby"] = metadata["publisher"] if metadata["external_ids"]["isrc"]: audiofile["isrc"] = metadata["external_ids"]["isrc"] audiofile.save(v2_version=3) # For supported id3 tags: # https://github.com/quodlibet/mutagen/blob/master/mutagen/id3/_frames.py # Each class in the linked source file represents an id3 tag audiofile = ID3(path) if metadata["year"]: audiofile["TORY"] = TORY(encoding=3, text=metadata["year"]) audiofile["TYER"] = TYER(encoding=3, text=metadata["year"]) if metadata["publisher"]: audiofile["TPUB"] = TPUB(encoding=3, text=metadata["publisher"]) provider = metadata["provider"] audiofile["COMM"] = COMM(encoding=3, text=metadata["external_urls"][provider]) if metadata["lyrics"]: audiofile["USLT"] = USLT(encoding=3, desc=u"Lyrics", text=metadata["lyrics"]) if cached_albumart is None: cached_albumart = urllib.request.urlopen( metadata["album"]["images"][0]["url"]).read() albumart.close() try: audiofile["APIC"] = APIC( encoding=3, mime="image/jpeg", type=3, desc=u"Cover", data=cached_albumart, ) except IndexError: pass audiofile.save(v2_version=3)
def as_mp3(self): """ Embed metadata to MP3 files. """ music_file = self.music_file meta_tags = self.meta_tags # EasyID3 is fun to use ;) # For supported easyid3 tags: # https://github.com/quodlibet/mutagen/blob/master/mutagen/easyid3.py # Check out somewhere at end of above linked file audiofile = EasyID3(music_file) self._embed_basic_metadata(audiofile, preset=TAG_PRESET) audiofile["media"] = meta_tags["type"] audiofile["author"] = meta_tags["artists"][0]["name"] audiofile["lyricist"] = meta_tags["artists"][0]["name"] audiofile["arranger"] = meta_tags["artists"][0]["name"] audiofile["performer"] = meta_tags["artists"][0]["name"] audiofile["website"] = meta_tags["external_urls"][self.provider] audiofile["length"] = str(meta_tags["duration"]) if meta_tags["publisher"]: audiofile["encodedby"] = meta_tags["publisher"] if meta_tags["external_ids"]["isrc"]: audiofile["isrc"] = meta_tags["external_ids"]["isrc"] audiofile.save(v2_version=3) # For supported id3 tags: # https://github.com/quodlibet/mutagen/blob/master/mutagen/id3/_frames.py # Each class represents an id3 tag audiofile = ID3(music_file) if meta_tags["year"]: audiofile["TORY"] = TORY(encoding=3, text=meta_tags["year"]) audiofile["TYER"] = TYER(encoding=3, text=meta_tags["year"]) if meta_tags["publisher"]: audiofile["TPUB"] = TPUB(encoding=3, text=meta_tags["publisher"]) audiofile["COMM"] = COMM( encoding=3, text=meta_tags["external_urls"][self.provider]) if meta_tags["lyrics"]: audiofile["USLT"] = USLT(encoding=3, desc=u"Lyrics", text=meta_tags["lyrics"]) try: albumart = urllib.request.urlopen( meta_tags["album"]["images"][0]["url"]) audiofile["APIC"] = APIC( encoding=3, mime="image/jpeg", type=3, desc=u"Cover", data=albumart.read(), ) albumart.close() except IndexError: pass audiofile.save(v2_version=3) return True
def add_mp3_metadata(file_path, title='Unknown', artist='Unknown', album='Unknown', index=0, year=""): """ adds tags for the mp3 file (artist, album etc.) :param file_path: the path of the mp3 file that was downloaded :type file_path: str :param title: the title of the song :type title: str :param artist: the artist of the song :type artist: str :param album: the album that the song is part of :type album: str :param index: the index of the song in the album :type index: str :param year: the year of release of the song/ album :type year: str :return: None """ try: print("replacing the file...") AudioSegment.from_file(file_path).export(file_path, format='mp3') print("writing tags on file...") print("{} {} {} {}".format(title, album, artist, index)) except FileNotFoundError as e: print("failed to convert {} to mp3 because file not found: {}".format(title, e)) return except Exception as e: print("unhandled exception in converting {} to mp3: {}".format(title, e)) return if title is 'Unknown': title = file_path.split('\\')[-1].split('.')[0] try: audio = ID3(file_path) except ID3NoHeaderError as e: audio = ID3() audio.add(TIT2(encoding=3, text=title)) audio['TIT2'] = TIT2(encoding=Encoding.UTF8, text=title) # title audio['TPE1'] = TPE1(encoding=Encoding.UTF8, text=artist) # contributing artist audio['TPE2'] = TPE2(encoding=Encoding.UTF8, text=artist) # album artist audio['TALB'] = TALB(encoding=Encoding.UTF8, text=album) # album audio['TRCK'] = TRCK(encoding=Encoding.UTF8, text=str(index)) # track number audio['TORY'] = TORY(encoding=Encoding.UTF8, text=str(year)) # Original Release Year audio['TYER'] = TYER(encoding=Encoding.UTF8, text=str(year)) # Year Of Recording audio.save(file_path)
def clean_metadata(path): filename, filetype = os.path.splitext(path) try: origfile = ID3(path) except: origfile = ID3() # Save essential metadata artist = get_tag(origfile, 'TPE1') album = get_tag(origfile, 'TALB') title = get_tag(origfile, 'TIT2') genre = get_tag(origfile, 'TCON') track_num = get_tag(origfile, 'TRCK') year = get_tag(origfile, 'TYER') date = get_tag(origfile, 'TDRC') lyrics = get_tag(origfile, 'USLT') art = get_tag(origfile, 'APIC:') # Rename dirty file dirty_filepath = filename+"-dirty.mp3" os.rename(path, dirty_filepath) # Create new file with no tags subprocess.check_output(['ffmpeg', '-hide_banner', '-i', dirty_filepath, '-map_metadata', '-1', '-c:v', 'copy', '-c:a', 'copy', path]) # Apply desired tags to new file try: cleanfile = ID3(path) except ID3NoHeaderError: cleanfile = ID3() if artist != "": cleanfile.add(TPE1(encoding=3, text=artist)) if album != "": cleanfile.add(TALB(encoding=3, text=album)) if title != "": cleanfile.add(TIT2(encoding=3, text=title)) if genre != "": cleanfile.add(TCON(encoding=3, text=genre)) if track_num != "": cleanfile.add(TRCK(encoding=3, text=track_num)) if date != "": cleanfile.add(TDRC(encoding=3, text=date)) if year != "": cleanfile.add(TYER(encoding=3, text=year)) if year != "": cleanfile.add(TORY(encoding=3, text=year)) if lyrics != "": cleanfile.add(USLT(encoding=3, text=lyrics)) if art != "": cleanfile.add(APIC(encoding=3, mime='image/jpeg', type=3, desc=u'Cover', data=art)) cleanfile.save(path, v2_version=3) # Delete old, dirty file os.remove(dirty_filepath)
def as_mp3(self): """ Embed metadata to MP3 files. """ music_file = self.music_file meta_tags = self.meta_tags # EasyID3 is fun to use ;) # For supported easyid3 tags: # https://github.com/quodlibet/mutagen/blob/master/mutagen/easyid3.py # Check out somewhere at end of above linked file audiofile = EasyID3(music_file) audiofile['artist'] = meta_tags['artists'][0]['name'] audiofile['albumartist'] = meta_tags['artists'][0]['name'] audiofile['album'] = meta_tags['album']['name'] audiofile['title'] = meta_tags['name'] audiofile['tracknumber'] = [ meta_tags['track_number'], meta_tags['total_tracks'] ] audiofile['discnumber'] = [meta_tags['disc_number'], 0] audiofile['date'] = meta_tags['release_date'] audiofile['originaldate'] = meta_tags['release_date'] audiofile['media'] = meta_tags['type'] audiofile['author'] = meta_tags['artists'][0]['name'] audiofile['lyricist'] = meta_tags['artists'][0]['name'] audiofile['arranger'] = meta_tags['artists'][0]['name'] audiofile['performer'] = meta_tags['artists'][0]['name'] audiofile['website'] = meta_tags['external_urls']['spotify'] audiofile['length'] = str(meta_tags['duration']) if meta_tags['publisher']: audiofile['encodedby'] = meta_tags['publisher'] if meta_tags['genre']: audiofile['genre'] = meta_tags['genre'] if meta_tags['copyright']: audiofile['copyright'] = meta_tags['copyright'] if meta_tags['external_ids']['isrc']: audiofile['isrc'] = meta_tags['external_ids']['isrc'] audiofile.save(v2_version=3) # For supported id3 tags: # https://github.com/quodlibet/mutagen/blob/master/mutagen/id3/_frames.py # Each class represents an id3 tag audiofile = ID3(music_file) audiofile['TORY'] = TORY(encoding=3, text=meta_tags['year']) audiofile['TYER'] = TYER(encoding=3, text=meta_tags['year']) audiofile['TPUB'] = TPUB(encoding=3, text=meta_tags['publisher']) audiofile['COMM'] = COMM(encoding=3, text=meta_tags['external_urls']['spotify']) if meta_tags['lyrics']: audiofile['USLT'] = USLT(encoding=3, desc=u'Lyrics', text=meta_tags['lyrics']) try: albumart = urllib.request.urlopen( meta_tags['album']['images'][0]['url']) audiofile['APIC'] = APIC(encoding=3, mime='image/jpeg', type=3, desc=u'Cover', data=albumart.read()) albumart.close() except IndexError: pass audiofile.save(v2_version=3) return True
def update_to_v23(self, join_with="/"): """Convert older (and newer) tags into an ID3v2.3 tag. This updates incompatible ID3v2 frames to ID3v2.3 ones. If you intend to save tags as ID3v2.3, you must call this function at some point. """ if self.version < (2, 3, 0): del self.unknown_frames[:] # TMCL, TIPL -> TIPL if "TIPL" in self or "TMCL" in self: people = [] if "TIPL" in self: f = self.pop("TIPL") people.extend(f.people) if "TMCL" in self: f = self.pop("TMCL") people.extend(f.people) if "IPLS" not in self: self.add(IPLS(encoding=f.encoding, people=people)) # TODO: # * EQU2 -> EQUA # * RVA2 -> RVAD # TDOR -> TORY if "TDOR" in self: f = self.pop("TDOR") if f.text: d = f.text[0] if d.year and "TORY" not in self: self.add(TORY(encoding=f.encoding, text="%04d" % d.year)) # TDRC -> TYER, TDAT, TIME if "TDRC" in self: f = self.pop("TDRC") if f.text: d = f.text[0] if d.year and "TYER" not in self: self.add(TYER(encoding=f.encoding, text="%04d" % d.year)) if d.month and d.day and "TDAT" not in self: self.add( TDAT(encoding=f.encoding, text="%02d%02d" % (d.day, d.month))) if d.hour and d.minute and "TIME" not in self: self.add( TIME(encoding=f.encoding, text="%02d%02d" % (d.hour, d.minute))) if "TCON" in self: self["TCON"].genres = self["TCON"].genres if self.version < (2, 3): # ID3v2.2 PIC frames are slightly different. pics = self.getall("APIC") mimes = {"PNG": "image/png", "JPG": "image/jpeg"} self.delall("APIC") for pic in pics: newpic = APIC(encoding=pic.encoding, mime=mimes.get(pic.mime, pic.mime), type=pic.type, desc=pic.desc, data=pic.data) self.add(newpic) # ID3v2.2 LNK frames are just way too different to upgrade. self.delall("LINK") # leave TSOP, TSOA and TSOT even though they are officially defined # only in ID3v2.4, because most applications use them also in ID3v2.3 # New frames added in v2.4. for key in [ "ASPI", "EQU2", "RVA2", "SEEK", "SIGN", "TDRL", "TDTG", "TMOO", "TPRO" ]: if key in self: del (self[key]) for frame in self.values(): # ID3v2.3 doesn't support UTF-8 (and WMP can't read UTF-16 BE) if hasattr(frame, "encoding"): if frame.encoding > 1: frame.encoding = 1 # ID3v2.3 doesn't support multiple values if isinstance(frame, mutagen.id3.TextFrame): try: frame.text = [join_with.join(frame.text)] except TypeError: frame.text = frame.text[:1]
def __init_id3_tags(id3, major=3): """ Attributes: id3 ID3 Tag object major ID3 major version, e.g.: 3 for ID3v2.3 """ from mutagen.id3 import TRCK, TPOS, TXXX, TPUB, TALB, UFID, TPE2, \ TSO2, TMED, TIT2, TPE1, TSRC, IPLS, TORY, TDAT, TYER id3.add(TRCK(encoding=major, text="1/10")) id3.add(TPOS(encoding=major, text="1/1")) id3.add( TXXX(encoding=major, desc="MusicBrainz Release Group Id", text="e00305af-1c72-469b-9a7c-6dc665ca9adc")) id3.add(TXXX(encoding=major, desc="originalyear", text="2011")) id3.add( TXXX(encoding=major, desc="MusicBrainz Album Type", text="album")) id3.add( TXXX(encoding=major, desc="MusicBrainz Album Id", text="e7050302-74e6-42e4-aba0-09efd5d431d8")) id3.add(TPUB(encoding=major, text="J&R Adventures")) id3.add(TXXX(encoding=major, desc="CATALOGNUMBER", text="PRAR931391")) id3.add(TALB(encoding=major, text="Don\'t Explain")) id3.add( TXXX(encoding=major, desc="MusicBrainz Album Status", text="official")) id3.add(TXXX(encoding=major, desc="SCRIPT", text="Latn")) id3.add( TXXX(encoding=major, desc="MusicBrainz Album Release Country", text="US")) id3.add(TXXX(encoding=major, desc="BARCODE", text="804879313915")) id3.add( TXXX(encoding=major, desc="MusicBrainz Album Artist Id", text=[ "3fe817fc-966e-4ece-b00a-76be43e7e73c", "984f8239-8fe1-4683-9c54-10ffb14439e9" ])) id3.add(TPE2(encoding=major, text="Beth Hart & Joe Bonamassa")) id3.add(TSO2(encoding=major, text="Hart, Beth & Bonamassa, Joe")) id3.add(TXXX(encoding=major, desc="ASIN", text="B005NPEUB2")) id3.add(TMED(encoding=major, text="CD")) id3.add( UFID(encoding=major, owner="http://musicbrainz.org", data=b"f151cb94-c909-46a8-ad99-fb77391abfb8")) id3.add(TIT2(encoding=major, text="Sinner's Prayer")) id3.add( TXXX(encoding=major, desc="MusicBrainz Artist Id", text=[ "3fe817fc-966e-4ece-b00a-76be43e7e73c", "984f8239-8fe1-4683-9c54-10ffb14439e9" ])) id3.add(TPE1(encoding=major, text=["Beth Hart & Joe Bonamassa"])) id3.add( TXXX(encoding=major, desc="Artists", text=["Beth Hart", "Joe Bonamassa"])) id3.add(TSRC(encoding=major, text=["NLB931100460", "USMH51100098"])) id3.add( TXXX(encoding=major, desc="MusicBrainz Release Track Id", text="d062f484-253c-374b-85f7-89aab45551c7")) id3.add( IPLS(encoding=major, people=[["engineer", "James McCullagh"], ["engineer", "Jared Kvitka"], ["arranger", "Jeff Bova"], ["producer", "Roy Weisman"], ["piano", "Beth Hart"], ["guitar", "Blondie Chaplin"], ["guitar", "Joe Bonamassa"], ["percussion", "Anton Fig"], ["drums", "Anton Fig"], ["keyboard", "Arlan Schierbaum"], ["bass guitar", "Carmine Rojas"], ["orchestra", "The Bovaland Orchestra"], ["vocals", "Beth Hart"], ["vocals", "Joe Bonamassa"]])), id3.add(TORY(encoding=major, text="2011")) id3.add(TYER(encoding=major, text="2011")) id3.add(TDAT(encoding=major, text="2709"))
def MP3Tagger(self): Caminho = self.lineEdit.text() if Caminho == "": QMessageBox.about(self, "ERRO", "Nenhum caminho especificado.") else: File = glob.glob(Caminho + "/*.mp3") for i in File: # Caminho completo do arquivo com extensão self.label_10.setText(_translate("MainWindow", "")) QtWidgets.QApplication.processEvents() Path = os.path.dirname(i) # Caninho completo da pasta do arquivo Name1 = os.path.basename(i) # Nome do arquivo completo com extensão Name2 = os.path.splitext(Name1) # Nome do arquivo dividido na extensão Name3 = Name2[0].split(" - ") # Nome do arquivo divido no artista e musica Name4 = ''.join(i for i in Name3[0] if not i.isdigit()) # Nome da música sem os números print("Caminho: " + i) print("Name1: " + str(Name1)) print("Name2: " + str(Name2)) print("Name3: " + str(Name3)) print("Name4: " + str(Name4)) self.label_10.setText(_translate("MainWindow", "Renomeando arquivo...")) QtWidgets.QApplication.processEvents() os.rename(i, Path + "\\" + Name3[1] + " -" + Name4 + ".mp3") # Renomeia o arquivo self.label_10.setText(_translate("MainWindow", "Buscando metadados no banco de dados do Spotify...")) QtWidgets.QApplication.processEvents() meta_tags = spotify_tools.generate_metadata(Name3[1] + " -" + Name4) # Gera as tags do mp3 if meta_tags == None: continue else: self.label_6.setText(_translate("MainWindow", str(meta_tags['artists'][0]['name']))) self.label_7.setText(_translate("MainWindow", str(meta_tags['name']))) self.label_8.setText(_translate("MainWindow", str(meta_tags['album']['name']))) self.label_10.setText(_translate("MainWindow", "Aplicando tags...")) ScriptFolder = os.path.dirname(os.path.realpath(sys.argv[0])) IMG = open(ScriptFolder + "\\" + 'cover2.jpg', 'wb') IMG.write(urllib.request.urlopen(meta_tags['album']['images'][0]['url']).read()) IMG.close() time.sleep(1) self.GenericCover3 = QPixmap('cover2.jpg') self.GenericCover4 = self.GenericCover3.scaled(141, 141) self.graphicsView.setPixmap(self.GenericCover4) QtWidgets.QApplication.processEvents() audiofile = MP3(Path + "\\" + Name3[1] + " -" + Name4 + ".mp3") audiofile.tags = None # Exclui qualquer tag antes de aplicar as novas (previne erro) audiofile.add_tags(ID3=EasyID3) audiofile['artist'] = meta_tags['artists'][0]['name'] audiofile['albumartist'] = meta_tags['artists'][0]['name'] audiofile['album'] = meta_tags['album']['name'] audiofile['title'] = meta_tags['name'] audiofile['tracknumber'] = [meta_tags['track_number'], meta_tags['total_tracks']] audiofile['discnumber'] = [meta_tags['disc_number'], 0] audiofile['date'] = meta_tags['release_date'] audiofile['originaldate'] = meta_tags['release_date'] audiofile['media'] = meta_tags['type'] audiofile['author'] = meta_tags['artists'][0]['name'] audiofile['lyricist'] = meta_tags['artists'][0]['name'] audiofile['arranger'] = meta_tags['artists'][0]['name'] audiofile['performer'] = meta_tags['artists'][0]['name'] audiofile['website'] = meta_tags['external_urls']['spotify'] audiofile['length'] = str(meta_tags['duration_ms'] / 1000.0) if meta_tags['publisher']: audiofile['encodedby'] = meta_tags['publisher'] if meta_tags['genre']: audiofile['genre'] = meta_tags['genre'] if meta_tags['copyright']: audiofile['copyright'] = meta_tags['copyright'] if meta_tags['external_ids']['isrc']: audiofile['isrc'] = meta_tags['external_ids']['isrc'] audiofile.save(v2_version=3) # For supported id3 tags: # https://github.com/quodlibet/mutagen/blob/master/mutagen/id3/_frames.py # Each class represents an id3 tag audiofile = ID3(Path + "\\" + Name3[1] + " -" + Name4 + ".mp3") year, *_ = meta_tags['release_date'].split('-') audiofile['TORY'] = TORY(encoding=3, text=year) audiofile['TYER'] = TYER(encoding=3, text=year) audiofile['TPUB'] = TPUB(encoding=3, text=meta_tags['publisher']) audiofile['COMM'] = COMM(encoding=3, text=meta_tags['external_urls']['spotify']) if meta_tags['lyrics']: audiofile['USLT'] = USLT(encoding=3, desc=u'Lyrics', text=meta_tags['lyrics']) try: albumart = urllib.request.urlopen(meta_tags['album']['images'][0]['url']) audiofile['APIC'] = APIC(encoding=3, mime='image/jpeg', type=3, desc=u'Cover', data=albumart.read()) albumart.close() except IndexError: pass audiofile.save(v2_version=3) self.label_10.setText(_translate("MainWindow", "Concluído.")) QtWidgets.QApplication.processEvents() time.sleep(2) # pausa dramática # Some com os textos: self.label_10.setText(_translate("MainWindow", "")) QtWidgets.QApplication.processEvents() QMessageBox.about(self, "Concluído", "Operação concluída.")
def test_tory(self): id3 = ID3() id3.version = (2, 3) id3.add(TORY(encoding=0, text="2006")) id3.update_to_v24() self.failUnlessEqual(id3["TDOR"], "2006")