Plugins: pyql.py

File pyql.py, 1.7 kB (added by sherl0k@gmail.com, 1 year ago)

X-Chat2 plugin for announcing what song you're playing. Still in development.

Line 
1 #
2 # pyql - show what's currently playing in Quod Libet
3 #
4 # Quod Libet needs to be running of course!
5 #
6 # This is a lame python version of QLCtrl http://ruined.us/projects/qlctrl/
7 # Unlike QLCtrl this script does not do any error checking whatsoever (yet)
8 #
9 # (c) Lasse Pommerenke, housetier@gmail.com
10 # written with pida: http://pida.berlios.de/index.php/Main_Page
11 #
12 # modified by Chris Balcum (sherl0k), sherl0k@gmail.com
13 # http://shiningpolaris.com
14 #
15 # thanks to Jooon for bugfixing the bitrate + time properties
16 # if one field is missing, it'll give an error. someone feel free to fix that.
17 #
18 # History:
19 # 0.1 initial release, seems to work on my pc
20 # 0.2 less user editing required, thanks to piman in #quodlibet on oftc
21 # 0.3 added in song length, album, and bitrate properties (sherl0k)
22
23
24 import os
25 current_file_name = os.path.expanduser('~/.quodlibet/current')
26
27 # except for programming mistakes you shouldn't need to edit anything below this
28 # line
29 import xchat
30 import re
31
32 __module_name__ = "pyql"
33 __module_version__ = "0.3"
34 __module_description__ = "shows what's playing in quod libet"
35
36 def np_handler(foo1, foo2, foo3):
37     f = open(current_file_name)
38     data = f.read()
39     f.close()
40
41     list1 = data.split("\n")
42     list2 = [foo for foo in list1 if re.search("^(artist|~#bitrate|title|album|~#length)=.*", foo)]
43    
44     dict = {}
45     for foo in list2:
46         k, v = foo.split("=")
47         dict[k] = v
48     xchat.command("say np: %s - %s (%s) [%skbps, %sm%ss]" % (dict["artist"], dict["title"], dict["album"], int(dict["~#bitrate"])/1000 , int(dict["~#length"])/60, int(dict["~#length"])%60))
49     return xchat.EAT_ALL
50
51 xchat.hook_command("np", np_handler, help="its too simple for help!")
52