Commit 07836086 authored by echel0n's avatar echel0n

Added function to get redirect url for torrent providers that frequently change their urls

Fixed login issues for YGGTorrents torrent provider
parent d615ca6c
......@@ -106,6 +106,25 @@ class GenericProvider(object):
def urls(self):
return self._urls
def get_redirect_url(self, url):
"""Get the final address that the provided URL redirects to."""
sickrage.app.log.debug('Retrieving redirect URL for {}'.format(url))
response = self.session.get(url, stream=True)
if response:
response.close()
return response.url
# Jackett redirects to a magnet causing InvalidSchema.
# Use an alternative method to get the redirect URL.
sickrage.app.log.debug('Using alternative method to retrieve redirect URL')
response = self.session.get(url, allow_redirects=False)
if response and response.headers.get('Location'):
return response.headers['Location']
sickrage.app.log.debug('Unable to retrieve redirect URL for {}'.format(url))
return url
def _check_auth(self):
return True
......
......@@ -30,7 +30,7 @@ from sickrage.providers import TorrentProvider
class YggtorrentProvider(TorrentProvider):
def __init__(self):
"""Initialize the class."""
super(YggtorrentProvider, self).__init__('Yggtorrent', 'https://www2.yggtorrent.se', True)
super(YggtorrentProvider, self).__init__('Yggtorrent', 'https://www2.yggtorrent.si', True)
# URLs
self._urls.update({
......@@ -155,21 +155,24 @@ class YggtorrentProvider(TorrentProvider):
}
if not self._is_authenticated():
try:
self.session.post(self.urls['login'], data=login_params)
except Exception:
resp = self.session.post(self.urls['login'], data=login_params)
if not resp:
sickrage.app.log.warning('Unable to connect or login to provider')
return False
if not self._is_authenticated():
if not resp.ok and resp.status_code == 401:
sickrage.app.log.warning('Invalid username or password. Check your settings')
return False
if not self._is_authenticated():
sickrage.app.log.warning('Unable to connect or login to provider')
return False
return True
def _is_authenticated(self):
try:
self.session.get(self.urls['auth']).json()
self.session.get(self.urls['auth'], params={'attempt': 1}).json()
except Exception:
return False
return True
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment