Advertisement
Velvetine

Mediaspam

Oct 11th, 2015
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.42 KB | None | 0 0
  1. #-*- coding: utf-8 -*-
  2. __module_name__ = "media spammer"
  3. __module_version__ = "9005"
  4. __module_description__ = "media spammer"
  5. import urllib2
  6. from urllib2 import Request, urlopen, URLError, HTTPError
  7. import socket
  8. import os.path
  9. import math
  10. import xchat
  11. from HTMLParser import HTMLParser
  12.  
  13. mpc_host = 'localhost'
  14. mpc_port = '13579'
  15.  
  16. foo_host = '127.0.0.1'
  17. foo_port = '3333'
  18.  
  19. #Must have web interface enabled and have a mpc-hc revision greater then 3110
  20. #and you must update the host and port name if you change them from the default values
  21. args = dict()
  22.  
  23. class MyHTMLParser(HTMLParser):
  24.     def __init__(self):
  25.         HTMLParser.__init__(self)
  26.         self.curtag = ("", None)
  27.     def handle_starttag(self, tag, attrs):
  28.         self.curtag = (tag, attrs)
  29.     def handle_endtag(self, tag):
  30.         self.curtag = ("", None)
  31.     def handle_data(self, data):
  32.         if self.curtag[0] == "p":
  33.             if self.curtag[1][0][0] == "id":
  34.                 args[self.curtag[1][0][1]] = data
  35.  
  36. def mpcSpam(word, word_eol, userdata):
  37.     req = urllib2.Request('http://'+mpc_host+':'+mpc_port+'/variables.html')
  38.    
  39.     try: response = urllib2.urlopen(req,timeout=2)
  40.     except URLError, e:
  41.         xchat.prnt('Server did not respond, maybe mpc-hc isn\'t running: '+str(e.reason))
  42.         return xchat.EAT_ALL
  43.  
  44.     parser = MyHTMLParser()
  45.     parser.feed(response.read())
  46.  
  47.     filename = args["filepath"]
  48.     size = os.path.getsize(filename.decode('utf-8'))
  49.     size = int(math.floor(size/1048576))
  50.     filename = os.path.basename(filename)
  51.     state = args["statestring"]
  52.     current_time = args["positionstring"]
  53.     total_time = args["durationstring"]
  54.     position = float(args["position"])
  55.     duration = float(args["duration"])
  56.     loops = math.floor(((position/duration)*20))
  57.     progress = "10"
  58.     for i in range(20):
  59.         if loops < i:
  60.             progress = progress + "4"
  61.             loops = 21
  62.         progress = progress + '|'
  63.     #variables: size, filename, state, current_time, total_time
  64.     xchat.command("ME 11※ 00MPC-HC 10 " + filename + "00 " + current_time + "/" + total_time + "03 "+str(size)+"MB 11※")
  65.     return xchat.EAT_ALL
  66.    
  67. #Must have foo_controlserver and foo_controlserver output options set to
  68. #'%codec%|||%playback_time%|||%length%|||%bitrate%|||%samplerate%|||%artist%|||%album%|||%album artist%|||%date%|||%genre%|||%tracknumber%|||%title%|||%playback_time_seconds%|||%length_seconds%'
  69. #also change the "Base Delimiter from "|" to "|||"
  70. #or this will not work!
  71. #also, as pointed out by weeaboo faggot herkz, if you wanna spam jap shit you gotta enable utf8 output
  72. #foo_controlserver can be downloaded from this url: http://www.hydrogenaudio.org/forums/index.php?s=425185f6437f61b939f004da0c9eee91&act=attach&type=post&id=2744
  73. #and be sure and update the ports/hostnames if you change them from the defaults
  74. def fooSpam(word, word_eol, userdata):
  75.     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  76.    
  77.     try: sock.connect((foo_host,int(foo_port)))
  78.     except socket.error, e:
  79.         xchat.prnt('An error occured, foobar probably isn\'t running or you didn\'t install foo_controlserver: '+str(e))
  80.         return xchat.EAT_ALL
  81.        
  82.     buf = sock.recv(1024)
  83.     pos = buf.find('Connected to foobar2000 Control Server')
  84.     if pos < 0:
  85.         xchat.prnt('An error occured idk why m8')
  86.         sock.close()
  87.         return xchat.EAT_ALL
  88.     else:
  89.         buf = sock.recv(1024)
  90.         sock.close()
  91.        
  92.     buf = buf.split('|||')
  93.     state = {
  94.         '111': lambda : 'Playing',
  95.         '112': lambda : 'Stopped',
  96.         '113': lambda : 'Paused'
  97.     }[buf[0]]()
  98.     codec = buf[4]
  99.     current_time = buf[5]
  100.     total_time = buf[6]
  101.     bitrate = buf[7]
  102.     samplerate = buf[8]
  103.     album_artist = buf[11]
  104.     album = buf[10]
  105.     title = buf[15]
  106.     artist = buf[9]
  107.     track = buf[14]
  108.     try:
  109.         duration = float(buf[16])
  110.         loops = math.floor(((position/duration)*20))
  111.         derps = 0
  112.         progress = '10'
  113.         while derps < 20:
  114.             if loops < derps:
  115.                 progress = progress+'4'
  116.                 loops = 21
  117.             progress = progress+'|'
  118.             derps = derps+1
  119.     except:
  120.         duration = "∞"
  121.         progress = "12||||||||||||||||||||"
  122.     #variables: codec, current_time, total_time, bit rate, sample rate, artist, album, album artist, year, genre, track, title
  123.     if album_artist == artist:
  124.         xchat.command("ME 11♪♪ 0fb2k10 " + artist + " ["+album+"] "+track+". "+title+"0 " + current_time + "/" + total_time + " 03"+bitrate+"kbps/"+codec+"/"+samplerate+"Hz11 ♪♪")
  125.     else:
  126.         xchat.command("ME 11♪♪ 0fb2k10 " + album_artist + " ["+album+"] "+track+". "+title+" – " +artist+ "0 " + current_time + "/" + total_time + " 03"+bitrate+"kbps/"+codec+"/"+samplerate+"Hz11 ♪♪")
  127.     return xchat.EAT_ALL
  128.  
  129. def fooControl(word, word_eol, userdata):
  130.     if len(word) < 2:
  131.         xchat.prnt('You didn\'t issue a command!')
  132.         return xchat.EAT_ALL
  133.     else:
  134.         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  135.    
  136.         try: sock.connect((foo_host,int(foo_port)))
  137.         except socket.error, e:
  138.             xchat.prnt('An error occured, foobar probably isn\'t running or you didn\'t install foo_controlserver: '+str(e))
  139.             return xchat.EAT_ALL
  140.        
  141.         buf = sock.recv(1024)
  142.         pos = buf.find('Connected to foobar2000 Control Server')
  143.         if pos < 0:
  144.             xchat.prnt('An error occured idk why m8')
  145.             sock.close()
  146.             return xchat.EAT_ALL
  147.         else:
  148.             buf = sock.recv(1024)
  149.             if word[1] in ('play','stop','pause','prev','next'):
  150.                 sock.send(word[1]+"\n")
  151.                 sock.close()
  152.                 return xchat.EAT_ALL
  153.             else:
  154.                 xchat.prnt('This isn\'t a valid command!')
  155.                 sock.close()
  156.                 return xchat.EAT_ALL
  157.            
  158. xchat.hook_command('aud', fooSpam)
  159. xchat.hook_command('vid', mpcSpam)
  160. xchat.hook_command('fooplay', fooControl)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement