Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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