Skip to content

Commit

Permalink
consolidate meta imports
Browse files Browse the repository at this point in the history
  • Loading branch information
regosen committed Jun 2, 2022
1 parent b82ccb2 commit 0aab5a7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
28 changes: 4 additions & 24 deletions get_cover_art/cover_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
from pathlib import Path

from .apple_downloader import AppleDownloader
from .meta.meta_mp3 import MetaMP3
from .meta.meta_mp4 import MetaMP4
from .meta.meta_flac import MetaFLAC
from .meta.meta_dsf import MetaDSF
from .meta.meta_opus import MetaOpus
from .meta.meta_vorbis import MetaVorbis
from .meta import get_meta

DEFAULTS = {
"art_size": "500",
Expand Down Expand Up @@ -141,27 +136,10 @@ def _find_folder_art(self, meta, folder):
return filename
return None

def _get_meta(self, path):
_base, ext = os.path.splitext(path.lower())
if ext == '.mp3':
return MetaMP3(path)
if ext == '.m4a':
return MetaMP4(path)
if ext == '.flac':
return MetaFLAC(path)
if ext == '.dsf':
return MetaDSF(path)
if ext == '.opus':
return MetaOpus(path)
if ext == '.ogg':
return MetaVorbis(path)
self.files_invalid.append(path)
return None

def scan_file(self, path):
art_folder = self.art_folder_override or os.path.split(path)[0]
try:
meta = self._get_meta(path)
meta = get_meta(path)
if meta:
filename = self._slugify(self.art_dest_filename.format(artist=meta.artist, album=meta.album, title=meta.title))
art_path = os.path.join(art_folder, filename)
Expand Down Expand Up @@ -212,6 +190,8 @@ def scan_file(self, path):
else:
self.ignore_artwork.add(art_path)
self.files_skipped.append(path)
else:
self.files_invalid.append(path)

except Exception as e:
print(f"ERROR: failed to process {path}, {type(e).__name__}: {str(e)}")
Expand Down
22 changes: 22 additions & 0 deletions get_cover_art/meta/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from .meta_mp3 import MetaMP3
from .meta_mp4 import MetaMP4
from .meta_flac import MetaFLAC
from .meta_dsf import MetaDSF
from .meta_opus import MetaOpus
from .meta_vorbis import MetaVorbis

EXT_TO_CONSTRUCTOR = {
'mp3': MetaMP3,
'm4a': MetaMP4,
'flac': MetaFLAC,
'dsf': MetaDSF,
'opus': MetaOpus,
'ogg': MetaVorbis,
}

def get_meta(path):
ext = path.split('.')[-1].lower()
constructor = EXT_TO_CONSTRUCTOR[ext]
if constructor:
return constructor(path)
return None

0 comments on commit 0aab5a7

Please sign in to comment.