#! /usr/bin/env python __module_name__ = "amarok display" __module_version__ = "1.0" __module_description__ = "amarok display" import xchat from os import popen from random import randint import string from urllib import unquote def show_song(word, word_eol, userdata): ########################## CONFIGURATION ###################### # #Written by Moobert and Eno_ # ##You can your own xchat colours in the song display by editing the below: # # info_name = 9 first_bracket = 5 second_bracket = 7 song_info = 8 # #then type; #/disork # to show the song information. #/disrok help # to get a list of other commands. # #problems/ideas: # Drop one of us a line on server irc.odinnet.ca, in #oldskool # ############################################################## 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] == 'send': file = unquote(getinfod('encodedURL')).replace('file:', '') songdata = 'dcc send ' + word[2] + ' "' + file + '"' arun = -1 else: print """ Valid commands are: /disrok rand Display amarok's currently playing song using random colors /disrok stop Stop amarok /disrok play Resume amarok /disrok prev Play previous song in amarok playlist /disrok next Play next song in amarok playlist /disrok vol <0-100> Set audio volume in amarok /disrok send Send current playing song to nick /disrok 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] + ' from the album ' + c[3] + '"' + getinfod('album') + '"' + 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 else: if arun == 1: print "amarok doesn't seem to be playing..." elif arun == 0: print 'load amarok, or check that dcop is running.' xchat.command(songdata) return xchat.EAT_ALL xchat.hook_command("disrok", show_song) print 'Display amarok loaded, type "/disrok help" for a command list'