Skip to content

Commit

Permalink
Use old method to get the redirect URL for Jackett. Fixes #6788 (#6790)
Browse files Browse the repository at this point in the history
* Use old method to get the redirect URL for Jackett. Fixes #6788

* self.session
  • Loading branch information
medariox authored Jun 7, 2019
1 parent 0a45848 commit bb51d2c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions medusa/providers/torrent/torrent_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bb51d2c

Please sign in to comment.