Skip to content

Commit 4d28ef8

Browse files
author
E.S. Rosenberg a.k.a. Keeper of the Keys
committed
Add art_file() property to PodcastEpisode, attempts to get the filename from the URL, if it fails uses guid.
1 parent 5d4036a commit 4d28ef8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/gpodder/model.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545

4646
import minidb
4747

48+
from urllib.parse import urlparse
49+
4850

4951
class NoHandlerForURL(Exception):
5052
pass
@@ -96,6 +98,7 @@ class EpisodeModelFields(minidb.Model):
9698
description_html = str
9799
episode_art_url = str
98100

101+
99102
class PodcastModelFields(minidb.Model):
100103
title = str
101104
url = str
@@ -462,6 +465,19 @@ def update_from_dict(self, episode_dict):
462465
if k in episode_dict:
463466
setattr(self, k, episode_dict[k])
464467

468+
@property
469+
def art_file(self):
470+
if self.episode_art_url != None and self.episode_art_url != '':
471+
filename = self.guid
472+
try:
473+
url = urlparse(self.episode_art_url)
474+
filename = os.path.basename(url.path)
475+
except:
476+
logger.debug('urlparse failed for episode_art_url: %s', self.episode_art_url)
477+
478+
return os.path.join(self.podcast.save_dir, filename)
479+
return None
480+
465481

466482
class PodcastChannel(PodcastModelFields, PodcastModelMixin):
467483
_common_prefix = str

0 commit comments

Comments
 (0)