New hack: mpd_random_playlist.c
[mpd-hacks.git] / weechat-mpd-ctl.py
blob694a287fc8a25a6c827e753a614f584dcfe29537
1 # Author: Skippy the Kangoo <Skippythekangoo AT yahoo DOT fr>
2 # This script manages basic controls of mpd (play/pause, next song, previous song, increase volume, decrease volume, display current song)
3 # Usage: /mpd toggle|next|prev|volume_up|volume_down|status
4 # Released under GNU GPL v2 or newer
6 import weechat
7 from os import popen
9 weechat.register ('mpd', '0.0.2', '', 'mpd control script')
11 weechat.add_command_handler('mpd', 'mpd', 'mpd control', 'toggle|next|prev|volume_up|volume_down|status', '', 'toggle|next|prev|volume_up|volume_down|status')
13 def toggle (server, args,):
14 popen('mpc toggle')
15 return weechat.PLUGIN_RC_OK
17 def next (server, args,):
18 popen('mpc next')
19 return weechat.PLUGIN_RC_OK
21 def prev (server, args,):
22 popen('mpc prev')
23 return weechat.PLUGIN_RC_OK
25 def volume_up (server, args,):
26 popen('mpc volume +10')
27 return weechat.PLUGIN_RC_OK
29 def volume_down (server, args,):
30 volume_down = popen('mpc volume -10')
31 return weechat.PLUGIN_RC_OK
33 def status (server, args,):
34 status = popen('mpc').readline().rstrip()
35 weechat.print_infobar(3, status)
36 return weechat.PLUGIN_RC_OK
38 def mpd(server, args):
40 largs = args.split(" ")
42 #strip spaces
43 while '' in largs:
44 largs.remove('')
45 while ' ' in largs:
46 largs.remove(' ')
48 if len(largs) == 0:
49 weechat.command("/help mpd")
50 return weechat.PLUGIN_RC_OK
51 else:
52 inchan = False
54 if largs[0] == 'toggle':
55 toggle(" ".join(largs[1:]), inchan)
56 elif largs[0] == 'next':
57 next(" ".join(largs[1:]), inchan)
58 elif largs[0] == 'prev':
59 prev(' '.join(largs[1:]), inchan)
60 elif largs[0] == 'volume_up':
61 volume_up(' '.join(largs[1:]), inchan)
62 elif largs[0] == 'volume_down':
63 volume_down(' '.join(largs[1:]), inchan)
64 elif largs[0] == 'status':
65 status(" ".join(largs[1:]), inchan)
66 return weechat.PLUGIN_RC_OK