def search_nyaa_magnet(car: str): rt = [] try: respBT = requests.get('https://sukebei.nyaa.si/?f=0&c=0_0&q=' + car) BTTree = html.fromstring(respBT.content) bt_xpath = '//*/tbody/tr/td[@class="text-center"]/a[2]/@href' if len(BTTree.xpath(bt_xpath)) > 0: print(f'{car} found in nyaa') name_xpath = '//*/tbody/tr/td[@colspan="2"]/a' titles = [ ind.get('title', '')[0:25] for ind in BTTree.xpath(name_xpath) ] file_xpath = '//*/tbody/tr/td' file_sizes = [ ind.text for ind in BTTree.xpath(file_xpath) if 'GiB' in ind.text or 'Bytes' in ind.text or 'MiB' in ind.text ] magnets = BTTree.xpath(bt_xpath) for i in range(len(titles)): rt.append({ 'title': titles[i], 'size': file_sizes[i], 'magnet': magnets[i], 'car': car, 'size_sort': parsed_size_to_int(file_sizes[i]) }) except Exception: print_exc() pass return rt
def search_torrentkitty_magnet(car: str): rt = [] try: # torrent kitty is good for chinese subtitled movies respBT = requests.get('https://www.torrentkitty.tv/search/' + car) BTTree = html.fromstring(respBT.content) bt_xpath = '//html/body//table[@id="archiveResult"]//td[@class="action"]/a[2]/@href' if len(BTTree.xpath(bt_xpath)) > 0: print(f'{car} found in torrentkitty') name_xpath = '//html/body//table[@id="archiveResult"]//td[@class="name"]' titles = [ ind.text_content()[0:25] for ind in BTTree.xpath(name_xpath) ] file_xpath = '//html/body//table[@id="archiveResult"]//td[@class="size"]/text()' file_sizes = [ind for ind in BTTree.xpath(file_xpath)] magnets = BTTree.xpath(bt_xpath) for i in range(len(titles)): rt.append({ 'title': titles[i], 'size': file_sizes[i], 'magnet': magnets[i], 'car': car, 'size_sort': parsed_size_to_int(file_sizes[i]) }) except Exception as e: print_exc() pass return rt
def javbus_magnet_search(car: str): jav_url = return_config_string(['其他设置', 'javbus网址']) gid_match = r'.*?var gid = (\d*);.*?' magnet_xpath = { 'magnet': '//tr/td[position()=1]/a[1]/@href', 'title': '//tr/td[position()=1]/a[1]/text()', 'size': '//tr/td[position()=2]/a[1]/text()' } main_url_template = jav_url+'{car}' magnet_url_template = jav_url+'ajax/uncledatoolsbyajax.php?gid={gid}&uc=0' res = return_get_res(main_url_template.format(car=car)).text gid = re.search(gid_match, res).groups()[0] res = return_get_res(magnet_url_template.format(gid=gid), headers={'referer': main_url_template.format(car=car)}).content root = etree.HTML(res) magnets = defaultlist(dict) for k, v in magnet_xpath.items(): _values = root.xpath(v) for _i, _value in enumerate(_values): magnets[_i].update({k: _value.strip('\t').strip('\r').strip('\n').strip()}) if k == 'size': magnets[_i].update({'size_sort': parsed_size_to_int(_value.strip('\t').strip('\r').strip('\n').strip())}) return magnets