2020-04-24 19:01:44 +00:00
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
2022-09-01 18:52:02 +00:00
|
|
|
from .core import ConnectorCache, ConnectorCore, ConnectorReturn, curl_content
|
|
|
|
from ..utils import check_blacklist_words, check_if_vf, link_exist_in_db
|
2020-04-24 19:01:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Nyaa(ConnectorCore):
|
2022-09-01 18:52:02 +00:00
|
|
|
color = "is-link"
|
|
|
|
title = "Nyaa"
|
|
|
|
favicon = "nyaa.png"
|
|
|
|
base_url = "https://nyaa.si"
|
2020-04-24 19:01:44 +00:00
|
|
|
is_light = False
|
|
|
|
|
|
|
|
def get_full_search_url(self):
|
2022-09-01 18:52:02 +00:00
|
|
|
sort_type = "size"
|
2020-04-24 19:01:44 +00:00
|
|
|
if self.return_type is ConnectorReturn.HISTORY:
|
2022-09-01 18:52:02 +00:00
|
|
|
sort_type = "id"
|
2020-04-24 19:01:44 +00:00
|
|
|
|
2022-09-01 18:52:02 +00:00
|
|
|
to_query = "(%s vf)|(%s vostfr)|(%s multi)|(%s french)" % (
|
2021-09-01 15:57:54 +00:00
|
|
|
self.query,
|
|
|
|
self.query,
|
|
|
|
self.query,
|
2022-09-01 18:52:02 +00:00
|
|
|
self.query,
|
|
|
|
)
|
|
|
|
return "%s/?f=0&c=1_3&s=%s&o=desc&q=%s&p=%s" % (
|
|
|
|
self.base_url,
|
|
|
|
sort_type,
|
|
|
|
to_query,
|
|
|
|
self.page,
|
2021-09-01 15:57:54 +00:00
|
|
|
)
|
2020-04-24 19:01:44 +00:00
|
|
|
|
|
|
|
def get_history(self):
|
|
|
|
self.search()
|
|
|
|
|
|
|
|
@ConnectorCache.cache_data
|
|
|
|
def search(self):
|
|
|
|
response = curl_content(self.get_full_search_url())
|
|
|
|
|
2022-09-01 18:52:02 +00:00
|
|
|
if response["http_code"] == 200:
|
|
|
|
html = BeautifulSoup(response["output"], "html.parser")
|
|
|
|
trs = html.select("table.torrent-list tr")
|
2020-04-24 19:01:44 +00:00
|
|
|
valid_trs = 0
|
|
|
|
|
|
|
|
for i, tr in enumerate(trs):
|
|
|
|
if not i:
|
|
|
|
continue
|
|
|
|
|
2022-09-01 18:52:02 +00:00
|
|
|
tds = tr.findAll("td")
|
2020-05-20 14:25:08 +00:00
|
|
|
check_downloads = int(tds[7].get_text())
|
|
|
|
check_seeds = int(tds[5].get_text())
|
2020-04-24 19:01:44 +00:00
|
|
|
|
|
|
|
if check_downloads or check_seeds:
|
2022-09-01 18:52:02 +00:00
|
|
|
urls = tds[1].findAll("a")
|
2020-04-24 19:01:44 +00:00
|
|
|
|
|
|
|
if len(urls) > 1:
|
|
|
|
url = urls[1]
|
|
|
|
has_comment = True
|
|
|
|
else:
|
|
|
|
url = urls[0]
|
|
|
|
has_comment = False
|
|
|
|
|
|
|
|
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
|
2022-09-01 18:52:02 +00:00
|
|
|
href = self.base_url + url["href"]
|
|
|
|
|
|
|
|
self.data.append(
|
|
|
|
{
|
|
|
|
"vf": check_if_vf(url_safe),
|
|
|
|
"href": href,
|
|
|
|
"name": url_safe,
|
|
|
|
"comment": str(urls[0]).replace(
|
|
|
|
"/view/", self.base_url + "/view/"
|
|
|
|
)
|
|
|
|
if has_comment
|
|
|
|
else "",
|
|
|
|
"link": tds[2]
|
|
|
|
.decode_contents()
|
|
|
|
.replace("/download/", self.base_url + "/download/"),
|
|
|
|
"size": tds[3].get_text(),
|
|
|
|
"date": tds[4].get_text(),
|
|
|
|
"seeds": check_seeds,
|
|
|
|
"leechs": tds[6].get_text(),
|
|
|
|
"downloads": check_downloads,
|
|
|
|
"class": self.color
|
|
|
|
if link_exist_in_db(href)
|
|
|
|
else "is-%s" % tr["class"][0],
|
|
|
|
}
|
|
|
|
)
|
2020-04-24 19:01:44 +00:00
|
|
|
|
|
|
|
self.on_error = False
|
2021-07-11 08:51:57 +00:00
|
|
|
self.is_more = valid_trs and valid_trs != len(trs) - 1
|
2021-01-30 18:40:36 +00:00
|
|
|
|
|
|
|
@ConnectorCache.cache_data
|
|
|
|
def is_vf(self, url):
|
|
|
|
response = curl_content(url)
|
|
|
|
|
2022-09-01 18:52:02 +00:00
|
|
|
if response["http_code"] == 200:
|
|
|
|
html = BeautifulSoup(response["output"], "html.parser")
|
|
|
|
title = html.select("h3.panel-title")
|
2021-01-30 18:40:36 +00:00
|
|
|
return check_if_vf(title[0].get_text())
|
|
|
|
|
|
|
|
return False
|