From fa57752714418ba67a6ad8d176e5a8f3b1c37e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?X=C3=A9fir=20Destiny?= Date: Sun, 1 Dec 2019 18:30:24 +0100 Subject: [PATCH] Change how Ygg is handled --- app.py | 21 +++++++++++++++--- connectors.py | 51 ++++++++++++++++++++++++++++++++++++++++--- templates/home.html | 3 --- templates/latest.html | 27 +++++++++++++++++++++++ templates/layout.html | 2 +- templates/search.html | 2 +- 6 files changed, 95 insertions(+), 11 deletions(-) delete mode 100644 templates/home.html create mode 100644 templates/latest.html diff --git a/app.py b/app.py index 27a2f48..aa706a9 100644 --- a/app.py +++ b/app.py @@ -16,7 +16,7 @@ def verify_password(username, password): @app.route('/') def home(): - return render_template('home.html', form=SearchForm()) + return render_template('layout.html', form=SearchForm()) @app.route('/search') @@ -28,8 +28,8 @@ def search(): results = [ Nyaa(query).run(), Pantsu(query).run(), - YggTorrent(query, category=2179).run(), - YggTorrent(query, category=2178).run(), + YggTorrent(query).run(), + YggAnimation(query).run(), AnimeUltime(query).run(), ] return render_template('search.html', form=SearchForm(), connectors=results) @@ -37,6 +37,21 @@ def search(): @app.route('/latest') def latest(): + torrents = [ + Nyaa('', return_type=ConnectorReturn.HISTORY, page=request.args.get('page', 1)).run(), + Pantsu('', return_type=ConnectorReturn.HISTORY, page=request.args.get('page', 1)).run(), + YggTorrent('', return_type=ConnectorReturn.HISTORY, page=request.args.get('page', 1)).run(), + YggAnimation('', return_type=ConnectorReturn.HISTORY, page=request.args.get('page', 1)).run(), + AnimeUltime('', return_type=ConnectorReturn.HISTORY, page=request.args.get('page', 1)).run(), + ] + + results = [] + + for torrent in torrents: + results = results + torrent.data + + print(results) + return 'Hello!' diff --git a/connectors.py b/connectors.py index 19ab514..5df1f5e 100644 --- a/connectors.py +++ b/connectors.py @@ -25,9 +25,38 @@ class ConnectorLang(Enum): class Connector(ABC): blacklist_words = ['Chris44', 'Vol.'] - def __init__(self, query, page=1, return_type=ConnectorReturn.SEARCH, category=None): + @property + @abstractmethod + def color(self): + pass + + @property + @abstractmethod + def title(self): + pass + + @property + @abstractmethod + def favicon(self): + pass + + @property + @abstractmethod + def base_url(self): + pass + + @property + @abstractmethod + def is_light(self): + pass + + @property + @abstractmethod + def is_behind_cloudflare(self): + pass + + def __init__(self, query, page=1, return_type=ConnectorReturn.SEARCH): self.query = query - self.category = category self.data = [] self.is_more = False self.on_error = True @@ -54,7 +83,7 @@ class Connector(ABC): return self def curl_content(self, url, params=None, ajax=False): - if isinstance(self, YggTorrent): + if self.is_behind_cloudflare: try: qt_env = {'QT_QPA_PLATFORM': 'offscreen'} if platform is 'linux' else {} qt_output = run('phantomjs --cookies-file=/tmp/cookies.json delay.js "%s" 5000' % url, env=qt_env, @@ -114,6 +143,7 @@ class Nyaa(Connector): favicon = 'nyaa.png' base_url = 'https://nyaa.si' is_light = False + is_behind_cloudflare = False def get_full_search_url(self): sort_type = 'size' @@ -186,6 +216,7 @@ class Pantsu(Connector): favicon = 'pantsu.png' base_url = 'https://nyaa.net' is_light = False + is_behind_cloudflare = False def get_full_search_url(self): sort_type = 4 @@ -253,6 +284,8 @@ class YggTorrent(Connector): favicon = 'yggtorrent.png' base_url = 'https://www2.yggtorrent.pe' is_light = False + is_behind_cloudflare = True + category = 2179 def get_full_search_url(self): sort_type = 'size' @@ -312,12 +345,23 @@ class YggTorrent(Connector): self.is_more = valid_trs is not len(trs) +class YggAnimation(YggTorrent): + color = 'is-success' + title = 'YggAnimation' + favicon = 'yggtorrent.png' + base_url = 'https://www2.yggtorrent.pe' + is_light = False + is_behind_cloudflare = True + category = 2178 + + class AnimeUltime(Connector): color = 'is-warning' title = 'Anime-Ultime' favicon = 'animeultime.png' base_url = 'http://www.anime-ultime.net' is_light = True + is_behind_cloudflare = False def get_full_search_url(self): from_date = '' @@ -416,6 +460,7 @@ class Other(Connector): title = 'Other' favicon = 'blank.png' is_light = True + is_behind_cloudflare = False def get_full_search_url(self): pass diff --git a/templates/home.html b/templates/home.html deleted file mode 100644 index 48a21f7..0000000 --- a/templates/home.html +++ /dev/null @@ -1,3 +0,0 @@ -{% extends "layout.html" %} -{% block title %}Animes torrents search engine{% endblock %} -{% block body %}{% endblock %} diff --git a/templates/latest.html b/templates/latest.html new file mode 100644 index 0000000..d191e31 --- /dev/null +++ b/templates/latest.html @@ -0,0 +1,27 @@ +{% extends "layout.html" %} +{% block title %} - Latest{% endblock %} +{% block body %} + + + + + + + + + + + + + + + + +
NameLinkSizeDate + + + + + +
+{% endblock %} diff --git a/templates/layout.html b/templates/layout.html index 57f2606..92fdbcf 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -5,7 +5,7 @@ - {% block title %}{% endblock %} + Animes torrents search engine{% block title %}{% endblock %} diff --git a/templates/search.html b/templates/search.html index f3b5c6a..470618d 100644 --- a/templates/search.html +++ b/templates/search.html @@ -1,5 +1,5 @@ {% extends "layout.html" %} -{% block title %}Animes torrents search engine - {{ request.args.get('q') }}{% endblock %} +{% block title %} - {{ request.args.get('q') }}{% endblock %} {% block body %}