From 044d9570aea9a8b28e7db8247e5f8b067a88e8a8 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Thu, 17 Sep 2015 16:33:48 +0200 Subject: [PATCH] Use search_image to find cover file --- patacrep/songs/__init__.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/patacrep/songs/__init__.py b/patacrep/songs/__init__.py index b62d45ba..3c1ddf00 100644 --- a/patacrep/songs/__init__.py +++ b/patacrep/songs/__init__.py @@ -194,20 +194,23 @@ class Song: """ raise NotImplementedError() - def get_cover_fullpath(self, default=None): + def get_cover_fullpath(self, datadir, default=None): """Return the fullpath of the cover file if found""" - filename = self.data.get('cov') + filename = str(self.data.get('cov', '')) if not filename: return default - dirname = os.path.dirname(self.fullpath) - filepath = os.path.join(dirname, str(filename)) - filepath += '.' + # Temporary hack: what should it contain exactly? + config = { + 'datadir': datadir, + 'filename': '', + } - extensions = ['jpg', 'png'] + extensions = ['', '.jpg', '.png'] for extension in extensions: - if os.path.isfile(filepath + extension): - return filepath + extension + fullpath = search_image(filename + extension, self.fullpath, config) + if fullpath: + return fullpath # How to handle when the cover should have been there ? # raise FileNotFoundError()