1
# -*- coding: utf-8 -*-
3
# Author: Ingelrest François (Francois.Ingelrest@gmail.com)
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.
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.
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
19
import dbus, os.path, sys
34
(CMD_ARGS, CMD_HELP, CMD_NAME) = range(3)
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 ),
49
# Check the command line
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
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])
69
session = dbus.SessionBus()
70
activeServices = session.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus').ListNames()
72
if 'org.mpris.pogo' not in activeServices:
73
print 'Pogo is not running, or D-Bus support is not available'
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')
80
if cmd == SET: tracklist.SetTracks(sys.argv[2:], True)
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()