def assertSortBySimilarity(self, search): results = [{ 'title': 'Ipsum ep01' }, { 'title': 'Ipsum Dolor ep01' }, { 'title': 'Ipsum Dolor Sit ep01' }] AnimesubUtil.sort_by_similarity(search, 'title', results) first_item = results[0] self.assertEqual(search, first_item['title'])
def get_results(self, name, language): results = [] url = "http://animesub.info/szukaj.php?szukane={0}&pTitle={1}".format(name, language) s = requests.Session() r = s.get(url) read_data = r.text list_items = re.compile('<tr class="KNap"><td align="left">(.+?)<\/td>([\S\s]+?)value="(.+?)">([\S\s]+?)value="(.+?)">').findall(read_data) count = len(list_items) if count > 0: for item in list_items: title = item[0] kod = item[2] token = item[4] cookie = (s.cookies.items()) cookie = (cookie[0][1]) results.append({"title": title, "kod": kod, "token": token, "cookie": cookie}) AnimesubUtil.sort_by_similarity(name, "title", results) return results
def _search_tvshow(self, item): if item.get('searchstring', None): name = item['searchstring'] else: name = AnimesubUtil(item["file_original_name"]).searchable() log("Szukana nazwa: %s" % name) results = self.get_results(name, "org") if len(results) == 0: results = self.get_results(name, "en") if len(results) == 0: results = self.get_results(name, "pl") return results
def download(self, kod, token, zip_filename, cookie, file_name): ## Cleanup temp dir, we recomend you download/unzip your subs in temp folder and ## pass that to XBMC to copy and activate if xbmcvfs.exists(__temp__): shutil.rmtree(__temp__) xbmcvfs.mkdirs(__temp__) cookies = {'ansi_sciagnij': cookie} data = [('id', kod), ('sh', token), ('single_file', 'Pobierz napisy')] r = requests.post('http://animesub.info/sciagnij.php', cookies=cookies, data=data) with open(zip_filename, "wb") as subFile: subFile.write(r.content) subFile.close() AnimesubUtil(file_name).prepare_zip(zip_filename) xbmc.Monitor().waitForAbort(0.5) xbmc.executebuiltin(('XBMC.Extract("%s","%s")' % (zip_filename, __temp__,)).encode('utf-8'), True)
def assertEpisode(self, expected, actual): self.assertEqual(expected, AnimesubUtil(actual).episode())
def assertPrepareZip(self, search_name, check_name, zip_content): prepared_content = AnimesubUtil(search_name).prepare_zip(zip_content) with ZipFile(prepared_content, 'r') as prepared_zip: self.assertEquals(1, len(prepared_zip.filelist)) self.assertEquals(check_name, prepared_zip.filelist[0].filename)
def assertTitle(self, expected, actual): self.assertEqual(expected, AnimesubUtil(actual).searchable())