This repository was archived by the owner on May 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmpc.hc.np.py
More file actions
51 lines (39 loc) · 1.42 KB
/
mpc.hc.np.py
File metadata and controls
51 lines (39 loc) · 1.42 KB
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
# -*- coding: utf-8 -*-
#/**
#* mpc.hc.np.py, snippet to display now-playing info for MPC-HC
#* Released under the terms of MIT license
#*
#* https://github.com/mpc-hc/snippets
#*
#* Copyright (C) 2013, 2015 MPC-HC Team
#*/
__module_name__ = "MPC-HC NP snippet"
__module_version__ = "0.2"
__module_description__ = "Displays MPC-HC Player Info!"
import xchat
import urllib2
import re
###############################################################################
# Setup
MPC_HC_PORT = "13579" # Default port
MPC_HC_PAGE = "info.html" # Page where "now playing" info is displayed
###############################################################################
MPC_HC_URL = "http://{0}:{1}/{2}".format("localhost", MPC_HC_PORT, MPC_HC_PAGE)
MPC_HC_REGEXP = re.compile(r"\<p\ id\=\"mpchc_np\"\>(.*)\<\/p\>")
def mpc_hc(caller, callee, helper):
try:
data = urllib2.urlopen(MPC_HC_URL).read()
mpc_hc_np = MPC_HC_REGEXP.findall(data)[0].replace("«", "«")
mpc_hc_np = mpc_hc_np.replace("»", "»")
mpc_hc_np = mpc_hc_np.replace("•", "•")
except:
xchat.prnt("Error: MPC-HC not detected")
return xchat.EAT_ALL
else:
xchat.command("say %s" % mpc_hc_np)
return xchat.EAT_ALL
xchat.hook_command(
"np",
mpc_hc,
help="Use: /np :: Setup: Options -> Player -> Web Interface -> Listen on port"
)