From b13f185ddf325104a6fb1dc456204fd118bd2918 Mon Sep 17 00:00:00 2001 From: StudioEtrange Date: Mon, 23 Sep 2024 04:29:57 +0200 Subject: [PATCH 1/2] Update yggtorrent.py URL and authentification mechanism Update yggtorrent.py URL and authentification mechanism --- medusa/providers/torrent/html/yggtorrent.py | 25 ++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/medusa/providers/torrent/html/yggtorrent.py b/medusa/providers/torrent/html/yggtorrent.py index a89cba4d7f..b24daf241a 100644 --- a/medusa/providers/torrent/html/yggtorrent.py +++ b/medusa/providers/torrent/html/yggtorrent.py @@ -6,6 +6,8 @@ import logging import re +import json +from requests.utils import dict_from_cookiejar from medusa import tv from medusa.bs4_parser import BS4Parser @@ -36,10 +38,11 @@ def __init__(self): self.password = None # URLs - self.url = 'https://yggtorrent.wtf' + # check URL change here : https://yggland.fr/FAQ-Tutos/#status + self.url = 'https://ygg.re/' self.urls = { 'auth': urljoin(self.url, 'user/ajax_usermenu'), - 'login': urljoin(self.url, 'user/login'), + 'login': urljoin(self.url, 'auth/process_login'), 'search': urljoin(self.url, 'engine/search'), 'download': urljoin(self.url, 'engine/download_torrent?id={0}') } @@ -56,6 +59,9 @@ def __init__(self): # Cache self.cache = tv.Cache(self, min_time=20) + # Required cookies to check authentification + self.required_cookies=('ygg_',) + def search(self, search_strings, age=0, ep_obj=None, **kwargs): """ Search a provider and parse the results. @@ -194,8 +200,21 @@ def login(self): return True def _is_authenticated(self): + if not any(dict_from_cookiejar(self.session.cookies).values()) or not self.check_required_cookies(): + return False + response = self.session.get(self.urls['auth']) - if not response: + if not response or response is None or not response.status_code == 200: + log.debug("cannot reach account information page") + return False + + try: + j = json.loads(response.text) + except: + return False + nickname = j.get('nickname') + if nickname is None or nickname == '': + log.debug("nickname information missing") return False return True From 92227147f1edf2100266d70e02e96a2cd62ae9e8 Mon Sep 17 00:00:00 2001 From: StudioEtrange Date: Sat, 2 Nov 2024 22:15:14 +0100 Subject: [PATCH 2/2] Allow to change yggtorrent url by overriding it with an environement variable --- medusa/providers/torrent/html/yggtorrent.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/medusa/providers/torrent/html/yggtorrent.py b/medusa/providers/torrent/html/yggtorrent.py index b24daf241a..99d3d0c5ee 100644 --- a/medusa/providers/torrent/html/yggtorrent.py +++ b/medusa/providers/torrent/html/yggtorrent.py @@ -7,6 +7,7 @@ import logging import re import json +import os from requests.utils import dict_from_cookiejar from medusa import tv @@ -39,7 +40,7 @@ def __init__(self): # URLs # check URL change here : https://yggland.fr/FAQ-Tutos/#status - self.url = 'https://ygg.re/' + self.url = os.getenv('MEDUSA_YGGTORRENT_OVERRIDE_URL') or 'https://ygg.re/' self.urls = { 'auth': urljoin(self.url, 'user/ajax_usermenu'), 'login': urljoin(self.url, 'auth/process_login'),