Author Pawel Pogorzelski pawelpogorzelski AT gmail DOT com What it doe

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#Author: Pawel Pogorzelski <pawelpogorzelski AT gmail DOT com>
#What it does: This script shows the currently played song in sonata
#Usage: /weesonata - Displays the songname
#Released under GNU GPL v2 or newer
#/usr/bin/python
#coding: utf-8
import weechat
import re
import codecs
from os import popen
weechat.register ('weesonata', '0.01', '', """sonata-weechat current song script (usage: /weesonata)""")
weechat.add_command_handler ('weesonata', 'show_it_to_them')
default = {
"msg_head": "is playing",
"msg_tail": "with sonata",
"spacer": "*",
}
for k, v in default.items():
if not weechat.get_plugin_config(k):
weechat.set_plugin_config(k, v)
def show_it_to_them(server, args):
spacer = weechat.get_plugin_config("spacer")
msg_tail = weechat.get_plugin_config("msg_tail")
msg_head = weechat.get_plugin_config("msg_head")
sonata_info = popen ('sonata info')
if sonata_info.readline().rstrip().find('MPD')==-1:
sonata_info = popen ('sonata info')
song_name_text = sonata_info.readline().rstrip().split(': ')
song_artist_text = sonata_info.readline().rstrip().split(': ')
album_text = sonata_info.readline().rstrip().split(': ')
date_text = sonata_info.readline().rstrip().split(': ')
track_text = sonata_info.readline().rstrip().split(': ')
type_text = sonata_info.readline().rstrip().split(': ')
file_text = sonata_info.readline().rstrip().split(': ')
time_text = sonata_info.readline().rstrip().split(': ')
bitrate_text = sonata_info.readline().rstrip().split(': ')
all = '/me ' + " " + msg_head + " " + song_name_text[1] + " " + spacer + " " + song_artist_text[1] + " " + spacer + " " + time_text[1] + " " + spacer + " " + bitrate_text[1] + "kbit/s " + spacer + " "+ msg_tail
else :
all = '/me listens to silence :)'
weechat.command(all)
return 0