1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-10 04:02:17 +00:00

Added support for embeded album art in MP3s

This commit is contained in:
Taizo Simpson 2018-10-08 15:31:15 -04:00
parent 29e462e0b8
commit befc460120
No known key found for this signature in database
GPG Key ID: D197B1197B2D4D68

View File

@ -9,10 +9,12 @@
import codecs import codecs
import mimetypes import mimetypes
import mutagen
import os.path import os.path
import requests import requests
import shlex import shlex
import subprocess import subprocess
import tempfile
from flask import request, Response, send_file from flask import request, Response, send_file
from flask import current_app from flask import current_app
@ -133,8 +135,17 @@ def download_media():
def cover_art(): def cover_art():
res = get_entity(Folder) res = get_entity(Folder)
if not res.cover_art or not os.path.isfile(os.path.join(res.path, res.cover_art)): if not res.cover_art or not os.path.isfile(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') raise NotFound('Cover art')
else:
cover_path = os.path.join(res.path, res.cover_art) cover_path = os.path.join(res.path, res.cover_art)
size = request.values.get('size') size = request.values.get('size')
if size: if size: