Skip to content

Commit

Permalink
Use alternative method to get the redirect URL for Jackett. Fixes #6826
Browse files Browse the repository at this point in the history
… (#6827)

* Use alternative method to get the redirect URL for Jackett. Fixes #6826

* Update CHANGELOG.md
  • Loading branch information
medariox authored Jun 13, 2019
1 parent ab27e5d commit 339ade0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#### Improvements

#### Fixes
- Fixed Jackett providers returning empty torrents on magnet redirect (2) ([#6827](https://github.com/pymedusa/Medusa/pull/6827))

-----

Expand Down
19 changes: 8 additions & 11 deletions medusa/providers/torrent/torrent_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
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 @@ -151,18 +149,17 @@ 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})

try:
response = self.session.get(url, stream=True)
if response:
response.close()
return response.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.
except InvalidSchema:
response = self.session.get(url, allow_redirects=False)
if response and response.headers.get('Location'):
return response.headers['Location']
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']

log.debug('Unable to retrieve redirect URL for {url}', {'url': url})
return url
Expand Down

0 comments on commit 339ade0

Please sign in to comment.