Script: weempd.py

WARNING: this script has been disabled (not compatible with Python 3).

Display which song mpd is currently playing.
Author: Apprentice — Version: 0.1.1 — License: GPL3
For WeeChat ≥ 0.3.0, requires: mpc.
Tags: music, py2
Added: 2009-06-17 — Updated: 2010-06-22

Download GitHub Repository

 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
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
  Author:
    Pablo Escobar <pablo__escobar AT tlen DOT pl>

  Adapted for Weechat 0.3.0 by:
    Apprentice <apprent1ce AT livejournal DOT com>

  What it does:
    This script shows the currently played song in mpd 

  Usage:
    /weempd - Displays the songname 

  Released under GNU GPL v3 or newer
"""

import weechat as wc
import re
from os.path import basename, splitext
from os import popen

wc.register("weempd", "Apprentice", "0.1.1", "GPL3", "np for mpd", "", "")

def subst(text, values):
  out = ""
  n = 0
  for match in re.finditer(findvar, text):
    if match is None:
      continue 
    else:
      l, r = match.span()
      nam = match.group(1)
      out += text[n:l+1] + values.get(nam, "") #"$" + nam)
      n = r
  return out + text[n:]


def np(data, buffer, args):
  """
   Send information about the currently
   played song to the channel.
  """
  spacer = wc.config_get_plugin("spacer")
  msg_head = wc.config_get_plugin("msg_head")
  tempinfo = popen('mpc').readline().rstrip()
  if tempinfo.find("volume:") == -1:
    all = '/me ' + msg_head + spacer + tempinfo 
    wc.command(wc.current_buffer(), all)
  return 0
  
wc.hook_command("weempd", "now playing", "", np.__doc__, "", "np", "")

default = {
  "msg_head": "np:",
  "spacer": " " ,
}

for k, v in default.items():
  if not wc.config_is_set_plugin(k):
    wc.config_set_plugin(k, v)