Compare commits

..

2 Commits

Author SHA1 Message Date
3bf2ad38c2 Print warning if album art isn't named correctly 2025-01-18 13:40:27 +00:00
4d011c0d5d Copy album art in separate method 2025-01-18 12:34:05 +00:00

View File

@ -13,7 +13,6 @@ class Transcoder:
def transcode(self): def transcode(self):
transcode_list = [] transcode_list = []
file_whitelist = ['.jpg', '.jpeg', '.png']
for artist in self.input_root.iterdir(): for artist in self.input_root.iterdir():
if artist.is_dir(): if artist.is_dir():
artist_out = Path(self.output_root) / artist.name artist_out = Path(self.output_root) / artist.name
@ -27,11 +26,10 @@ class Transcoder:
album_out.mkdir() album_out.mkdir()
done_file = album / 'DONE' done_file = album / 'DONE'
open(done_file, 'a').close() open(done_file, 'a').close()
self.copy_album_art(album, album_out)
for file in album.iterdir(): for file in album.iterdir():
if file.is_file() and file.suffix.lower() == '.flac': if file.is_file() and file.suffix.lower() == '.flac':
transcode_list.append((str(file), str(album_out / f"{file.stem}.{self.extension}"))) transcode_list.append((str(file), str(album_out / f"{file.stem}.{self.extension}")))
elif file.is_file() and file.suffix.lower() in file_whitelist:
shutil.copy(file, album_out / file.name)
else: else:
print(f"Warning, skipping non-dir '{album}' found in artist '{artist.parts[-1]}'") print(f"Warning, skipping non-dir '{album}' found in artist '{artist.parts[-1]}'")
continue continue
@ -70,3 +68,18 @@ class Transcoder:
except Exception: except Exception:
return f"ERROR: Transcoding of '{in_track}' failed." return f"ERROR: Transcoding of '{in_track}' failed."
@staticmethod
def copy_album_art(in_dir: Path, out_dir: Path, file_whitelist: list = None):
if file_whitelist is None:
file_whitelist = ['.jpg', '.jpeg', '.png']
art_file_name = "cover.jpg"
art_found = False
for file in in_dir.iterdir():
if file.is_file() and file.suffix.lower() in file_whitelist:
if file.name == art_file_name:
art_found = True
shutil.copy(file, out_dir / file.name)
if not art_found:
print(f"Warning: {art_file_name} not found in {in_dir}")