fix tag picking for flac as flac uses different tag names
All checks were successful
Gitea/pysonic/pipeline/head This commit looks good

This commit is contained in:
dave 2022-06-02 15:17:12 -07:00
parent 6106fa9aa5
commit 2de8547ab7
5 changed files with 102 additions and 51 deletions

View File

@ -1,4 +1,4 @@
FROM ubuntu:focal
FROM dockermirror:5000/ubuntu:focal
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y ffmpeg

View File

@ -16,7 +16,6 @@ TRANSCODE_TIMEOUT = int(os.environ.get("PYSONIC_ENCODE_TIMEOUT", 5 * 60))
def extension(mime):
r = TYPE_TO_EXTENSION.get(mime)
print(f"getting extension for {mime}: {r}")
return r

View File

@ -5,7 +5,7 @@ from contextlib import closing
import mimetypes
from time import time
from threading import Thread
from pysonic.types import MUSIC_TYPES, MPX_TYPES, FLAC_TYPES, MUSIC_EXTENSIONS, IMAGE_EXTENSIONS, \
from pysonic.types import MUSIC_TYPES, WAV_TYPES, MPX_TYPES, FLAC_TYPES, MUSIC_EXTENSIONS, IMAGE_EXTENSIONS, \
TYPE_TO_EXTENSION, UNKNOWN_MIME
from mutagen.id3 import ID3
from mutagen import MutagenError
@ -314,6 +314,7 @@ class PysonicFilesystemScanner(object):
logging.error("failed to read audio information: %s", m)
return
# these fields are generic
try:
meta["length"] = int(audio.info.length)
except (ValueError, AttributeError):
@ -324,30 +325,61 @@ class PysonicFilesystemScanner(object):
# meta["kbitrate"] = int(bitrate / 1024)
except (ValueError, AttributeError):
pass
try:
meta["track"] = int(RE_NUMBERS.findall(''.join(audio['TRCK'].text))[0])
except (KeyError, IndexError):
pass
try:
meta["artist"] = ''.join(audio['TPE1'].text)
except KeyError:
pass
try:
meta["album"] = ''.join(audio['TALB'].text)
except KeyError:
pass
try:
meta["title"] = ''.join(audio['TIT2'].text)
except KeyError:
pass
try:
meta["year"] = audio['TDRC'].text[0].year
except (KeyError, IndexError):
pass
try:
meta["genre"] = audio['TCON'].text[0]
except (KeyError, IndexError):
pass
# these fields are format-specific
#TODO determine if having WAV_TYPES does anything at all
if ftype in MPX_TYPES or ftype in WAV_TYPES:
try:
meta["track"] = int(RE_NUMBERS.findall(''.join(audio['TRCK'].text))[0])
except (KeyError, IndexError):
pass
try:
meta["artist"] = ''.join(audio['TPE1'].text)
except KeyError:
pass
try:
meta["album"] = ''.join(audio['TALB'].text)
except KeyError:
pass
try:
meta["title"] = ''.join(audio['TIT2'].text)
except KeyError:
pass
try:
meta["year"] = audio['TDRC'].text[0].year
except (KeyError, IndexError):
pass
try:
meta["genre"] = audio['TCON'].text[0]
except (KeyError, IndexError):
pass
elif ftype in FLAC_TYPES:
try:
meta["track"] = int(audio["tracknumber"][0])
except (KeyError, IndexError):
pass
try:
meta["artist"] = audio["artist"][0]
except (KeyError, IndexError):
pass
try:
meta["album"] = audio["album"][0]
except (KeyError, IndexError):
pass
try:
meta["title"] = audio["title"][0]
except (KeyError, IndexError):
pass
try:
meta["year"] = int(audio["date"][0]) # TODO is this ever a full date?
except (KeyError, IndexError):
pass
try:
meta["genre"] = audio["genre"][0]
except (KeyError, IndexError):
pass
logging.info("got all media info from %s", fpath)
return meta

View File

@ -1,34 +1,48 @@
# known mimes
MIME_MPEG = "audio/mpeg"
KNOWN_MIMES = ["audio/mpeg", "audio/flac", "audio/x-wav", "image/jpeg", "image/png"]
MIME_FLAC = "audio/flac"
MIME_XFLAC = "audio/x-flac"
MUSIC_TYPES = ["audio/mpeg", "audio/flac", "audio/x-wav"]
MIME_XWAV = "audio/x-wav"
MPX_TYPES = ["audio/mpeg"]
MIME_JPEG = "image/jpeg"
MIME_PNG = "image/png"
MIME_GIF = "image/gif"
FLAC_TYPES = ["audio/flac"]
WAV_TYPES = ["audio/x-wav"]
# groupings of similar files by mime
KNOWN_MIMES = [MIME_MPEG, MIME_FLAC, MIME_XFLAC, MIME_XWAV, MIME_JPEG, MIME_PNG]
IMAGE_TYPES = ["image/jpeg", "image/png", "image/gif"]
MUSIC_TYPES = [MIME_MPEG, MIME_FLAC, MIME_XFLAC, MIME_XWAV]
MPX_TYPES = [MIME_MPEG]
FLAC_TYPES = [MIME_FLAC, MIME_XFLAC]
WAV_TYPES = [MIME_XWAV]
IMAGE_TYPES = [MIME_JPEG, MIME_PNG, MIME_GIF]
IMAGE_EXTENSIONS = ["jpg", "jpeg", "png", "gif"]
MUSIC_EXTENSIONS = ["mp3", "flac", "wav"]
TYPE_TO_EXTENSION = {
"audio/mpeg": "mp3",
"audio/flac": "flac",
"audio/x-wav": "wav",
"image/jpeg": "jpg",
"image/png": "png",
MIME_MPEG: "mp3",
MIME_FLAC: "flac",
MIME_XFLAC: "flac",
MIME_XWAV: "wav",
MIME_JPEG: "jpg",
MIME_PNG: "png",
}
EXTENSION_TO_TYPE = {
"mp3": "audio/mpeg",
"flac": "audio/flac",
"wav": "audio/x-wav",
"jpg": "image/jpeg",
"png": "image/png",
"mp3": MIME_MPEG,
"flac": MIME_FLAC,
"wav": MIME_XWAV,
"jpg": MIME_JPEG,
"png": MIME_PNG,
}

View File

@ -1,11 +1,17 @@
beautifulsoup4==4.6.0
bs4==0.0.1
cheroot==6.0.0
CherryPy==14.0.1
lxml==4.2.1
more-itertools==4.1.0
beautifulsoup4==4.11.1
cheroot==8.6.0
CherryPy==18.6.1
jaraco.classes==3.2.1
jaraco.collections==3.5.1
jaraco.context==4.1.1
jaraco.functools==3.5.0
jaraco.text==3.7.0
lxml==4.9.0
more-itertools==8.13.0
mutagen==1.40.0
portend==2.2
portend==3.1.0
pytz==2018.3
six==1.11.0
tempora==1.11
soupsieve==2.3.2.post1
tempora==5.0.1
zc.lockfile==2.0