~ubuntu-branches/ubuntu/vivid/gpodder/vivid

« back to all changes in this revision

Viewing changes to share/gpodder/extensions/enqueue_in_mediaplayer.py

  • Committer: Package Import Robot
  • Author(s): tony mancill
  • Date: 2013-04-12 22:07:02 UTC
  • mfrom: (5.2.27 sid)
  • Revision ID: package-import@ubuntu.com-20130412220702-mux8v9r8zt2jin0x
Tags: 3.5.1-1
* New upstream release.
* d/control: declare versioned dependency on python-gtk2 (>= 2.16)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
__category__ = 'interface'
20
20
__only_for__ = 'gtk'
21
21
 
22
 
AMAROK = (['amarok', '--play', '--append'],
23
 
    '%s/%s' % (_('Enqueue in'), 'Amarok'))
24
 
VLC = (['vlc', '--started-from-file', '--playlist-enqueue'],
25
 
    '%s/%s' % (_('Enqueue in'), 'VLC'))
26
 
 
 
22
class Player:
 
23
    def __init__(self, application, command):
 
24
        self.title = '/'.join((_('Enqueue in'), application))
 
25
        self.command = command
 
26
        self.gpodder = None
 
27
 
 
28
    def is_installed(self):
 
29
        return util.find_command(self.command[0]) is not None
 
30
 
 
31
    def enqueue_episodes(self, episodes):
 
32
        filenames = [episode.get_playback_url() for episode in episodes]
 
33
 
 
34
        subprocess.Popen(self.command + filenames,
 
35
                stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 
36
 
 
37
        for episode in episodes:
 
38
            episode.playback_mark()
 
39
            self.gpodder.update_episode_list_icons(selected=True)
 
40
 
 
41
 
 
42
PLAYERS = [
 
43
    # Amarok, http://amarok.kde.org/
 
44
    Player('Amarok', ['amarok', '--play', '--append']),
 
45
 
 
46
    # VLC, http://videolan.org/
 
47
    Player('VLC', ['vlc', '--started-from-file', '--playlist-enqueue']),
 
48
 
 
49
    # Totem, https://live.gnome.org/Totem
 
50
    Player('Totem', ['totem', '--enqueue']),
 
51
]
27
52
 
28
53
class gPodderExtension:
29
54
    def __init__(self, container):
30
55
        self.container = container
31
56
 
32
 
        # Check media players
33
 
        self.amarok_available = self.check_mediaplayer(AMAROK[0][0])
34
 
        self.vlc_available = self.check_mediaplayer(VLC[0][0])
35
 
 
36
 
    def check_mediaplayer(self, cmd):
37
 
        return not (util.find_command(cmd) == None)
38
 
 
39
 
    def _enqueue_episodes_cmd(self, episodes, cmd):
40
 
        filenames = [episode.get_playback_url() for episode in episodes]
41
 
 
42
 
        vlc = subprocess.Popen(cmd + filenames,
43
 
            stdout=subprocess.PIPE, stderr=subprocess.PIPE
44
 
        )
45
 
 
46
 
    def enqueue_episodes_amarok(self, episodes):
47
 
        self._enqueue_episodes_cmd(episodes, AMAROK[0])
48
 
 
49
 
    def enqueue_episodes_vlc(self, episodes):
50
 
        self._enqueue_episodes_cmd(episodes, VLC[0])
 
57
        # Only display media players that can be found at extension load time
 
58
        self.players = filter(lambda player: player.is_installed(), PLAYERS)
 
59
 
 
60
    def on_ui_object_available(self, name, ui_object):
 
61
        if name == 'gpodder-gtk':
 
62
            for p in self.players:
 
63
                p.gpodder = ui_object
51
64
 
52
65
    def on_episodes_context_menu(self, episodes):
53
 
        if not [e for e in episodes if e.file_exists()]:
 
66
        if not any(e.file_exists() for e in episodes):
54
67
            return None
55
68
 
56
 
        menu_entries = []
57
 
 
58
 
        if self.amarok_available:
59
 
            menu_entries.append((AMAROK[1], self.enqueue_episodes_amarok))
60
 
 
61
 
        if self.vlc_available:
62
 
            menu_entries.append((VLC[1], self.enqueue_episodes_vlc))
63
 
 
64
 
        return menu_entries
 
69
        return [(p.title, p.enqueue_episodes) for p in self.players]
 
70