Skip to content

Instantly share code, notes, and snippets.

@berrythesoftwarecodeprogrammar
Created April 12, 2016 10:41
Show Gist options
  • Save berrythesoftwarecodeprogrammar/b02ca24bc7834519c40e51ecc9b39131 to your computer and use it in GitHub Desktop.
Save berrythesoftwarecodeprogrammar/b02ca24bc7834519c40e51ecc9b39131 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__module_name__ = "mpc.py"
__module_author__ = "brr [berr.yt]"
__module_version__ = "20160412"
__module_description__ = "now playing for media player classic"
#--------------------------------------------------------------#
infourl = "http://localhost:13579/info.html"
# Available variables for format: $media $ext $version $elapsed $length $size
format = '$ext; $media'
command = 'say'
#--------------------------------------------------------------#
import hexchat
from urllib2 import urlopen
from re import search, split as resplit, sub
def mpc(word, word_eol, userdata):
try:
info = urlopen(infourl).read()
except:
print '[!] Error retrieving MPC info. Is MPC even running bitch?'
return hexchat.EAT_ALL
info = search('<p id="mpchc_np">(.*)<\/p>',info)
if info is None:
print '[!] Error retrieving MPC info. Either the page format changed or this code SUCKS!'
return hexchat.EAT_ALL
else:
info = [x.strip() for x in resplit('&[^; ]+;',info.group(1)) if x != '']
version = info[0]
media = info[1]
media = media.rsplit('.',1)
ext = media[1]
media = media[0]
elapsed = info[2].split('/')[0]
length = info[2].split('/')[1]
size = info[3]
if length[:2] == '00':
length = length[3:]
elapsed = elapsed[3:]
msg = format
msg = sub('\$ext',ext,msg)
msg = sub('\$media',media,msg)
msg = sub('\$version',version,msg)
msg = sub('\$elapsed',elapsed,msg)
msg = sub('\$length',length,msg)
msg = sub('\$size',size,msg)
hexchat.command(command+' '+msg)
return hexchat.EAT_ALL
hexchat.hook_command('mpc', mpc, help="Usage: /mpc\n--> Says what you're watching in MPC")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment