~jwiltshire/pogo/debian

« back to all changes in this revision

Viewing changes to src/remote.py

  • Committer: Jonathan Wiltshire
  • Date: 2010-12-20 23:52:57 UTC
  • Revision ID: git-v1:e24ab7d692aa9fecd89514fbd769b83b9db2dd55
Tags: upstream/0.3
Imported Upstream version 0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
#
 
3
# Author: Ingelrest François (Francois.Ingelrest@gmail.com)
 
4
#
 
5
# This program is free software; you can redistribute it and/or modify
 
6
# it under the terms of the GNU General Public License as published by
 
7
# the Free Software Foundation; either version 2 of the License, or
 
8
# (at your option) any later version.
 
9
#
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU Library General Public License for more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License
 
16
# along with this program; if not, write to the Free Software
 
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
18
 
 
19
import dbus, os.path, sys
 
20
 
 
21
(
 
22
    PLAY,
 
23
    PAUSE,
 
24
    NEXT,
 
25
    PREVIOUS,
 
26
    STOP,
 
27
    SET,
 
28
    ADD,
 
29
    CLEAR,
 
30
    SHUFFLE,
 
31
    VOLUME,
 
32
) = range(10)
 
33
 
 
34
(CMD_ARGS, CMD_HELP, CMD_NAME) = range(3)
 
35
 
 
36
commands = {
 
37
                'play':    ( '',                 'Start playing the current track',             PLAY    ),
 
38
                'pause':   ( '',                 'Pause or continue playing the current track', PAUSE   ),
 
39
                'next':    ( '',                 'Jump to the next track',                      NEXT    ),
 
40
                'prev':    ( '',                 'Jump to the previous track',                  PREVIOUS),
 
41
                'stop':    ( '',                 'Stop playback',                               STOP    ),
 
42
                'pl-set':  ( 'file1 file2...',   'Set the playlist to the given files',         SET     ),
 
43
                'pl-add':  ( 'file1 file2...',   'Append the given files to the playlist',      ADD     ),
 
44
                'pl-clr':  ( '',                 'Clear the playlist',                          CLEAR   ),
 
45
                'shuffle': ( '',                 'Shuffle the playlist',                        SHUFFLE ),
 
46
                'volume':  ( 'value (0 -- 100)', 'Set the volume',                              VOLUME  ),
 
47
           }
 
48
 
 
49
# Check the command line
 
50
cmdLineOk = False
 
51
 
 
52
if len(sys.argv) > 1:
 
53
    cmdName = sys.argv[1]
 
54
 
 
55
    if cmdName not in commands:                                    print '%s is not a valid command\n'     % cmdName
 
56
    elif len(sys.argv) == 2 and commands[cmdName][CMD_ARGS] != '': print '%s needs some arguments\n'       % cmdName
 
57
    elif len(sys.argv) > 2 and commands[cmdName][CMD_ARGS] == '':  print '%s does not take any argument\n' % cmdName
 
58
    else:                                                          cmdLineOk = True
 
59
 
 
60
if not cmdLineOk:
 
61
    print 'Usage: %s command [arg1 arg2...]\n' % os.path.basename(sys.argv[0])
 
62
    print 'Command  | Arguments        | Description'
 
63
    print '-------------------------------------------------------------------------'
 
64
    for cmd, data in sorted(commands.iteritems()):
 
65
        print '%s| %s| %s' % (cmd.ljust(9), data[CMD_ARGS].ljust(17), data[CMD_HELP])
 
66
    sys.exit(1)
 
67
 
 
68
# Connect to D-BUS
 
69
session        = dbus.SessionBus()
 
70
activeServices = session.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus').ListNames()
 
71
 
 
72
if 'org.mpris.pogo' not in activeServices:
 
73
    print 'Pogo is not running, or D-Bus support is not available'
 
74
    sys.exit(2)
 
75
 
 
76
cmd       = commands[cmdName][CMD_NAME]
 
77
player    = dbus.Interface(session.get_object('org.mpris.pogo', '/Player'),    'org.freedesktop.MediaPlayer')
 
78
tracklist = dbus.Interface(session.get_object('org.mpris.pogo', '/TrackList'), 'org.freedesktop.MediaPlayer')
 
79
 
 
80
if   cmd == SET:      tracklist.SetTracks(sys.argv[2:], True)
 
81
elif cmd == ADD:
 
82
    print 'Hello'
 
83
    tracklist.AddTracks(sys.argv[2:], False)
 
84
elif cmd == PLAY:     player.Play()
 
85
elif cmd == NEXT:     player.Next()
 
86
elif cmd == STOP:     player.Stop()
 
87
elif cmd == PAUSE:    player.Pause()
 
88
elif cmd == CLEAR:    tracklist.Clear()
 
89
elif cmd == VOLUME:   player.VolumeSet(int(sys.argv[2]))
 
90
elif cmd == SHUFFLE:  tracklist.SetRandom(True)
 
91
elif cmd == PREVIOUS: player.Prev()