2020-04-24 19:01:44 +00:00
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
|
|
|
from .core import ConnectorCore, ConnectorReturn, ConnectorCache, curl_content
|
2021-01-30 18:40:36 +00:00
|
|
|
from ..utils import parse_date, link_exist_in_db, check_blacklist_words, check_if_vf
|
2020-04-24 19:01:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Pantsu(ConnectorCore):
|
|
|
|
color = 'is-info'
|
|
|
|
title = 'Pantsu'
|
|
|
|
favicon = 'pantsu.png'
|
|
|
|
base_url = 'https://nyaa.net'
|
|
|
|
is_light = False
|
2021-01-07 20:19:50 +00:00
|
|
|
is_behind_cloudflare = False
|
2020-04-24 19:01:44 +00:00
|
|
|
|
|
|
|
def get_full_search_url(self):
|
|
|
|
sort_type = 4
|
|
|
|
if self.return_type is ConnectorReturn.HISTORY:
|
|
|
|
sort_type = 2
|
|
|
|
|
|
|
|
to_query = '(%s vf)|(%s vostfr)|(%s multi)|(%s french)' % (self.query, self.query, self.query, self.query)
|
|
|
|
return '%s/search/%s?c=3_13&order=false&q=%s&sort=%s' % (self.base_url, self.page, to_query, sort_type)
|
|
|
|
|
|
|
|
def get_history(self):
|
|
|
|
self.search()
|
|
|
|
|
|
|
|
@ConnectorCache.cache_data
|
|
|
|
def search(self):
|
|
|
|
response = curl_content(self.get_full_search_url())
|
|
|
|
|
|
|
|
if response['http_code'] == 200:
|
|
|
|
html = BeautifulSoup(response['output'], 'html.parser')
|
|
|
|
trs = html.select('div.results tr')
|
|
|
|
valid_trs = 0
|
|
|
|
|
|
|
|
for i, tr in enumerate(trs):
|
|
|
|
if not i:
|
|
|
|
continue
|
|
|
|
|
|
|
|
tds = tr.findAll('td')
|
2020-05-20 14:25:08 +00:00
|
|
|
check_downloads = int(tds[6].get_text().replace('-', '0'))
|
|
|
|
check_seeds = int(tds[4].get_text().replace('-', '0'))
|
2020-04-24 19:01:44 +00:00
|
|
|
|
|
|
|
if check_downloads or check_seeds:
|
|
|
|
url = tds[1].a
|
|
|
|
url_safe = url.get_text()
|
|
|
|
|
2020-04-27 18:47:54 +00:00
|
|
|
if check_blacklist_words(url_safe):
|
2020-04-24 19:01:44 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
valid_trs = valid_trs + 1
|
2020-04-24 19:49:30 +00:00
|
|
|
href = self.base_url + url['href']
|
2020-04-24 19:01:44 +00:00
|
|
|
|
|
|
|
self.data.append({
|
2021-01-30 18:40:36 +00:00
|
|
|
'vf': check_if_vf(url_safe),
|
2020-04-24 19:01:44 +00:00
|
|
|
'href': href,
|
|
|
|
'name': url_safe,
|
|
|
|
'comment': '',
|
|
|
|
'link': tds[2].decode_contents().replace('icon-magnet', 'fa fa-fw fa-magnet').replace(
|
|
|
|
'icon-floppy', 'fa fa-fw fa-download'),
|
2020-05-20 14:25:08 +00:00
|
|
|
'size': tds[3].get_text(),
|
2020-04-24 19:01:44 +00:00
|
|
|
'date': parse_date(tds[7]['title'][:-6], '%m/%d/%Y, %I:%M:%S %p'),
|
|
|
|
'seeds': check_seeds,
|
2020-05-20 14:25:08 +00:00
|
|
|
'leechs': tds[5].get_text(),
|
2020-04-24 19:01:44 +00:00
|
|
|
'downloads': check_downloads,
|
|
|
|
'class': self.color if link_exist_in_db(href) else 'is-%s' % tr['class'][0]
|
|
|
|
})
|
|
|
|
|
|
|
|
self.on_error = False
|
|
|
|
self.is_more = valid_trs and valid_trs is not len(trs) - 1
|
2021-01-30 18:40:36 +00:00
|
|
|
|
|
|
|
@ConnectorCache.cache_data
|
|
|
|
def is_vf(self, url):
|
|
|
|
response = curl_content(url)
|
|
|
|
|
|
|
|
if response['http_code'] == 200:
|
|
|
|
html = BeautifulSoup(response['output'], 'html.parser')
|
|
|
|
title = html.select('h1.torrent-hr')
|
|
|
|
print(title, flush=True)
|
|
|
|
return check_if_vf(title[0].get_text())
|
|
|
|
|
|
|
|
return False
|