From 6e1b47ac86aad92db8b2e69e8895dc33c7b03ef5 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Thu, 17 Sep 2015 15:06:29 +0200 Subject: [PATCH] Add method to retrieve the fullpath of the cover file --- patacrep/songs/__init__.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/patacrep/songs/__init__.py b/patacrep/songs/__init__.py index fbf02e36..aaee99cf 100644 --- a/patacrep/songs/__init__.py +++ b/patacrep/songs/__init__.py @@ -194,6 +194,24 @@ class Song: """ raise NotImplementedError() + def get_cover_fullpath(self, default=None): + filename = self.data.get('cov') + if not filename: + return default + + dirname = os.path.dirname(self.fullpath) + filepath = os.path.join(dirname, str(filename)) + filepath += '.' + + extensions = ['jpg', 'png'] + for extension in extensions: + if os.path.isfile(filepath + extension): + return filepath + extension + + # How to handle when the cover should have been there ? + # raise FileNotFoundError() + return default + def unprefixed_title(title, prefixes): """Remove the first prefix of the list in the beginning of title (if any). """