From 7106d95cee3861f732bc5e331d1aa75be65439d6 Mon Sep 17 00:00:00 2001 From: Taizo Simpson Date: Mon, 8 Oct 2018 16:34:44 -0400 Subject: [PATCH] Added support for ID3 based metadata, OGG, and FLAC in album art extraction --- supysonic/api/media.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/supysonic/api/media.py b/supysonic/api/media.py index 63bc469..c958e0c 100644 --- a/supysonic/api/media.py +++ b/supysonic/api/media.py @@ -7,6 +7,7 @@ # # Distributed under terms of the GNU AGPLv3 license. +import base64 import codecs import mimetypes import mutagen @@ -140,9 +141,16 @@ def cover_art(): cover_path = temp_cover.name for track in res.tracks: song = mutagen.File(track.path) - if type(song) == mutagen.mp3.MP3 and len(song.tags.getall('APIC')) > 0: + if isinstance(song.tags, mutagen.id3.ID3Tags) and len(song.tags.getall('APIC')) > 0: temp_cover.write(song.tags.getall('APIC')[0].data) break + elif isinstance(song, mutagen.flac.FLAC) and len(song.pictures): + temp_cover.write(song.pictures[0].data) + break + elif isinstance(song.tags, mutagen._vorbis.VCommentDict) and 'METADATA_BLOCK_PICTURE' in song.tags and len(song.tags['METADATA_BLOCK_PICTURE']) > 0: + picture = mutagen.flac.Picture(base64.b64decode(song.tags['METADATA_BLOCK_PICTURE'][0])) + temp_cover.write(picture.data) + break else: raise NotFound('Cover art') else: