Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-*- coding: utf-8 -*-
- __module_name__ = "media spammer"
- __module_version__ = "9005"
- __module_description__ = "media spammer"
- import urllib2
- from urllib2 import Request, urlopen, URLError, HTTPError
- import socket
- import os.path
- import math
- import xchat
- from HTMLParser import HTMLParser
- mpc_host = 'localhost'
- mpc_port = '13579'
- foo_host = '127.0.0.1'
- foo_port = '3333'
- #Must have web interface enabled and have a mpc-hc revision greater then 3110
- #and you must update the host and port name if you change them from the default values
- args = dict()
- class MyHTMLParser(HTMLParser):
- def __init__(self):
- HTMLParser.__init__(self)
- self.curtag = ("", None)
- def handle_starttag(self, tag, attrs):
- self.curtag = (tag, attrs)
- def handle_endtag(self, tag):
- self.curtag = ("", None)
- def handle_data(self, data):
- if self.curtag[0] == "p":
- if self.curtag[1][0][0] == "id":
- args[self.curtag[1][0][1]] = data
- def mpcSpam(word, word_eol, userdata):
- req = urllib2.Request('http://'+mpc_host+':'+mpc_port+'/variables.html')
- try: response = urllib2.urlopen(req,timeout=2)
- except URLError, e:
- xchat.prnt('Server did not respond, maybe mpc-hc isn\'t running: '+str(e.reason))
- return xchat.EAT_ALL
- parser = MyHTMLParser()
- parser.feed(response.read())
- filename = args["filepath"]
- size = os.path.getsize(filename.decode('utf-8'))
- size = int(math.floor(size/1048576))
- filename = os.path.basename(filename)
- state = args["statestring"]
- current_time = args["positionstring"]
- total_time = args["durationstring"]
- position = float(args["position"])
- duration = float(args["duration"])
- loops = math.floor(((position/duration)*20))
- progress = "10"
- for i in range(20):
- if loops < i:
- progress = progress + "4"
- loops = 21
- progress = progress + '|'
- #variables: size, filename, state, current_time, total_time
- xchat.command("ME 11※ 00MPC-HC 10 " + filename + "00 " + current_time + "/" + total_time + "03 "+str(size)+"MB 11※")
- return xchat.EAT_ALL
- #Must have foo_controlserver and foo_controlserver output options set to
- #'%codec%|||%playback_time%|||%length%|||%bitrate%|||%samplerate%|||%artist%|||%album%|||%album artist%|||%date%|||%genre%|||%tracknumber%|||%title%|||%playback_time_seconds%|||%length_seconds%'
- #also change the "Base Delimiter from "|" to "|||"
- #or this will not work!
- #also, as pointed out by weeaboo faggot herkz, if you wanna spam jap shit you gotta enable utf8 output
- #foo_controlserver can be downloaded from this url: http://www.hydrogenaudio.org/forums/index.php?s=425185f6437f61b939f004da0c9eee91&act=attach&type=post&id=2744
- #and be sure and update the ports/hostnames if you change them from the defaults
- def fooSpam(word, word_eol, userdata):
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- try: sock.connect((foo_host,int(foo_port)))
- except socket.error, e:
- xchat.prnt('An error occured, foobar probably isn\'t running or you didn\'t install foo_controlserver: '+str(e))
- return xchat.EAT_ALL
- buf = sock.recv(1024)
- pos = buf.find('Connected to foobar2000 Control Server')
- if pos < 0:
- xchat.prnt('An error occured idk why m8')
- sock.close()
- return xchat.EAT_ALL
- else:
- buf = sock.recv(1024)
- sock.close()
- buf = buf.split('|||')
- state = {
- '111': lambda : 'Playing',
- '112': lambda : 'Stopped',
- '113': lambda : 'Paused'
- }[buf[0]]()
- codec = buf[4]
- current_time = buf[5]
- total_time = buf[6]
- bitrate = buf[7]
- samplerate = buf[8]
- album_artist = buf[11]
- album = buf[10]
- title = buf[15]
- artist = buf[9]
- track = buf[14]
- try:
- duration = float(buf[16])
- loops = math.floor(((position/duration)*20))
- derps = 0
- progress = '10'
- while derps < 20:
- if loops < derps:
- progress = progress+'4'
- loops = 21
- progress = progress+'|'
- derps = derps+1
- except:
- duration = "∞"
- progress = "12||||||||||||||||||||"
- #variables: codec, current_time, total_time, bit rate, sample rate, artist, album, album artist, year, genre, track, title
- if album_artist == artist:
- xchat.command("ME 11♪♪ 0fb2k10 " + artist + " ["+album+"] "+track+". "+title+"0 " + current_time + "/" + total_time + " 03"+bitrate+"kbps/"+codec+"/"+samplerate+"Hz11 ♪♪")
- else:
- xchat.command("ME 11♪♪ 0fb2k10 " + album_artist + " ["+album+"] "+track+". "+title+" – " +artist+ "0 " + current_time + "/" + total_time + " 03"+bitrate+"kbps/"+codec+"/"+samplerate+"Hz11 ♪♪")
- return xchat.EAT_ALL
- def fooControl(word, word_eol, userdata):
- if len(word) < 2:
- xchat.prnt('You didn\'t issue a command!')
- return xchat.EAT_ALL
- else:
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- try: sock.connect((foo_host,int(foo_port)))
- except socket.error, e:
- xchat.prnt('An error occured, foobar probably isn\'t running or you didn\'t install foo_controlserver: '+str(e))
- return xchat.EAT_ALL
- buf = sock.recv(1024)
- pos = buf.find('Connected to foobar2000 Control Server')
- if pos < 0:
- xchat.prnt('An error occured idk why m8')
- sock.close()
- return xchat.EAT_ALL
- else:
- buf = sock.recv(1024)
- if word[1] in ('play','stop','pause','prev','next'):
- sock.send(word[1]+"\n")
- sock.close()
- return xchat.EAT_ALL
- else:
- xchat.prnt('This isn\'t a valid command!')
- sock.close()
- return xchat.EAT_ALL
- xchat.hook_command('aud', fooSpam)
- xchat.hook_command('vid', mpcSpam)
- xchat.hook_command('fooplay', fooControl)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement