diff --git a/medusa/providers/torrent/torrent_provider.py b/medusa/providers/torrent/torrent_provider.py index cdbfb8727c..87a3495ec7 100644 --- a/medusa/providers/torrent/torrent_provider.py +++ b/medusa/providers/torrent/torrent_provider.py @@ -22,6 +22,8 @@ from medusa.logger.adapters.style import BraceAdapter from medusa.providers.generic_provider import GenericProvider +from requests.exceptions import InvalidSchema + log = BraceAdapter(logging.getLogger(__name__)) log.logger.addHandler(logging.NullHandler()) @@ -149,10 +151,18 @@ def get_redirect_url(self, url): """Get the final address that the provided URL redirects to.""" log.debug('Retrieving redirect URL for {url}', {'url': url}) - response = self.session.get(url, stream=True) - if response: - response.close() - return response.url + try: + 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. + except InvalidSchema: + response = self.session.get(url, allow_redirects=False) + if response and response.headers.get('Location'): + return response.headers['Location'] log.debug('Unable to retrieve redirect URL for {url}', {'url': url}) return url