rendered paste bodycolor = {"white":"\00300", "black":"\00301", "lblue":"\00302", "green":"\00303", "red":"\00304","dred":"\00305", "purple":"\00306", "dyellow":"\00307", "yellow":"\00308", "bgreen":"\00309","dgreen":"\00310", "green":"\00311", "lblue":"\00312", "bpurple":"\00313", "dgrey":"\00314","lgrey":"\00315", "closec":"\003", "closea":"\017", "closeb":"\002", "bold":"\002"}results_keeper = {"index":0}def main(): global rls_regx, dmobj rls_regx = re.compile('(.*)NEW in (.*): -> ([^\s]*.) \((.*)\) - \(http:\/\/www.sceneaccess.org\/details.php\?id=(\d+)\)(.*)') #YOU MUST USE DOUBLE BACKSLASHES, NOT SINGLE! OTHERWISE YOU WILL GET ERRORS CONNECTING TO THE DATABASE dmobj = dataman("/home/TRB/rlsdb_databases", "rlsdb_prelim02-linux-test-base_v016.db")def on_text(word, word_eol, userdata): global dmobj, results_keeper sttext = xchat.strip(word[1]) stnick = xchat.strip(word[0]) destination = xchat.get_context() if destination.get_info('channel') == "#scc-announce" and stnick == "SCC": #grep the line to get the infos scctext = re.match(rls_regx, xchat.strip(sttext)) #Size details sizedetail = scctext.group(4).replace(')', '') sizedetail = sizedetail.replace('(', '') sizedetail = re.search("([0-9]{1,6}\.[0-9]{2})(.*)(M|m|K|k|G|g)(.*)", sizedetail) #sizedetail.group(1) = 541.34 #sizedetail.group(3) = M nicesize = sizedetail.group(1)+sizedetail.group(3) if sizedetail.group(3) == "K" or sizedetail.group(3) == "k": multi=int(1024) if sizedetail.group(3) == "M" or sizedetail.group(3) == "m": multi=int(1048576) if sizedetail.group(3) == "G" or sizedetail.group(3) == "g": multi=int(1073741824) torrent_size_bytes = float(sizedetail.group(1)) * multi torrent_size_bytes = int(torrent_size_bytes) pretimere = re.search("Uploaded (.*) after pre", scctext.group(4)) if pretimere is not None: pretime = pretimere.group(1) else: pretime = "NOT_AVAILABLE" rls_link = "https://www.sceneaccess.org/details.php?id=" + str(scctext.group(5)) current_time = time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime()) currnet_time_unix = int(time.time()) print "Adding " + scctext.group(3) + " to the RLSdb" dmobj.Additem(dmobj.GetLastIndex(), scctext.group(5), current_time, currnet_time_unix, "Good", scctext.group(3), scctext.group(2), torrent_size_bytes, pretime, rls_link, "False", "__dm_blank_val__", "__dm_blank_val__", "__dm_blank_val__", "__dm_blank_val__", "__dm_blank_val__", "__dm_blank_val__", "__dm_blank_val__", "PRELIM DATA! NOT SUITABLE FOR PRODUCTION USE!") elif destination.get_info('channel') == "#rlsdb": loc = xchat.get_context() # stnick = Nick # sttext = Text st_args = "" text_split = re.split(' ', word[1], 1) st_cmd = text_split[0] try: st_args = text_split[1] except: text_split.append(None) st_args = text_split[1] if st_cmd.lower() == "!help": if st_args is None: msg = "NOTICE " + stnick + " " + color["lblue"] + "Accepted commands: !search, !rgxsearch, !id, !getresults, !dbstats. For further help with the listed commands, use !help <command>." xchat.command(msg) else: if st_args == "!search": msg = ["NOTICE " + stnick + " " + color["lblue"] + "!search " + color["dyellow"] + "[@grp] " + color["red"] + "<args>" + color["lblue"] +":"] msg.append("NOTICE " + stnick + " " + color["lblue"] + "This will search for torrents that either partially or fully match the supplied args. This accepts the following wildcards: * % ") msg.append("NOTICE " + stnick + " " + color["lblue"] + "The first part inside the [] is completely optional. It allows the option to search through a certain section/groups only. Here is an example of how to properly use this feature:") msg.append("NOTICE " + stnick + " " + color["lblue"] + "!search @TV/XviD Top.Gear*") msg.append("NOTICE " + stnick + " " + color["lblue"] + "This will search for Top.Gear* in the TV/XviD group. You can also wildcard the group. Again, the group part is completely optional. If you don't include it then RLSdb will search through all groups.") if st_args == "!rgxsearch": msg = ["NOTICE " + stnick + " " + color["lblue"] + "!rgxsearch " + color["dyellow"] + "[@grp] " + color["red"] + "<args>" + color["lblue"] +":"] msg.append("NOTICE " + stnick + " " + color["lblue"] + "This is the same as !search except that it does not accept wildcards. Instead, it fully accepts regexes.") if st_args == "!id": msg = ["NOTICE " + stnick + " " + color["lblue"] + "!id " + color["red"] + "<id>" + color["lblue"] +":"] msg.append("NOTICE " + stnick + " " + color["lblue"] + "This will search for a torrent with the matching ID. The ID is the one SCC uses for its torrents.") if st_args == "!getresults": msg = ["NOTICE " + stnick + " " + color["lblue"] + "!getresults " + color["red"] + "<searchID>" + color["lblue"] +":"] msg.append("NOTICE " + stnick + " " + color["lblue"] + "This will return the search results from the provided SearchID in a private notice.") if st_args == "!dbstats": msg = ["NOTICE " + stnick + " " + color["lblue"] + "!dbstats:"] msg.append("NOTICE " + stnick + " " + color["lblue"] + "This will return statistics on the database RLSdb is using.") for x in msg: xchat.command(x) elif st_cmd.lower() == "!search": print "D1" if re.search("(@.*) ", st_args) is None: print "D2" query = st_args.replace('*', '%') query_data = dmobj.Querybyname(query) if query_data[0] == "GOOD": print "D3" result_size = str(len(query_data[1])) nextid = str(results_keeper["index"] + 1) results_keeper["index"] = int(nextid) if int(result_size) > 25: fnum = "first 25 results" elif int(result_size) == 1: fnum = "result" else: fnum = "the " + str(result_size) + " results" msg = "MSG #rlsdb " + color["lblue"] + "Found " + color["purple"] + result_size + color["lblue"] + " entries that matched " + stnick + "'s query. Sending " + fnum + " in a PM. Search id: " + str(nextid) loc.command(msg) n = 1 res = None for x in query_data[1]: result = dmobj.QuerybyIndex(x) nres = color["lblue"] + str(n) + ": " + color["closec"] + color["bold"] + result[5] + " - " + result[4] + " - " + result[8] msg2 = "MSG " + stnick + " " + color["lblue"] + str(n) + ": " + color["closec"] + color["bold"] + result[5] + " - " + result[4] + " - " + result[8] if n == 1: res = [nres] else: res.append(nres) if n < 26: loc.command(msg2) else: break n += 1 results_keeper[nextid] = res else: msg = "MSG #rlsdb " + color["lblue"] + "Didn't find any matches for " + st_args loc.command(msg) else: print "D4" query = re.search("(@.*) (.*)", st_args) # query.group(1) = the group # query.group(2) = the args fxgrp = query.group(1).replace('@', '') fxgrp = fxgrp.replace('*', '%') fxargs = query.group(2).replace('*', '%') query_data = dmobj.Querybynamegrp(fxgrp, fxargs) if query_data[0] == "GOOD": print "D5" result_size = str(len(query_data[1])) nextid = str(results_keeper["index"] + 1) results_keeper["index"] = int(nextid) if int(result_size) > 25: fnum = "first 25 results" elif int(result_size) == 1: fnum = "result" else: fnum = "the " + str(result_size) + " results" msg = "MSG #rlsdb " + color["lblue"] + "Found " + color["purple"] + result_size + color["lblue"] + " entries that matched " + stnick + "'s query. Sending " + fnum + " in a PM. Search id: " + str(nextid) loc.command(msg) n = 1 res = None for x in query_data[1]: result = dmobj.QuerybyIndex(x) nres = color["lblue"] + str(n) + ": " + color["closec"] + color["bold"] + result[5] + " - " + result[4] + " - " + result[8] msg2 = "MSG " + stnick + " " + color["lblue"] + str(n) + ": " + color["closec"] + color["bold"] + result[5] + " - " + result[4] + " - " + result[8] if n == 1: res = [nres] else: res.append(nres) if n < 26: loc.command(msg2) else: break n += 1 results_keeper[nextid] = res else: msg = "MSG #rlsdb " + color["lblue"] + "Didn't find any matches for " + st_args loc.command(msg) elif st_cmd.lower() == "!id": if len(st_args) > 0: id = int(st_args) query_data = dmobj.Querybyid(id) if query_data[0] == "GOOD": print "YEY!" print query_data result_size = len(query_data[1]) else: print query_data else: msg = "NOTICE " + stnick + " " + color["lblue"] + "You need to specify an ID to query! Maybe you haven't used !help? " elif st_cmd.lower() == "!dbstats": dbstats = dmobj.GetDBStats() msg = ["MSG #rlsdb " + color["red"] + color["bold"] + "RLSdb Database Stats"] msg.append("MSG #rlsdb " + color["red"] + "Total Entries: " + color["lblue"] + str(dbstats[0])) msg.append("MSG #rlsdb " + color["red"] + "Last Release Added: " + color["lblue"] + dbstats[1]) msg.append("MSG #rlsdb " + color["red"] + "Database Size: " + color["lblue"] + dbstats[2]) for x in msg: xchat.command(x) elif st_cmd.lower() == "!getresults": try: int(st_args) scid = str(st_args) fail=False except: fail=True if fail is False: try: results_keeper[scid] sfail = False except: sfail = True if sfail is False: msg1 = "MSG #rlsdb " + color["lblue"] + "Sending results from SearchID #" + scid + " to " + stnick loc.command(msg1) for x in results_keeper[scid]: msg = "NOTICE " + stnick + " " + x loc.command(msg) if sfail is True: msg1 = "MSG #rlsdb " + color["lblue"] + "Couldn't find SearchID #" + scid loc.command(msg1) # This gets the script movinif (__name__ == "__main__"): main()def scriptunload(userdata): print "\0034" + __module_name__, __module_version__,"has been unloaded\003" xchat.hook_unload(scriptunload)xchat.hook_print('Channel Message', on_text)