Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update provider yggtorrent URL and authentification mechanism and add env var to override yggtorrent URL #11838

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions medusa/providers/torrent/html/yggtorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

import logging
import re
import json
import os
from requests.utils import dict_from_cookiejar

from medusa import tv
from medusa.bs4_parser import BS4Parser
Expand Down Expand Up @@ -36,10 +39,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 = os.getenv('MEDUSA_YGGTORRENT_OVERRIDE_URL') or '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}')
}
Expand All @@ -56,6 +60,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.
Expand Down Expand Up @@ -194,8 +201,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
Expand Down