All pastes #1659733 Raw Edit

Skippythekangoo

public text v1 · immutable
#1659733 ·published 2009-11-06 17:10 UTC
rendered paste body
# Author: Skippy the Kangoo <Skippythekangoo AT yahoo DOT fr>
# This script manages basic controls of mpd (play/pause, next song, previous song, increase volume, decrease volume, display current song) 
# Usage: /mpd toggle|next|prev|volume_up|volume_down|status
# Released under GNU GPL v2 or newer

import weechat
from mpd import *

SCRIPT_NAME = "gstmpd"
SCRIPT_AUTHOR  = "Skippy the Kangoo <Skippythekangoo AT yahoo DOT fr"
SCRIPT_VERSION = "0.1-dev"
SCRIPT_LICENSE = "GPL3"
SCRIPT_DESC    = "WeeChat mpd manager"
SCRIPT_DISCHARGE = "disconnect"
SCRIPT_CHARSET =""

weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,SCRIPT_DESC, SCRIPT_DISCHARGE, SCRIPT_CHARSET)

host = 'localhost'
port = 6600
client = MPDClient()

def connect():
	global host, port, client
	client.connect(host, port)
	status = client.status()
	weechat.prnt("", "host : %s" % host)
	weechat.prnt("", "port : %s" % port)
	weechat.prnt("", "%s" % client)
	weechat.prnt("", "%s" % status["state"])
connect()

status = client.status()

def disconnect():
	global client, status
	weechat.prnt("", "%s" % status["state"])
	weechat.prnt("", "%s" % client)
	client.close()
	client.disconnect()
	return weechat.WEECHAT_RC_OK

def play():
	global client, status
	client.play()
	weechat.prnt("", "%s" % status["state"])
	return weechat.WEECHAT_RC_OK

def pause():
	global client, status
	client.pause()
	weechat.prnt("", "%s" % status["state"])
	return weechat.WEECHAT_RC_OK

def toggle():
	global client, status
	if status["state"] == pause:
		client.play()
	else:
		client.pause()
	weechat.prnt("", "%s" % status["state"])
	return weechat.WEECHAT_RC_OK

def stop():
	global client
	client.stop()
	return weechat.WEECHAT_RC_OK

def next():
	global client
	client.next()
	return weechat.WEECHAT_RC_OK

def previous():
	global client
	client.previous()
	return weechat.WEECHAT_RC_OK

def gstmpd(server, args):
	largs = args.split(" ")
	# strip spaces
	while '' in largs:
        	largs.remove('')
	while ' ' in largs:
        	largs.remove(' ')

	if len(largs) ==  0:
#		weechat.command("/help gstmpd")
		weechat.prnt("", "crotte")
	else:
		if largs[0] == 'toggle':
			toggle()
	return weechat.PLUGIN_RC_OK