Support fetching cover art images from the Cover Art Archive
Add option `--cover-art` to `whipper cd rip` command which accepts three values: - `file`: save the downloaded cover image as standalone file in the rip folder (named `cover.jpg`) - `embed`: embed the download cover image into all the ripped audio tracks (no standalone file will be kept) - `complete`: save standalone cover image as standalone file and embed it into all the ripped audio tracks (`file` + `embed`) Every cover art is fetched from the Cover Art Archive as JPEG thumbnail with a maximum dimension of 500px. Other supported values for the thumbnails are 250, 500 and 1200 (currently only some images have a corresponding 1200px sized thumbnail). This feature introduces an optional dependency on the `Pillow` module which is required for the decoding of the cover file (required by the `embed` and `complete` option values). Problem: - EmbedPicTureTask shouldn't be a task. Signed-off-by: ABCbum <kimlong221002@gmail.com> Co-authored-by: JoeLametta <JoeLametta@users.noreply.github.com> Signed-off-by: JoeLametta <JoeLametta@users.noreply.github.com>
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
|
||||
import argparse
|
||||
import cdio
|
||||
import importlib.util
|
||||
import os
|
||||
import glob
|
||||
import logging
|
||||
@@ -290,6 +291,14 @@ Log files will log the path to tracks relative to this directory.
|
||||
help="whether to continue ripping if "
|
||||
"the disc is a CD-R",
|
||||
default=False)
|
||||
self.parser.add_argument('-C', '--cover-art',
|
||||
action="store", dest="fetch_cover_art",
|
||||
help="Fetch cover art and save it as "
|
||||
"standalone file, embed into FLAC files "
|
||||
"or perform both actions: file, embed, "
|
||||
"complete option values respectively",
|
||||
choices=['file', 'embed', 'complete'],
|
||||
default=None)
|
||||
|
||||
def handle_arguments(self):
|
||||
self.options.output_directory = os.path.expanduser(
|
||||
@@ -342,6 +351,19 @@ Log files will log the path to tracks relative to this directory.
|
||||
logger.info("creating output directory %s", dirname)
|
||||
os.makedirs(dirname)
|
||||
|
||||
self.coverArtPath = None
|
||||
if (self.options.fetch_cover_art in {"embed", "complete"} and
|
||||
importlib.util.find_spec("PIL") is None):
|
||||
logger.warning("the cover art option '%s' won't be honored "
|
||||
"because the 'pillow' module isn't available",
|
||||
self.options.fetch_cover_art)
|
||||
elif self.options.fetch_cover_art in {"file", "embed", "complete"}:
|
||||
self.coverArtPath = self.program.getCoverArt(
|
||||
dirname,
|
||||
self.program.metadata.mbid)
|
||||
if self.options.fetch_cover_art == "file":
|
||||
self.coverArtPath = None # NOTE: avoid image embedding (hacky)
|
||||
|
||||
# FIXME: turn this into a method
|
||||
def _ripIfNotRipped(number):
|
||||
logger.debug('ripIfNotRipped for track %d', number)
|
||||
@@ -412,7 +434,8 @@ Log files will log the path to tracks relative to this directory.
|
||||
what='track %d of %d%s' % (
|
||||
number,
|
||||
len(self.itable.tracks),
|
||||
extra))
|
||||
extra),
|
||||
coverArtPath=self.coverArtPath)
|
||||
break
|
||||
# FIXME: catching too general exception (Exception)
|
||||
except Exception as e:
|
||||
@@ -474,6 +497,11 @@ Log files will log the path to tracks relative to this directory.
|
||||
continue
|
||||
_ripIfNotRipped(i + 1)
|
||||
|
||||
if (self.options.fetch_cover_art == "embed" and
|
||||
self.coverArtPath is not None):
|
||||
logger.debug('deleting cover art file at: %r', self.coverArtPath)
|
||||
os.remove(self.coverArtPath)
|
||||
|
||||
logger.debug('writing cue file for %r', discName)
|
||||
self.program.writeCue(discName)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user