def to_ape(self, ape_meta: APEv2File) -> None: def add_if_exist(obj, tag_key): if obj is None: return if isinstance(obj, str): ape_meta.tags[tag_key] = APEValue(obj, TEXT) elif isinstance(obj, bytes): ape_meta.tags[tag_key] = APEValue(obj, BINARY) else: raise ValueError("Unknown tag value type") if ape_meta.tags is None: ape_meta.add_tags() add_if_exist(self.title, 'ALBUM') add_if_exist(self.full_artist, 'ALBUM ARTIST') if self.cover: add_if_exist(b'fluss.jpg\x00' + self.cover, 'Cover Art (Front)') add_if_exist(self.genre, 'GENRE') add_if_exist(self.date, 'YEAR') if self.discnumber is not None: add_if_exist(str(self.discnumber), 'DISCNUMBER') if self.cuesheet: ape_meta.tags['CUESHEET'] = str(self.cuesheet) add_if_exist(self.cuesheet.catalog, 'CATALOG') add_if_exist(self.cuesheet.rems.get('UPC', None), 'UPC') add_if_exist(self.cuesheet.rems.get('COMMENT', None), 'COMMENT') ape_meta.save()
def use_ape(): audio = APEv2File(song_path) if not audio.tags: audio.add_tags() audio.tags.clear() audio.tags['title'] = song['name'] audio.tags['artist'] = song['artist'] audio.tags['album'] = song['album'] audio.save()
def getTagMediaAPE(self, pathfile): """Collect tag MP3 file media.""" # no Mutagen informations !! list_infostrack = self.getTagFile( pathfile, DBMediaDuration(pathfile).totalduration, 'audio/ape') #mediafile = APEv2(pathfile) #print(mediafile.pprint()) try: mediafile = APEv2File(pathfile) if mediafile: for tag in mediafile.keys(): if 'COVER' not in tag.upper(): list_infostrack.update( {tag.upper(): mediafile[tag][0]}) except: pass if 'TRACK' in list_infostrack.keys(): list_infostrack['TRACKNUMBER'] = list_infostrack['TRACK'] return list_infostrack
def artist_from_audio(file): audio = None if file[-5:] == '.flac': try: audio = FLAC(file) return artist_from_id3(audio) except FLACNoHeaderError: pass elif file[-4:] == '.mp3': try: audio = EasyMP3(file) return artist_from_id3(audio) except HeaderNotFoundError: pass elif file[-4:] == '.ape': try: audio = APEv2File(file) return artist_from_id3(audio) except APENoHeaderError: pass elif file[-4:] == '.wma': try: audio = ASF(file) if audio is None: return None artist = None try: artist = str(audio['WM/AlbumArtist'][0]) except KeyError: try: artist = str(audio['Author'][0]) except KeyError: return None return artist.strip() except ASFHeaderError: return None else: return None
def getAudioMetaData(service, ext): title = "" genre = "" artist = "" album = "" length = "" audio = None if fileExists("/tmp/.emcAudioTag.jpg"): os.remove("/tmp/.emcAudioTag.jpg") elif fileExists("/tmp/.emcAudioTag.png"): os.remove("/tmp/.emcAudioTag.png") elif fileExists("/tmp/.emcAudioTag.gif"): os.remove("/tmp/.emcAudioTag.gif") if service: path = service.getPath() if ext.lower() == ".mp3": try: audio = MP3(os.path.join(path), ID3 = EasyID3) except: audio = None elif ext.lower() == ".flac": try: audio = FLAC(os.path.join(path)) except: audio = None elif ext.lower() == ".ogg": try: audio = OggVorbis(os.path.join(path)) except: audio = None elif ext.lower() == ".mp4" or ext.lower() == ".m4a": try: audio = EasyMP4(os.path.join(path)) except: audio = None # first for older mutagen-package(under 1.27) # APEv2 is tagged from tools like "mp3tag" # no tagging in new mutagen.aac elif ext.lower() == ".aac": try: audio = APEv2File(os.path.join(path)) except: audio = None if audio: if ext.lower() != ".aac": length = str(datetime.timedelta(seconds=int(audio.info.length))) else: if isMutagenAAC: getlength = AAC(os.path.join(path)) length = str(datetime.timedelta(seconds=int(getlength.info.length))) else: length = str(datetime.timedelta(seconds=int(audio._Info.length))) title = audio.get('title', [service.getPath()])[0] try: genre = audio.get('genre', [''])[0] except: genre = "" artist = audio.get('artist', [''])[0] album = audio.get('album', [''])[0] # now we try to get embedded covers if ext.lower() == ".mp3": try: scover = ID3(service.getPath()) except: scover = None if scover: scovers = scover.getall("APIC") if len(scovers) > 0: try: ext = "." + scovers[0].mime.lower().split("/", -1)[1] writeTmpCover(scovers[0].data, ext) except Exception, e: emcDebugOut("[EMCMutagenSupport] Exception in Mp3EmbeddedCover: " + str(e)) elif ext.lower() == ".flac": try: scover = audio.pictures except: scover = None if scover: if scover[0].data: try: ext = "." + scover[0].mime.lower().split("/", -1)[1] writeTmpCover(scover[0].data, ext) except Exception, e: emcDebugOut("[EMCMutagenSupport] Exception in FlacEmbeddedCover: " + str(e)) elif ext.lower() == ".ogg": try: scover = audio except: scover = None if scover: for b64_data in scover.get("metadata_block_picture", []): try: data = base64.b64decode(b64_data) except (TypeError, ValueError): continue try: picture = Picture(data) except FLACError: continue try: ext = "." + picture.mime.lower().split("/", -1)[1] writeTmpCover(picture.data, ext) except Exception, e: emcDebugOut("[EMCMutagenSupport] Exception in OggEmbeddedCover: " + str(e))
def test_empty(self): f = APEv2File(os.path.join(DIR, "data", "xing.mp3")) self.assertFalse(f.items())
def setUp(self): self.audio = APEv2File("tests/data/click.mpc")
def setUp(self): self.audio = APEv2File(os.path.join(DATA_DIR, "click.mpc"))
def __init__(self, filename: str): self.file = APEv2File(filename)