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."""'Retrieving redirect URL for {}'.format(url))
response = self.session.get(url, stream=True)
if response:
return response.url
# Jackett redirects to a magnet causing InvalidSchema.
# Use an alternative method to get the redirect URL.'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']'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', '', True)
super(YggtorrentProvider, self).__init__('Yggtorrent', '', True)
# URLs
......@@ -155,21 +155,24 @@ class YggtorrentProvider(TorrentProvider):
if not self._is_authenticated():
try:['login'], data=login_params)
except Exception:
resp =['login'], data=login_params)
if not resp:'Unable to connect or login to provider')
return False
if not self._is_authenticated():
if not resp.ok and resp.status_code == 401:'Invalid username or password. Check your settings')
return False
if not self._is_authenticated():'Unable to connect or login to provider')
return False
return True
def _is_authenticated(self):
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