Browse Source

Use search_image to find cover file

pull/98/head
Oliverpool 9 years ago
parent
commit
044d9570ae
  1. 19
      patacrep/songs/__init__.py

19
patacrep/songs/__init__.py

@ -194,20 +194,23 @@ class Song:
""" """
raise NotImplementedError() 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""" """Return the fullpath of the cover file if found"""
filename = self.data.get('cov') filename = str(self.data.get('cov', ''))
if not filename: if not filename:
return default return default
dirname = os.path.dirname(self.fullpath) # Temporary hack: what should it contain exactly?
filepath = os.path.join(dirname, str(filename)) config = {
filepath += '.' 'datadir': datadir,
'filename': '',
}
extensions = ['jpg', 'png'] extensions = ['', '.jpg', '.png']
for extension in extensions: for extension in extensions:
if os.path.isfile(filepath + extension): fullpath = search_image(filename + extension, self.fullpath, config)
return filepath + extension if fullpath:
return fullpath
# How to handle when the cover should have been there ? # How to handle when the cover should have been there ?
# raise FileNotFoundError() # raise FileNotFoundError()

Loading…
Cancel
Save