This repository has been archived on 2023-10-01. You can view files and clone it, but cannot push or open issues or pull requests.
PyNyaaTa/pynyaata/connectors/yggtorrent.py

99 lines
3.5 KiB
Python
Raw Normal View History

2020-04-24 19:01:44 +00:00
import re
from datetime import datetime
from urllib.parse import quote
from bs4 import BeautifulSoup
2022-12-21 14:53:50 +00:00
from .core import ConnectorCache, ConnectorCore, ConnectorReturn, curl_content
from ..utils import check_blacklist_words, check_if_vf, link_exist_in_db, parse_date
2020-04-24 19:01:44 +00:00
class YggTorrent(ConnectorCore):
color = 'is-success'
title = 'YggTorrent'
favicon = 'yggtorrent.png'
base_url = 'https://www6.yggtorrent.lol'
2020-04-24 19:01:44 +00:00
is_light = False
category = 2179
def get_full_search_url(self):
sort_type = 'size'
if self.return_type is ConnectorReturn.HISTORY:
sort_type = 'publish_date'
sort_page = '&page=%s' % (
(self.page - 1) * 50
) if self.page > 1 else ''
2020-04-24 19:01:44 +00:00
return '%s/engine/search?name=%s&category=2145&sub_category=%s&do=search&order=desc&sort=%s%s' % (
self.base_url, self.query, self.category, sort_type, sort_page
)
def get_history(self):
self.search()
@ConnectorCache.cache_data
def search(self):
if self.category:
response = curl_content(
self.get_full_search_url(), cloudflare=True
)
2020-04-24 19:01:44 +00:00
if response['http_code'] == 200:
html = BeautifulSoup(response['output'], 'html.parser')
trs = html.select('table.table tr')
valid_trs = 0
for i, tr in enumerate(trs):
if not i:
continue
tds = tr.findAll('td')
check_downloads = int(tds[6].get_text())
check_seeds = int(tds[7].get_text())
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
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': url['href'],
'name': url_safe,
'comment': '<a href="%s#comm" target="_blank"><i class="fa fa-comments-o"></i>%s</a>' %
(url['href'], tds[3].decode_contents()),
'link': '<a href="%s/engine/download_torrent?id=%s">'
'<i class="fa fa-fw fa-download"></i>'
'</a>' % (self.base_url,
re.search(r'/(\d+)', url['href']).group(1)),
'size': tds[5].get_text(),
'date': parse_date(datetime.fromtimestamp(int(tds[4].div.get_text()))),
2020-04-24 19:01:44 +00:00
'seeds': check_seeds,
'leechs': tds[8].get_text(),
2020-04-24 19:01:44 +00:00
'downloads': check_downloads,
'class': self.color if link_exist_in_db(quote(url['href'], '/+:')) else ''
})
self.on_error = False
2021-07-11 08:51:57 +00:00
self.is_more = valid_trs and valid_trs != len(trs) - 1
2020-04-24 19:01:44 +00:00
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('#title h1')
return check_if_vf(title[0].get_text())
return False
2020-04-24 19:01:44 +00:00
class YggAnimation(YggTorrent):
title = 'YggAnimation'
category = 2178