Skip to content

Instantly share code, notes, and snippets.

@sputnikus
Forked from sonicrules1234/nowplaying.py
Last active December 30, 2015 20:08
Show Gist options
  • Save sputnikus/7878323 to your computer and use it in GitHub Desktop.
Save sputnikus/7878323 to your computer and use it in GitHub Desktop.
import xchat, re, requests
from requests.auth import HTTPBasicAuth
__module_name__ = "vlcnowplaying"
__module_version__ = "1.1"
__module_description__ = "sputnikus' Now playing script for vlc"
metare = re.compile("""<meta\-information\>
\<title\>\<\!\[CDATA\[(.*)\]\]\>\<\/title\>
\<artist\>\<\!\[CDATA\[(.*)\]\]\>\<\/artist\>
\<genre\>\<\!\[CDATA\[(.*)\]\]\>\<\/genre\>
\<copyright\>\<\!\[CDATA\[(.*)\]\]\>\<\/copyright\>
\<album\>\<\!\[CDATA\[(.*)\]\]\>\<\/album\>
\<track\>\<\!\[CDATA\[(\d*)\]\]\>\<\/track\>
\<description\><\!\[CDATA\[(.*)\]\]\>\<\/description\>
\<rating\>\<\!\[CDATA\[(.*)\]\]\>\<\/rating\>
\<date\>\<\!\[CDATA\[(.*)\]\]\>\<\/date\>
\<url\>\<\!\[CDATA\[(.*)\]\]\>\<\/url\>
\<language\>\<\!\[CDATA\[(.*)\]\]\>\<\/language\>
\<now\_playing\>\<\!\[CDATA\[(.*)\]\]\>\<\/now\_playing\>
\<publisher\>\<\!\[CDATA\[(.*)\]\]\>\<\/publisher\>
\<encoded\_by\>\<\!\[CDATA\[(.*)\]\]\>\<\/encoded\_by\>
\<art\_url\>\<\!\[CDATA\[(.*)\]\]\>\<\/art\_url\>
\<track\_id\>\<\!\[CDATA\[(.*)\]\]\>\<\/track\_id\>
\<\/meta\-information\>""")
def on_NowPlaying(word, word_eol, userdata) :
response = request.get("http://127.0.0.1:8080/requests/status.xml", auth=HTTPBasicAuth('', '<your http password>'))
xml = x.text()
regex = userdata["regex"]
groups = regex.search(xml).groups()
data = dict(title=groups[0], artist=groups[1], genre=groups[2],\
cpyright=groups[3], album=groups[4], track=groups[5],\
description=groups[6], rating=groups[7], date=groups[8],\
url=groups[9], language=groups[10], now_playing=groups[11],\
publisher=groups[12], encoded_by=groups[13], art_url=groups[14],\
track_id=groups[15])
xchat.command("me is now playing \x02%(title)s from the album %(album)s by %(artist)s.\x02" % dict(channel=userdata["context"], title=data["title"], album=data["album"], artist=data["artist"]))
return xchat.EAT_ALL
xchat.hook_command("NP", on_NowPlaying, userdata={"regex":metare, "context":xchat.get_info("channel")})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment