# vim: set fileencoding=utf-8 :
# python script to display the song currently played in Amarok,
# just not quite so dry and repetitive, and with a little lemon twist
__module_name__ = "amarok_xchat"
__module_version__ = "1.4"
__module_description__ = "display Amarok's current track, just not quite so dry and repetitive, and with a little lemon twist"
import xchat
import commands
import random
## original amarok_xchat up to 0.2 by sven kissner (aka chimaera)
## below modifications by Scott R. Godin (aka WebDragon from irc.freenode.net, various channels)
### NOTE: A few utf-8 literals are embedded in various strings below: Take care if and when
### editing this script, that your editor supports utf-8 encoding properly.
### {{{ revision history
# 0.3 Added 'now playing' (amnp) event to display the information privately
# 0.4 Added random 'now playing' phrases to prepend to the track names and keep things interesting
# 0.5 Added a 'sig' so the random phrases are more obviously script-generated
# 0.6 Revised building of output phrasing to make future edits to the script easier for 'average joe' style purposes
# 0.7 Revise color/bold/underline processing to make selection simpler to understand for the average joe
# 0.8 add random.shuffle to phrases to additionally randomize the resultant bellcurve from random.choice
# 0.9 slight revisions to command structure to simplify pending phrase output revision
# 1.0 revise phrase output so that track info can be placed anywhere in the phrase instead of only at the end
# 1.1 refactor functions to avoid 'expensive concatenation' at the expense of being slightly more difficult to
# understand for the average user. this slightly undoes what we did in 0.6, but not too badly.
# 1.2 more phrases, now that we have the luxury of more flexibility :-)
# 1.3 added a status check to be sure amarok is at least playing or paused before trying to get track info.
# 1.4 patch for auralmoon and somafm, which have insanely long stream titles because I listen to them a lot.
# adjust to your own tastes for your own favorite streams
# TODO : add positive/negative weighting to strings and add commands for "don't diss this tune" "much love for this tune" so the randomizer
# doesn't spew nasty things about one of your favorite tunes or vice versa
### }}}
### {{{ phrase list
# there's no reason you have to use all the random phrases, mind you.
# You could simply comment out most of them and limit it to the usual boring first three in the list.
# Yeah yeah, I know, some people actually LIKE vanilla. BAH! :D
phrases = [
"say nope, I'm not telling you the song. nyah :P",
"me notes that this tagline has been censored on account of %s being, well.. listen!",
# "me is currently listening to: %s",
# "me is checking out %s",
# "me is now playing %s",
"me pumps up the volume and spins up some %s",
"me jams along with %s",
"me vainly attempts to listen to %s and write code at the same time",
"me kicks back as the random DJ spins up a bottle of %s",
"me falls asleep in his chair and snores his way through a heartwarming rendition of %s",
"me pulls a CD from the stacks at random and listens to %s",
"me blows the dust off a copy of %s",
"me wakes up and starts pounding the alarmclock, which is blaring out %s",
"say ... and then Amarok pulled this out of the magic hat: %s",
"me cleans the wax out of his ears so he can hear the faint strains of %s",
"me rummages in the stacks and comes up with %s",
"me cranks up the volume on %s until ears bleed in neighboring countries @_@;;",
"say ahhhhhhhhhh here we go... %s",
"me dredges the bowels of the cutouts bin and comes up with %s",
"me ♥ %s", "me <3 %s",
"me scratches his head, wondering where amarok found %s",
"me riffles the discs and comes up with %s",
# "say moving right along ... %s",
"me slips the DJ a fin and requests %s",
"me tips the bartender extra as he pours out a jigger of %s",
"me digs around a little til %s jumps out at me ...",
"me wonders why %s seems sooo loud... oh, right. hangover. =:P",
"say Ah, now this... %s ... this is some soul-candy here.",
"me orders up an extra-dry %s, shaken, not stirred",
"me rolls the knucklebones and comes up %s",
# "say I never saw a purple cow, but I've herd of %s ... :)",
"say and now, fudging the bell-curve completely, we have %s",
# "say I thought it was Ragnarok and Armageddon and the Apocalypse, but then I realized %s was turned up too loud",
"say They played it long | they played it loud | one thing's for sure | they're not too proud | to play %s | ~Burma Shave~",
"me turns up %s a little louder to add counterpoint to the neighbors humping next door... =8)",
"say Hey, at least these taglines aren't as boring as %s, right? (:",
"say Woah, what the hell is this? %s ? daaammnn.. ",
"say AH! I see you have the machine that goes: %s !",
"me plunges his fist into the heart of %s and screams 'YOUR SOUL IS MINE!' .. and then looks around ... uh.. hi? (damn mortal kombat flashbacks..)",
"me sits through %s, which is fortunately somewhat less boring than '99 bottles'",
"say shipwrecked on an island with nothing but coconuts, fish, and %s ... it could be worse ... ",
# "say %s ? Who thinks of these things?? O_o",
]
# fudge the phraselist bell curve a little before we start pulling random phrases from the list later
random.shuffle(phrases)
### }}}
### {{{ color processing
norm = '' # CTRL-O literal
color = '' # CTRL-C "
ul = '' # CTRL-_ "
bd = '' # CTRL-B "
c = {
'blue': 02,
'green': 03,
'red': 04,
'yellow': 05,
'purple': 06,
'orange': 07,
'ltgrey': 14,
'dkgrey': 15,
}
def col(code):
return "%s%02.f" % (color, c[code])
### }}}
### {{{ results processing subroutines
def artist():
##return col('green') + commands.getoutput("dcop amarok player artist") + norm
return "%s%s%s" % ( col('green'), commands.getoutput("dcop amarok player artist"), norm )
def album():
##return ul + col('green') + commands.getoutput("dcop amarok player album") + norm
return "%s%s%s%s" % ( ul, col('green'), commands.getoutput("dcop amarok player album"), norm )
def title():
##return "“" + bd + col('green') + commands.getoutput("dcop amarok player title") + norm + "”"
return "“%s%s%s%s”" % ( bd, col('green'), commands.getoutput("dcop amarok player title"), norm )
def sig():
##return " " + col('dkgrey') + "«" + __module_name__ + " - " + __module_version__ + "» " + norm
return " %s«%s - %s»%s" % ( col('dkgrey'), __module_name__, __module_version__, norm )
#return " "
def alternate(site):
t = commands.getoutput("dcop amarok player title")
ar = "%s%s%s" % ( col('green'), t.split(' - ', 1)[0], norm )
ti = "“%s%s%s%s”" % ( bd, col('green'), t.split(' - ', 1)[1] , norm )
loc = "%s%s%s%s" % ( ul, col('blue'), site, norm )
return "%s by %s streaming from %s" % (ti, ar, loc)
def whatsplaying():
alb = album();
# EXAMPLE shorten these streaming titles to be manageable and point to their origin
# simply splitting title on '-' isn't enough of a test.
if alb.find("Aural Moon: Progressive Rock Garden") > 0 :
return alternate('www.auralmoon.com')
if alb.find("Groove Salad: a nicely chilled plate of ambient") > 0 :
return alternate('Groove Salad: www.somafm.com')
if alb.find("Secret Agent: The soundtrack for your stylish, mysterious") > 0 :
return alternate('Secret Agent: www.somafm.com')
else:
#return title() + 'by' + artist() + 'from' + album()
return "%s by %s from %s" % ( title(), artist(), album() )
# Tap, tap<SQUEEEEEEEEEEEE>... Is this thing on?
def amarok_isplaying():
# result is a *string*. remember that.
amtest = commands.getoutput("dcop amarok player status")
if amtest == 'call failed':
return False
elif amtest == '0':
return False
else:
return True
### }}}
### {{{ results front end to xchat
# announce the current track publically along with the random tagline for doing so
def amarok_send(word, word_eol, userdata):
if amarok_isplaying():
try:
xchat.command( random.choice(phrases) % whatsplaying() + sig() )
except Exception, e:
xchat.prnt( "There was an error ... %s" % e )
return False
else:
xchat.prnt("Error: Amarok is either stopped or is not currently loaded.")
return xchat.EAT_ALL
# let the user know the tune without announcing it publically
def amarok_nowplaying(word, word_eol, userdata):
if amarok_isplaying():
try:
xchat.prnt( random.choice(phrases) % whatsplaying() + sig() )
except Exception, e:
xchat.prnt( "There was an error ... %s" % e )
return False
else:
xchat.prnt("Error: Amarok is either stopped or is not currently loaded.")
return xchat.EAT_ALL
### }}}
xchat.hook_command('am', amarok_send)
xchat.hook_command('amnp', amarok_nowplaying)
xchat.prnt(__module_name__ + ' v' + __module_version__ + ' loaded..')
# vim700: set nospell :
# vim600: set foldenable foldmethod=marker foldmarker={{{,}}} :