Get preview file name from CustomDownload.partial_filename

Add 'custom_downloader' member var to DownloadTask. Use it in
episode.get_playback_url() to get a preview file name.

Also add episode.can_preview() method and use it in ep.can_play().
This commit is contained in:
Teemu Ikonen 2022-10-27 23:57:05 +03:00
parent 642bf7e738
commit 9690b13a3a
2 changed files with 14 additions and 5 deletions

View File

@ -717,6 +717,7 @@ class DownloadTask(object):
self.speed = 0.0
self.progress = 0.0
self.error_message = None
self.custom_downloader = None
# Have we already shown this task in a notification?
self._notification_shown = False
@ -898,6 +899,7 @@ class DownloadTask(object):
else:
downloader = DefaultDownloader.custom_downloader(self._config, self.episode)
self.custom_downloader = downloader
headers, real_url = downloader.retrieve_resume(self.tempname, self.status_updated)
new_mimetype = headers.get('content-type', self.__episode.mime_type)

View File

@ -480,7 +480,15 @@ class PodcastEpisode(PodcastModelObject):
"""
# gPodder.playback_episodes() filters selection with this method.
"""
return self.was_downloaded(and_exists=True) or self.can_stream(config)
return (self.was_downloaded(and_exists=True)
or self.can_preview()
or self.can_stream(config))
def can_preview(self):
return (self.downloading
and self.download_task.custom_downloader is not None
and self.download_task.custom_downloader.partial_filename is not None
and os.path.exists(self.download_task.custom_downloader.partial_filename))
def can_stream(self, config):
"""
@ -620,11 +628,10 @@ class PodcastEpisode(PodcastModelObject):
Also returns the filename of a partially downloaded file
in case partial (preview) playback is desired.
"""
url = self.local_filename(create=False)
if (allow_partial and self.can_preview()):
return self.download_task.custom_downloader.partial_filename
if (allow_partial and url is not None and
os.path.exists(url + '.partial')):
return url + '.partial'
url = self.local_filename(create=False)
if url is None or not os.path.exists(url):
# FIXME: may custom downloaders provide the real url ?