#!/usr/bin/python __module_name__ = "SCCwatcher" __module_version__ = "1.0" __module_description__ = "SCCwatcher based on cancelbot" import xchat, os, re, string, urllib print "\0034",__module_name__, __module_version__,"has been loaded\003" #the globals go here option = {} xchatdir = xchat.get_info("xchatdir") color = {"white":"\0030", "black":"\0031", "blue":"\0032", "green":"\0033", "red":"\0034", "dred":"\0035", "purple":"\0036", "dyellow":"\0037", "yellow":"\0038", "bgreen":"\0039", "dgreen":"\00310", "green":"\00311", "blue":"\00312", "bpurple":"\00313", "dgrey":"\00314", "lgrey":"\00315", "close":"\003"} #the functions go here def load_vars(): global option try: inifile = open(os.path.join(xchatdir,"scc.ini")) line = inifile.readline() #The first line is a comment line = inifile.readline() while line != "": par1, par2 = re.split("=", line) option[par1] = string.strip(par2) line = inifile.readline() inifile.close option["sections"] = re.split(' ', option["sections"]) chans = re.split(' ', option["chans"]) option["chans"] = [] for pair in chans: par1, par2 = re.split(':', pair.lower()) option["chans"].append([par1, par2]) print color["dgreen"], "SCCwatcher scc.ini Load Success" except EnvironmentError: print color["red"], "Could not open scc.ini put it in your "+xchatdir+"" def on_text(word, word_eol, userdata): if option["service"] != 'on': return counter = 0 destination = xchat.get_context() network = destination.get_info('network').lower() channel = destination.get_info('channel').lower() triggernick = word[0].lower() #trigger = re.split(' ',word[1].lower()) #da spostar dentro, dopo il controllo del canale? for section in option["sections"]: if re.search(section, word[1], re.I): counter += 1 for chan in option["chans"]: if chan[0] == network and chan[1] == channel: #try: if counter > 0 and triggernick == "scc": tomatch = xchat.strip(word_eol[1]) print color["dgreen"], "going to match: " + tomatch p = re.compile(' NEW in (.*): -> ([^\s]*.) \((.*)\) - \(http:\/\/www.sceneaccess.org\/details.php\?id=(\d+)\)(.*)') matchedtext = p.match(tomatch) print matchedtext downloadurl = "http://www.sceneaccess.org/download2.php/" + matchedtext.group(4) + "/" + option["passkey"] + "/" + matchedtext.group(2) + ".torrent" print color["dgreen"], "will download: " + downloadurl urllib.urlretrieve(downloadurl,option["savepath"] + matchedtext.group(2) + ".torrent") #matchedtext.group(1) = MP3 #matchedtext.group(2) = VA-Stamina_Daddy_Riddim_Aka_Gold_Spoon_Riddim_(Promo_CD)-2006-VYM #matchedtext.group(4) = 37518 #except AttributeError: # print color["red"], "Error saving the file :(" def on_local(word, word_eol, userdata): global option trigger = re.split(' ',word_eol[0].lower()) if trigger[1] == 'add': print color["red"],"Function not created yet" if trigger[1] == 'del' or trigger[1] == 'delete': print color["red"],"Function not created yet" if trigger[1] == 'list' or trigger[1] == 'print' or trigger[1] == 'show': print color["blue"], "Currently watching: " + str(option["chans"]) if trigger[1] == 'off': option["service"] = 'off' print color["red"], "Autodownloading has been turned off" if trigger[1] == 'on': option["service"] = 'on' print color["dgreen"], "Autodownloading has been turned on" return xchat.EAT_ALL def unload_cb(userdata): print "\0034",__module_name__, __module_version__,"has been unloaded\003" xchat.hook_unload(unload_cb) load_vars() #The hooks go here xchat.hook_print('Channel Message', on_text) xchat.hook_command('SCCwatcher', on_local, help="adjust the scc.ini as you wish :P")