Browse Source

Check for magnet link in 302

Check if url (e.g. Jackett) is redirecting to the magnet link.
pull/7325/head
mrlt8 5 years ago
committed by GitHub
parent
commit
1d13c79c75
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      couchpotato/core/media/_base/providers/torrent/torrentpotato.py

13
couchpotato/core/media/_base/providers/torrent/torrentpotato.py

@ -1,6 +1,7 @@
from urlparse import urlparse from urlparse import urlparse
import re import re
import traceback import traceback
import requests
from couchpotato.core.helpers.encoding import toUnicode from couchpotato.core.helpers.encoding import toUnicode
from couchpotato.core.helpers.variable import splitString, tryInt, tryFloat from couchpotato.core.helpers.variable import splitString, tryInt, tryFloat
@ -42,9 +43,19 @@ class Base(TorrentProvider):
log.error('%s: %s', (torrents.get('error'), host['host'])) log.error('%s: %s', (torrents.get('error'), host['host']))
elif torrents.get('results'): elif torrents.get('results'):
for torrent in torrents.get('results', []): for torrent in torrents.get('results', []):
if re.match('^(http|https|ftp)://.*$', torrent.get('download_url')):
req = requests.get(torrent.get('download_url'), allow_redirects = False)
if req.status_code == 302 and re.match('^magnet:.*$', req.headers["Location"]):
torrent['download_url'] = req.headers["Location"]
proto = "torrent_magnet"
else:
proto = "transmission"
else:
proto = "torrent_magnet"
results.append({ results.append({
'id': torrent.get('torrent_id'), 'id': torrent.get('torrent_id'),
'protocol': 'torrent' if re.match('^(http|https|ftp)://.*$', torrent.get('download_url')) else 'torrent_magnet', 'protocol' : proto,
'provider_extra': urlparse(host['host']).hostname or host['host'], 'provider_extra': urlparse(host['host']).hostname or host['host'],
'name': toUnicode(torrent.get('release_name')), 'name': toUnicode(torrent.get('release_name')),
'url': torrent.get('download_url'), 'url': torrent.get('download_url'),

Loading…
Cancel
Save