Allow streaming video episodes even if default audio player

a custom video player has to be defined
This commit is contained in:
Eric Le Lay 2020-09-12 14:36:11 +02:00
parent bc62e3bb4c
commit 8503fef689

View file

@ -2015,23 +2015,35 @@ class gPodder(BuilderWidget, dbus.service.Object):
self.update_podcast_list_model(set(e.channel.url for e in episodes))
self.db.commit()
def streaming_possible(self):
# User has to have a media player set on the Desktop, or else we
# would probably open the browser when giving a URL to xdg-open..
return (self.config.player and self.config.player != 'default')
def episode_player(self, episode):
file_type = episode.file_type()
if file_type == 'video' and self.config.videoplayer and \
self.config.videoplayer != 'default':
player = self.config.videoplayer
elif file_type == 'audio' and self.config.player and \
self.config.player != 'default':
player = self.config.player
else:
player = 'default'
return player
def streaming_possible(self, episode=None):
"""
Don't try streaming if the user has not defined a player
or else we would probably open the browser when giving a URL to xdg-open.
If an episode is given, we look at the audio or video player depending on its file type.
:return bool: if streaming is possible
"""
if episode:
player = self.episode_player(episode)
else:
player = self.config.player
return player and player != 'default'
def playback_episodes_for_real(self, episodes):
groups = collections.defaultdict(list)
for episode in episodes:
file_type = episode.file_type()
if file_type == 'video' and self.config.videoplayer and \
self.config.videoplayer != 'default':
player = self.config.videoplayer
elif file_type == 'audio' and self.config.player and \
self.config.player != 'default':
player = self.config.player
else:
player = 'default'
player = self.episode_player(episode)
# Mark episode as played in the database
episode.playback_mark()
@ -2103,7 +2115,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
def playback_episodes(self, episodes):
# We need to create a list, because we run through it more than once
episodes = list(Model.sort_episodes_by_pubdate(e for e in episodes if
e.was_downloaded(and_exists=True) or self.streaming_possible()))
e.was_downloaded(and_exists=True) or self.streaming_possible(e)))
try:
self.playback_episodes_for_real(episodes)
@ -2129,6 +2141,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
selection = self.treeAvailable.get_selection()
if selection.count_selected_rows() > 0:
(model, paths) = selection.get_selected_rows()
streaming_possible = self.streaming_possible()
for path in paths:
try:
@ -2153,10 +2166,11 @@ class gPodder(BuilderWidget, dbus.service.Object):
if episode.downloading:
can_cancel = True
else:
streaming_possible |= self.streaming_possible(episode)
can_download = True
can_download = can_download and not can_cancel
can_play = self.streaming_possible() or (can_play and not can_cancel and not can_download)
can_play = streaming_possible or (can_play and not can_cancel and not can_download)
can_delete = not can_cancel
if open_instead_of_play: