All pastes #55695 Raw Edit

Untitled

public text v1 · immutable
#55695 ·published 2006-05-14 06:11 UTC
rendered paste body
#
# pyql - show what's currently playing in Quod Libet
#
# Quod Libet needs to be running of course! 
#
# This is a lame python version of QLCtrl http://ruined.us/projects/qlctrl/
# Unlike QLCtrl this script does not do any error checking whatsoever (yet)
#
# (c) Lasse Pommerenke, housetier@gmail.com
# written with pida: http://pida.berlios.de/index.php/Main_Page
#
# History:
# 0.1 initial release, seems to work on my pc
# 0.2 less user editing required, thanks to piman in #quodlibet on oftc
# 0.2.1 FOR TOHELLWITHGA :O
#

import os
current_file_name = os.path.expanduser('~/.quodlibet/current')

# except for programming mistakes you shouldn't need to edit anything below this
# line
import xchat
import re

__module_name__ = "pyql"
__module_version__ = "0.2.1"
__module_description__ = "shows what's playing in quod libet"

def np_handler(foo1, foo2, foo3):
    f = open(current_file_name)
    data = f.read()
    f.close()

    list1 = data.split("\n")
    list2 = [foo for foo in list1 if re.search("^(artist|title|album|~#bitrate|~format)=.*", foo)]
    
    dict = {}
    for foo in list2:
        k, v = foo.split("=")
        dict[k] = v
    
    if int(dict['~#bitrate'])==0: bitrate='FLAC' # flac_in_hell would be proud
    elif int(dict['~#bitrate'][0:3])<=128: bitrate='last.fm' # they really need higher quality on lastfm    
    elif int(dict['~#bitrate'][0:3]) > 128 and int(dict['~#bitrate'][0:-3]) <= 320: bitrate='mp3,'+dict['~#bitrate'][0:-3]+'k'
    else: bitrate='CD' # quod libet doesn't even play CDs, hehe
    
    xchat.command("say Now Playing: %s - %s [%s] [%s]" % (dict["artist"],dict["title"],dict["album"],bitrate))
    return xchat.EAT_ALL

xchat.hook_command("ql", np_handler, help="its too simple for help!")