Playback multiple files on Maemo (bug 1037)
Create a temporary M3U playlist and send its filename to the Nokia Media Player, as this is the only way to open multiple files at once with the built-in Media Player.
This commit is contained in:
parent
56aea051b1
commit
82e5f51768
|
@ -2147,9 +2147,17 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
|
||||
# Open episodes with system default player
|
||||
if 'default' in groups:
|
||||
for filename in groups['default']:
|
||||
log('Opening with system default: %s', filename, sender=self)
|
||||
util.gui_open(filename)
|
||||
if gpodder.ui.maemo:
|
||||
# The Nokia Media Player app does not support receiving multiple
|
||||
# file names via D-Bus, so we simply place all file names into a
|
||||
# temporary M3U playlist and open that with the Media Player.
|
||||
m3u_filename = os.path.join(gpodder.home, 'gpodder_open_with.m3u')
|
||||
util.write_m3u_playlist(m3u_filename, groups['default'], extm3u=False)
|
||||
util.gui_open(m3u_filename)
|
||||
else:
|
||||
for filename in groups['default']:
|
||||
log('Opening with system default: %s', filename, sender=self)
|
||||
util.gui_open(filename)
|
||||
del groups['default']
|
||||
elif gpodder.ui.maemo and groups:
|
||||
# When on Maemo and not opening with default, show a notification
|
||||
|
|
|
@ -519,20 +519,8 @@ class PodcastChannel(PodcastModelObject):
|
|||
return
|
||||
|
||||
log('Writing playlist to %s', m3u_filename, sender=self)
|
||||
f = open(m3u_filename, 'w')
|
||||
f.write('#EXTM3U\n')
|
||||
|
||||
for episode in PodcastEpisode.sort_by_pubdate(downloaded_episodes):
|
||||
if episode.was_downloaded(and_exists=True):
|
||||
filename = episode.local_filename(create=False)
|
||||
assert filename is not None
|
||||
|
||||
if os.path.dirname(filename).startswith(os.path.dirname(m3u_filename)):
|
||||
filename = filename[len(os.path.dirname(m3u_filename)+os.sep):]
|
||||
f.write('#EXTINF:0,'+self.title+' - '+episode.title+' ('+episode.cute_pubdate()+')\n')
|
||||
f.write(filename+'\n')
|
||||
|
||||
f.close()
|
||||
util.write_m3u_playlist(m3u_filename, \
|
||||
PodcastEpisode.sort_by_pubdate(downloaded_episodes))
|
||||
|
||||
def get_episode_by_url(self, url):
|
||||
return self.db.load_single_episode(self, \
|
||||
|
@ -1162,7 +1150,19 @@ class PodcastEpisode(PodcastModelObject):
|
|||
except:
|
||||
log('Cannot format pubDate (time) for "%s".', self.title, sender=self)
|
||||
return '0000'
|
||||
|
||||
|
||||
def playlist_title(self):
|
||||
"""Return a title for this episode in a playlist
|
||||
|
||||
The title will be composed of the podcast name, the
|
||||
episode name and the publication date. The return
|
||||
value is the canonical representation of this episode
|
||||
in playlists (for example, M3U playlists).
|
||||
"""
|
||||
return '%s - %s (%s)' % (self.channel.title, \
|
||||
self.title, \
|
||||
self.cute_pubdate())
|
||||
|
||||
def cute_pubdate(self):
|
||||
result = util.format_date(self.pubDate)
|
||||
if result is None:
|
||||
|
|
|
@ -1507,3 +1507,39 @@ def detect_device_type():
|
|||
|
||||
return 'desktop'
|
||||
|
||||
|
||||
def write_m3u_playlist(m3u_filename, episodes, extm3u=True):
|
||||
"""Create an M3U playlist from a episode list
|
||||
|
||||
If the parameter "extm3u" is False, the list of
|
||||
episodes should be a list of filenames, and no
|
||||
extended information will be written into the
|
||||
M3U files (#EXTM3U / #EXTINF).
|
||||
|
||||
If the parameter "extm3u" is True (default), then the
|
||||
list of episodes should be PodcastEpisode objects,
|
||||
as the extended metadata will be taken from them.
|
||||
"""
|
||||
f = open(m3u_filename, 'w')
|
||||
|
||||
if extm3u:
|
||||
# Mandatory header for extended playlists
|
||||
f.write('#EXTM3U\n')
|
||||
|
||||
for episode in episodes:
|
||||
if not extm3u:
|
||||
# Episode objects are strings that contain file names
|
||||
f.write(episode+'\n')
|
||||
continue
|
||||
|
||||
if episode.was_downloaded(and_exists=True):
|
||||
filename = episode.local_filename(create=False)
|
||||
assert filename is not None
|
||||
|
||||
if os.path.dirname(filename).startswith(os.path.dirname(m3u_filename)):
|
||||
filename = filename[len(os.path.dirname(m3u_filename)+os.sep):]
|
||||
f.write('#EXTINF:0,'+episode.playlist_title()+'\n')
|
||||
f.write(filename+'\n')
|
||||
|
||||
f.close()
|
||||
|
||||
|
|
Loading…
Reference in New Issue