Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Script per Xchat: mpd_music.py
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Forum italiano (Italian)
View previous topic :: View next topic  
Author Message
Disabled
Tux's lil' helper
Tux's lil' helper


Joined: 09 Jul 2004
Posts: 96

PostPosted: Fri Apr 01, 2005 1:25 pm    Post subject: Script per Xchat: mpd_music.py Reply with quote

Ieri, non sapendo che fare, ho deciso di scrivere un piccolo script per xchat che mi permettesse di controllare mpd...

Non so se qualcuno lo abbia già fatto, ma nel caso possa interessare, eccolo qui:

Code:
__module_name__ = "mpd_music"
__module_version__ = "0.9"
__module_description__ = "Controlla mpd"

import xchat
import commands
import os
import string

print "Grazie per avere caricato il modulo mpd_music"
print "I comandi di questo plugin sono:"
print "/music, /stop, /play, /pause, /next, /prev, /volume e /mpc_command"

def check_mpd():
    if commands.getoutput('ps -A | grep mpd')=='':
        print "Non hai mpd avviato..."
        return 0
    return 1

def display_title(word, word_eol, userdata):
    if check_mpd() == 0:
        return xchat.EAT_XCHAT
    titolo = commands.getoutput('mpc')
    titolo = string.split(titolo, '\n')
    if titolo[0][:6] != 'volume':
        xchat.command("me is playing %s"%(titolo[0]))
    else:
        print "Non stai ascoltando nessuna canzone con mpd..."
    return xchat.EAT_XCHAT
   
def music_next(word, word_eol, userdata):
    if check_mpd() == 0:
        return xchat.EAT_XCHAT
    os.system("mpc next")
    return xchat.EAT_ALL

def music_prev(word, word_eol, userdata):
    if check_mpd() == 0:
        return xchat.EAT_XCHAT
    os.system("mpc prev")
    return xchat.EAT_ALL
   
def music_toggle(word, word_eol, userdata):
    if check_mpd() == 0:
        return xchat.EAT_XCHAT
    os.system("mpc toggle")
    return xchat.EAT_ALL

def music_stop(word, word_eol, userdata):
    if check_mpd() == 0:
        return xchat.EAT_XCHAT
    os.system("mpc stop")
    return xchat.EAT_ALL

def music_volume(word, word_eol, userdata):
    if check_mpd() == 0:
        return xchat.EAT_XCHAT
    os.system("mpc volume " + word[1])
    return xchat.EAT_ALL

def mpccommand(word, word_eol, userdata):
    if check_mpd() == 0:
        return xchat.EAT_XCHAT
    os.system("mpc " + word_eol[1])
    return xchat.EAT_XCHAT

def unload(userdata):
    print "Hai appena unloadato mpd_title, addio :)"
    return xchat.EAT_XCHAT

xchat.hook_command("MUSIC", display_title)
xchat.hook_command("NEXT", music_next)
xchat.hook_command("PREV", music_prev)
xchat.hook_command("PLAY", music_toggle)
xchat.hook_command("PAUSE", music_toggle)
xchat.hook_command("STOP", music_stop)
xchat.hook_command("VOLUME", music_volume)
xchat.hook_command("MPC_COMMAND", mpccommand)

xchat.hook_unload(unload)


Si accettano critiche e suggerimenti :P
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Forum italiano (Italian) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum