From 8d3d918accfd4392237cf59f94140ced81a44cba Mon Sep 17 00:00:00 2001 From: imDMG Date: Sun, 20 Jan 2019 00:29:04 +0500 Subject: [PATCH] add NoNaMe-Club search engine --- nnmclub.ico | Bin 0 -> 1150 bytes nnmclub.json | 10 ++ nnmclub.png | Bin 0 -> 912 bytes nnmclub.py | 265 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 275 insertions(+) create mode 100644 nnmclub.ico create mode 100644 nnmclub.json create mode 100644 nnmclub.png create mode 100644 nnmclub.py diff --git a/nnmclub.ico b/nnmclub.ico new file mode 100644 index 0000000000000000000000000000000000000000..c25690734fb4e9380bf1b1b0be161410d217e640 GIT binary patch literal 1150 zcmb7CT}YEr7=F&TP3N>VbG0;S>mn2(u_!cxbVGt7FHH2J@**gSE}|e-1XIF7f^x+Q zAqq`z{237hS!Q5R5Lk-cgjz(H7sf8cnU4KEyVi1pWF=9Wi2&(M&!)*40) zn?m=H;4GNv0r?p89>M+p`0Xn>1(XfnM4WLjIc6uLwLE@eW1DCUg0z)dn;D)iH|Wd9 zH&+@Oh0|*}CTle^B6}wa8Cz&d)}1T~wBANv_cgq+YAE?zQP_P}yIK>ERvVRGD}OU1ZYAv1&z48Rs0p`Mqhl zTnUWSX^31hf+J4R-4)ybf5==kM;o`}^XP+oerP{PPFOipgLsDVPapInN;_fAx4?ZM z1I-tm2>N|^>#abaI};7Mz+_Mrp3~wM~;L}3P>G?Gd^}Y&o6UAU`2wZFh&t<8e zHF|ZKx=@U^Px39lI;Fo=V3850*Wt&mEHrdyBRby#jvqrpy#M?oscKmiimpm;Lvlaf zGZ;vvU(IJL?4BwGzYbwuIP+>g)mrvH9CRR@V?jYG?P@+=9&|^XOL&nUbi*J}0xUsE QY-Z4HScX1tS%zQYZ=vuTcK!~P$2kGQf!OSh@w$m<2)C;ADxj}E*i#%p`#5uEt{&L`6>zWya8v5w zdtfgQd@upZCLpq`xj!crU~1Q|%hOT;7%?JyAPxgF4+F3MWvmsLBgec>LV*xGZE?zl>W3XuuX= zc|F>uu%;adLu4^N|3Ms`kE=f9oPbCIQ7EK#aB+S&pz6~szqtU%>u{(Otb}Go?a|pFCkc)a#J+`NhV6D^lrTdC1yuop z6hyZov;hfDtQvv+6B^uT^P-=i`6c)kbP%T76>RtmR|uR0stz{)C0s=2CGe2&5nsNW zV1l5_i*tn5pFfvo(NAUBa6#xmKJ?wwrs%o8qA9qze(zU1BH z&hLj^?|j!Z5AJ;MU5`?~t_+X#HJrc6uk@S|eC9npF*|-KCdQZ)n34QiL|vIJYcn*} zM=uf$Z31mNy*6-+35$qHUUNa(NGXR-qsohVY&MxJTT0TIrA0kEWUTX#G^vbj-h5*; zHS<7G+A4xd3v+0o&7`u()wkl$&CfiL)7Lv8+8x9d=@xB^-jK47J2Ke$zNt`~V2ybC zyQ}8*0`9lBjZc1^K6byy**u!MH$>0<;;B}bwzR)F_2|MLJ1k!PrMcl=_jbeA z<-u!DblpwgVKo{yZ8aY)Yi+UHS9b_by}DGFJ)Gzmbd;CROw{zE@2B`e;iA4gnmoa# zEwovRZC0gukCg(FctwhwSI8A9c}cu7DOtIE*%Dr%'): + data = data[3:-5] + if self.index_td == 5: + data = data.split('')[1].strip() + self.torrent[self.write] = data.strip() + self.write = None + + def error(self, message): + pass + + def download_torrent(self, url): + # Create a torrent file + file, path = tempfile.mkstemp('.torrent') + file = os.fdopen(file, "wb") + + # Download url + response = self._catch_error_request(url) + + # Write it to a file + file.write(response.read()) + file.close() + + # return file path + logging.debug(path + " " + url) + print(path + " " + url) + + def search(self, what, cat='all'): + c = self.supported_categories[cat] + query = '{}tracker.php?nm={}&{}'.format(self.url, what.replace(" ", "+"), "f=-1" if c == '-1' else "c=" + c) + response = self._catch_error_request(query) + parser = self.WorstParser(self.url) + parser.feed(response.read().decode('cp1251')) + parser.close() + + # if first request return that we have pages, we do cycle + if parser.pages: + for x in range(1, parser.pages): + response = self._catch_error_request('{}&start={}'.format(query, # &search_id= + # parser.search_id, + parser.found_torrents, + self.supported_categories[cat])) + parser.feed(response.read().decode('cp1251')) + parser.close() + + logging.info("Found torrents: %s" % parser.found_torrents) + + def _catch_error_request(self, url='', data=None): + url = url if url else self.url + + try: + response = self.session.open(url, data) + # Only continue if response status is OK. + if response.getcode() != 200: + logging.error('Unable connect') + raise HTTPError(response.geturl(), response.getcode(), + "HTTP request to {} failed with status: {}".format(url, response.getcode()), + response.info(), None) + except (URLError, HTTPError) as e: + logging.error(e) + raise e + + return response + + +if __name__ == "__main__": + nnmclub_se = nnmclub() + nnmclub_se.search('supernatural') + print("--- %s seconds ---" % (time.time() - start_time))