rendered paste body#! /usr/bin/env python
__module_name__ = "amaroK NP"
__module_version__ = "0.0pie"
__module_description__ = "Display a Now Playing with stats for amaroK"
import xchat
from os import popen
from random import randint
import string
from urllib import unquote
def show_song(word, word_eol, userdata):
info_name = 9
first_bracket = 5
second_bracket = 12
song_info = 8
songdata = ''
arun = 0
def zeroadd(info):
if len(str(info)) < 2:
return '0'+str(info)
else:
return ''+str(info)
c = [zeroadd(info_name), zeroadd(first_bracket), zeroadd(second_bracket), zeroadd(song_info)]
def getinfod(info):
return popen("dcop amarok default "+info,"r").read().strip()
for line in popen("dcop 2> /dev/null","r").readlines():
if 'amarok' in line:
arun = 1
if int(getinfod('status')) == 2:
arun = 2
def getVolume():
if (getinfod('getVolume') == "100"):
return "110"
else:
return getinfod('getVolume')
def randn():
return zeroadd(randint(0, 15))
def getRating():
score = int(getinfod('score'))
if (int(getinfod('trackPlayCounter')) == 0):
return "Not Applicable"
if (score <= 20):
return "Abominable"
elif (score > 20 and score <= 40):
return "Bad"
elif (score > 40 and score <= 60):
return "Average"
elif (score > 60 and score <= 80):
return "Good"
elif (score > 80):
return "Excellent"
def getQuality():
sample = str(int(getinfod('sampleRate'))/1000)
bitrate = getinfod('bitrate').strip(string.letters + ' ')
return bitrate + '/' + sample
def getPlayCounter():
if (int(getinfod('trackPlayCounter')) == 0):
return "Never before"
elif (int(getinfod('trackPlayCounter')) == 1):
return "Once before"
else:
return getinfod('trackPlayCounter') + " times before"
if arun > 0:
if len(word) > 1:
if word[1] == 'rand':
c = [randn(), randn(), randn(), randn()]
elif word[1] == 'vol':
getinfod('setVolume '+word[2])
print 'Amarok\'s volume set to ' + word[2] + '%'
arun = -1
elif word[1] == 'stop':
getinfod('stop')
arun = -1
elif word[1] == 'play':
getinfod('play')
arun = -1
elif word[1] == 'prev':
getinfod('prev')
arun = -1
elif word[1] == 'next':
getinfod('next')
arun = -1
elif word[1] == 'min':
isplaying = 'me ' + c[0] + 'is playing:' + c[1] + '[' + c[2] + '[' + c[3] + '"' + getinfod('title') + '"' + c[2] +' by ' + c[3] + '"' + getinfod('artist') + '"' + c[2] + ']' + c[1] + ']'
arun = -45
elif word[1] == 'send':
file = unquote(getinfod('encodedURL')).replace('file:', '')
songdata = 'dcc send ' + word[2] + ' "' + file + '"'
arun = -1
else:
print """
Valid commands are:
/pieplayer rand Display amarok's currently playing song using random colors
/pieplayer stop Stop amarok
/pieplayer play Resume amarok
/pieplayer prev Play previous song in amarok playlist
/pieplayer next Play next song in amarok playlist
/pieplayer vol <0-100> Set audio volume in amarok
/pieplayer send <nick> Send current playing song to nick
/pieplayer Display amarok's currently playing song
"""
arun = -1
if arun > 1:
isplaying = 'me ' + c[0] + 'is playing:' + c[1] + '[' + c[2] + '[' + c[3] + '"' + getinfod('title') + '"' + c[2] +' by ' + c[3] + '"' + getinfod('artist') + '"' + c[2] + ']' + c[1] + ']'
quality = c[0] + 'Quality:' + c[1] + '[' + c[2] + '[' + c[3] + getQuality() + c[2] + ']' + c[1] + ']'
position = c[0] + 'Position:' + c[1] + '[' + c[2] + '[' + c[3] + getinfod('currentTime')+' of '+getinfod('totalTime') + c[2] + ']' + c[1] + ']'
volume = c[0] + 'Volume:' + c[1] + '[' + c[2] + '[' + c[3] + getVolume() + '%' + c[2] + ']' + c[1] + ']'
played = c[0] + 'Played:' + c[1] + '[' + c[2] + '[' + c[3] + getPlayCounter() + c[2] + ']' + c[1] + ']'
score = c[0] + 'Rating:' + c[1] + '[' + c[2] + '[' + c[3] + getRating() + c[2] + ']' + c[1] + ']'
songdata = isplaying + ' ' + quality + ' ' + position + ' ' + volume + ' ' + played + ' ' + score + ' ' + c[0] + ' ~Dr. Keo`s PiePlayer for amaroK~ '
if arun < -4:
isplaying = 'me ' + c[0] + 'is playing:' + c[1] + '[' + c[2] + '[' + c[3] + '"' + getinfod('title') + '"' + c[2] +' by ' + c[3] + '"' + getinfod('artist') + '"' + c[2] + ']' + c[1] + ']'
else:
if arun == 1:
print "amaroK Ain't , Newb."
elif arun == 0:
print 'Load amaroK, or check to see that dcop is running.'
xchat.command(songdata)
return xchat.EAT_ALL
xchat.hook_command("pieplayer", show_song)
print 'Show amaroK song (pieplayer) loaded, type "/pieplayer help" for a command list'