Skip to content

Commit

Permalink
Update provider yggtorrent URL and authentification mechanism and add…
Browse files Browse the repository at this point in the history
… env var to override yggtorrent URL (#11838)

* Update yggtorrent.py URL and authentification mechanism

Update yggtorrent.py URL and authentification mechanism

* Allow to change yggtorrent url by overriding it with an environement variable

* Update yggtorrent.py

* Update yggtorrent.py

* Update yggtorrent.py

* Update yggtorrent.py

* Update yggtorrent.py

---------

Co-authored-by: Dario <[email protected]>
  • Loading branch information
StudioEtrange and medariox authored Dec 12, 2024
1 parent 6349562 commit 721a2c8
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions medusa/providers/torrent/html/yggtorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from __future__ import unicode_literals

import json
import logging
import re

Expand All @@ -17,6 +18,9 @@
from medusa.providers.torrent.torrent_provider import TorrentProvider

from requests.compat import urljoin
from requests.utils import dict_from_cookiejar

import validators

log = BraceAdapter(logging.getLogger(__name__))
log.logger.addHandler(logging.NullHandler())
Expand All @@ -36,13 +40,8 @@ def __init__(self):
self.password = None

# URLs
self.url = 'https://yggtorrent.wtf'
self.urls = {
'auth': urljoin(self.url, 'user/ajax_usermenu'),
'login': urljoin(self.url, 'user/login'),
'search': urljoin(self.url, 'engine/search'),
'download': urljoin(self.url, 'engine/download_torrent?id={0}')
}
# Check URL change here : https://yggland.fr/FAQ-Tutos/#status
self.url = 'https://ygg.re'

# Proper Strings
self.proper_strings = ['PROPER', 'REPACK', 'REAL', 'RERIP']
Expand All @@ -53,6 +52,12 @@ def __init__(self):
'Saison {season}', # example: 'Series.Name.Saison 3'
)

# Miscellaneous Options
self.enable_cookies = True
self.cookies = ''
self.required_cookies = ('ygg_',)
self.custom_url = None

# Cache
self.cache = tv.Cache(self, min_time=20)

Expand All @@ -66,6 +71,20 @@ def search(self, search_strings, age=0, ep_obj=None, **kwargs):
:returns: A list of search results (structure)
"""
results = []

if self.custom_url:
if not validators.url(self.custom_url):
log.warning('Invalid custom url: {0}', self.custom_url)
return results
self.url = self.custom_url

self.urls = {
'auth': urljoin(self.url, 'user/ajax_usermenu'),
'login': urljoin(self.url, 'auth/process_login'),
'search': urljoin(self.url, 'engine/search'),
'download': urljoin(self.url, 'engine/download_torrent?id={0}')
}

if not self.login():
return results

Expand Down Expand Up @@ -194,8 +213,22 @@ 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.status_code != 200:
log.debug('Cannot reach account information page')
return False

try:
j = json.loads(response.text)
except Exception:
log.warning('Cannot parse JSON response')
return False
nickname = j.get('nickname')
if nickname is None or nickname == '':
log.warning('Nickname information missing')
return False

return True
Expand Down

0 comments on commit 721a2c8

Please sign in to comment.