Amarok NP 0.1.0

Script para xchat desenvolvido no canal #gnu_xiitas@irc.freenode.net que mostra a música que está tocando no Amarok e também oferece alguns comandos simples para o controle do player.

# coding=utf-8
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
# Authors:
# Thomas Fortes
# Weslly Honorato
# Gabriel "Pnordico" Menezes
# #gnu_xiitas@freenode.org
 
__module_name__ = "Amarok_NP"
__module_version__ = "0.1.0" 
__module_description__ = "Executes dcop to print the Now Playing music info only when it changes and control amarok."
 
import time
import xchat
import threading
import commands
import string
 
class Amarok:
 
   status = 'off'
   prevSong = ''
   amarokHook = None
 
   amarok_msg_help = '''Amarok Np Plugin:
	/np start       Start the plugin loop
	/np finish      Stop the plugin loop
	/np show        Show the current song
	/np next        Go to next song
	/np prev        Go to previous song
	/np play        Play amarok
	/np pause       Pause amarok
	/np stop        Stop amarok'''
 
   # Functions to control amarok
 
   def amarok_next(self, word, word_eol, userdata):
      msg = commands.getoutput('dcop amarok player next')
      return xchat.EAT_ALL
 
   def amarok_prev(self, word, word_eol, userdata):
      msg = commands.getoutput('dcop amarok player prev')
      return xchat.EAT_ALL
 
   def amarok_play_pause(self, word, word_eol, userdata):
      msg = commands.getoutput('dcop amarok player playPause')
      return xchat.EAT_ALL
 
   def amarok_stop(self, word, word_eol, userdata):
      msg = commands.getoutput('dcop amarok player stop')
      return xchat.EAT_ALL
 
 
 
   # Now Playing functions   
 
 
   def amarok_loop(self, userdata):
      xchat.command('amaroknp')
      return 1
 
   def amarok_show_now(self, word, word_eol, userdata):
      if self.status == 'off':
         mystatus = 'off'
      else:
	 mystatus = 'on'
 
      self.prevSong = ''
      self.status = 'on'
      xchat.command('amaroknp')
      self.status = mystatus
 
   def amarok_loop_start(self, word, word_eol, userdata):
      self.status = 'on'
      return 1
 
   def amarok_loop_stop(self, word, word_eol, userdata):
      self.status = 'off'
      self.prevSong = ''
      return 1
 
   def amarok_send(self, word, word_eol, userdata):
 
     artist = commands.getoutput('dcop amarok player artist')
     title = commands.getoutput('dcop amarok player title')
     disc = commands.getoutput('dcop amarok player album')
     year = commands.getoutput('dcop amarok player year')
     genre = commands.getoutput('dcop amarok player genre')
     songtime = commands.getoutput('dcop amarok player totalTime')
 
     if self.prevSong != title:
        # Here we check if status is on and dcop succeeded
	if self.status == 'on' and songtime != 'call failed' and songtime != '?':
	   self.prevSong = title
	   xchat.command('allchan me is listening ' + artist + " - " + title + " ( " + "Album" + ": " +
           disc + " / Year: " + year + " / Genre: " + genre + " / Songtime: " + songtime + ")")
     return xchat.EAT_ALL
 
 
   def amarok_command_callback(self, word, word_eol, userdata):
      try:
	 if word[1].lower() == 'start':
	     return self.amarok_loop_start(word[1], word_eol[1], userdata)
	 if word[1].lower() == 'finish':
 	     return self.amarok_loop_stop(word[1], word_eol[1], userdata)
	 if word[1].lower() == 'next':
	     return self.amarok_next(word[1], word_eol[1], userdata)
	 if word[1].lower() == 'prev':
	     return self.amarok_prev(word[1], word_eol[1], userdata)
	 if word[1].lower() == 'play':
	     return self.amarok_play_pause(word[1], word_eol[1], userdata)
	 if word[1].lower() == 'pause':
	     return self.amarok_play_pause(word[1], word_eol[1], userdata)
	 if word[1].lower() == 'stop':
	     return self.amarok_stop(word[1], word_eol[1], userdata)
	 if word[1].lower() == 'show':
	     return self.amarok_show_now(word[1], word_eol[1], userdata)
 
	 if word[1].lower() == 'help':
	    print self.amarok_msg_help
 
      except IndexError:
	 print self.amarok_msg_help
      return xchat.EAT_ALL
 
   def run(self):
      xchat.hook_command('np', self.amarok_command_callback, help=self.amarok_msg_help)
      xchat.hook_command('amaroknp', self.amarok_send)
 
      amarokHook = xchat.hook_timer(5000, self.amarok_loop)
 
      xchat.prnt('Amarok np, Use /np start to start the loop, /np finish to stop and /np help for more info.')
 
 
class Script:
   Amarok().run()
 
if __name__ == "__main__":
   Script()
  1. Busca

  2. Arquivo

  3. Amiguinhos

  4. Posts recentes

  5. Nuvem de tags

  6. Comentários Recentes

  7. Licença

    Creative Commons License
    Esta obra está licenciada sob uma Licença Creative Commons. Overflow by Weslly Honorato is licensed under a Creative Commons Attribution-ShareAlike 2.5 Brazil License.
  8. Estatísticas

    eXTReMe Tracker
  9. /etc

    Firefox Powered by Wordpress tracker RSS Add to Technorati Favorites
  10. Meta

  11. Capitalismo

    Saiba onde tem o melhor preço antes de comprar