Skip to content

Commit

Permalink
Modifications that allow dynamic loading of cover art.
Browse files Browse the repository at this point in the history
Episode art will only be downloaded when the episode is downloaded too and will be deleted when the episode is deleted.

**Note: get_cover() now returns full URIs instead of a path only**
  • Loading branch information
E.S. Rosenberg a.k.a. Keeper of the Keys committed Feb 17, 2021
1 parent 682760e commit 374315b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
15 changes: 7 additions & 8 deletions src/gpodder/coverart.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,9 @@ def __init__(self, core):

def get_cover(self, podcast, download=False, episode=None):
if episode:
if podcast.download_episode_art == True:
# Get episode art.
filename = episode.art_file
cover_url = episode.episode_art_url
else:
cover_url = None
# Get episode art.
filename = episode.art_file
cover_url = episode.episode_art_url

else:
# Get podcast cover.
Expand All @@ -67,7 +64,7 @@ def get_cover(self, podcast, download=False, episode=None):
# Return already existing files
for extension in self.EXTENSIONS:
if os.path.exists(filename + extension):
return filename + extension
return 'file://' + filename + extension

# If allowed to download files, do so here
if download:
Expand Down Expand Up @@ -104,8 +101,10 @@ def get_cover(self, podcast, download=False, episode=None):
with open(temp_filename, 'wb') as fp:
fp.write(data)

return filename + extension
return 'file://' + filename + extension
except Exception as e:
logger.warn('Cannot save cover art', exc_info=True)
else:
return cover_url

return None
11 changes: 7 additions & 4 deletions src/gpodder/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ def delete_download(self):
if filename is not None:
util.delete_file(filename)

art_filename = self.art_file
if art_filename is not None:
for extension in self.podcast.model.core.cover_downloader.EXTENSIONS:
if os.path.exists(art_filename + extension):
art_filename = art_filename + extension
util.delete_file(art_filename)

self.state = gpodder.STATE_DELETED
self.is_new = False
self.save()
Expand Down Expand Up @@ -758,10 +765,6 @@ def _consume_custom_feed(self, custom_feed):
# Add new episodes to episodes
self.episodes.extend(new_episodes)

# Verify that all episode art is up-to-date
for episode in self.episodes:
self.model.core.cover_downloader.get_cover(self, download=True, episode=episode)

# Sort episodes by pubdate, descending
self.episodes.sort(key=lambda e: e.published, reverse=True)

Expand Down

0 comments on commit 374315b

Please sign in to comment.