From befc4601206b317c1e40f3379e8b8659f738ccfb Mon Sep 17 00:00:00 2001 From: Taizo Simpson Date: Mon, 8 Oct 2018 15:31:15 -0400 Subject: [PATCH] Added support for embeded album art in MP3s --- supysonic/api/media.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/supysonic/api/media.py b/supysonic/api/media.py index 8ccf426..63bc469 100644 --- a/supysonic/api/media.py +++ b/supysonic/api/media.py @@ -9,10 +9,12 @@ import codecs import mimetypes +import mutagen import os.path import requests import shlex import subprocess +import tempfile from flask import request, Response, send_file from flask import current_app @@ -133,9 +135,18 @@ def download_media(): def cover_art(): res = get_entity(Folder) if not res.cover_art or not os.path.isfile(os.path.join(res.path, res.cover_art)): - raise NotFound('Cover art') - - cover_path = os.path.join(res.path, res.cover_art) + # Check for embeded metadata in songs + temp_cover = tempfile.NamedTemporaryFile() + 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: + temp_cover.write(song.tags.getall('APIC')[0].data) + break + else: + raise NotFound('Cover art') + else: + cover_path = os.path.join(res.path, res.cover_art) size = request.values.get('size') if size: size = int(size)