From 3ec17dbd3343b4109350b9928ffee765272de2ed Mon Sep 17 00:00:00 2001 From: Kevin Locke Date: Tue, 28 Jan 2020 15:41:43 -0700 Subject: [PATCH] Fix crash fetching cover art for unknown album Ripping an unknown album when cover art fetching is enabled (e.g. `whipper cd rip --unknown --cover-art complete`) causes whipper to crash with an error similar to the following: ```python Traceback (most recent call last): File "", line 1, in File ".../whipper/whipper/command/main.py", line 43, in main ret = cmd.do() File ".../whipper/whipper/command/basecommand.py", line 139, in do return self.cmd.do() File ".../whipper/whipper/command/basecommand.py", line 139, in do return self.cmd.do() File ".../whipper/whipper/command/cd.py", line 191, in do self.doCommand() File ".../whipper/whipper/command/cd.py", line 363, in doCommand self.program.metadata.mbid) AttributeError: 'NoneType' object has no attribute 'mbid' ``` due to accessing `self.program.metadata.mbid` when `self.program.metadata` is `None`. To avoid this, only attempt to get cover art when `self.program.metadata` is available. Also print a warning when the cover art can't be fetched to inform the user that it isn't being downloaded. Signed-off-by: Kevin Locke --- whipper/command/cd.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/whipper/command/cd.py b/whipper/command/cd.py index 4e44e12..7045ac0 100644 --- a/whipper/command/cd.py +++ b/whipper/command/cd.py @@ -358,9 +358,14 @@ Log files will log the path to tracks relative to this directory. "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 getattr(self.program.metadata, "mbid", None) is not None: + self.coverArtPath = self.program.getCoverArt( + dirname, + self.program.metadata.mbid) + else: + logger.warning("the cover art option '%s' won't be honored " + "because disc metadata isn't available", + self.options.fetch_cover_art) if self.options.fetch_cover_art == "file": self.coverArtPath = None # NOTE: avoid image embedding (hacky)