Skip to content

Commit

Permalink
Merge pull request #43 from Keeper-of-the-Keys/dynamic-cover-art
Browse files Browse the repository at this point in the history
Modifications that allow dynamic loading of cover art.
  • Loading branch information
Keeper-of-the-Keys authored Feb 17, 2021
2 parents 682760e + 374315b commit 5590c87
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 5590c87

Please sign in to comment.