2011-11-06 19:25:30 +00:00
# a plugin adding a command to manipulate an MPD instance
from plugin import BasePlugin
from common import shell_split
import mpd
class Plugin ( BasePlugin ) :
def init ( self ) :
2011-11-07 22:32:21 +00:00
self . add_command ( ' mpd ' , self . command_mpd , " Usage: /mpd [full] \n Mpd: sends a message showing the current song of an MPD instance. If full is provided, the message is more verbose. " , self . completion_mpd )
2011-11-06 19:25:30 +00:00
def command_mpd ( self , args ) :
args = shell_split ( args )
2011-11-06 19:31:19 +00:00
c = mpd . MPDClient ( )
2011-11-06 20:36:43 +00:00
c . connect ( host = self . config . get ( ' host ' , ' localhost ' ) , port = self . config . get ( ' port ' , ' 6600 ' ) )
2011-11-06 19:29:46 +00:00
password = self . config . get ( ' password ' , ' ' )
if password :
2011-11-06 19:41:42 +00:00
c . password ( password )
2011-11-06 19:25:30 +00:00
current = c . currentsong ( )
current_time = float ( c . status ( ) [ ' elapsed ' ] )
s = ' %(artist)s - %(title)s ( %(album)s ) ' % current
if ' full ' in args :
pourcentage = int ( current_time / float ( current [ ' time ' ] ) * 10 )
s + = ' \x19 2[ \x19 1 ' + ' - ' * ( pourcentage - 1 ) + ' \x19 3+ ' + ' \x19 1 ' + ' - ' * ( 10 - pourcentage - 1 ) + ' \x19 2] \x19 o '
if not self . core . send_message ( ' %s ' % ( s , ) ) :
self . core . information ( ' Cannot send result ( %s ), this is not a conversation tab ' % result )
def completion_mpd ( self , the_input ) :
return the_input . auto_completion ( [ ' full ' ] )