diff --git a/couchpotato/core/downloaders/base.py b/couchpotato/core/downloaders/base.py index d5f1c422..c910edd2 100644 --- a/couchpotato/core/downloaders/base.py +++ b/couchpotato/core/downloaders/base.py @@ -4,6 +4,8 @@ from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin from couchpotato.environment import Env import os +import re +import traceback log = CPLog(__name__) @@ -45,6 +47,18 @@ class Downloader(Plugin): return is_correct + def magnetToTorrent(self, magnet_link): + torrent_hash = re.findall('urn:btih:([\w]{40})', magnet_link)[0] + url = 'http://torrage.com/torrent/%s.torrent' % torrent_hash + + try: + filedata = self.urlopen(url) + return filedata + except: + log.error('Failed converting magnet url to torrent: %s, %s', (url, traceback.format_exc())) + + return False + def isDisabled(self, manual): return not self.isEnabled(manual) diff --git a/couchpotato/core/downloaders/blackhole/main.py b/couchpotato/core/downloaders/blackhole/main.py index a3f03617..4713adf7 100644 --- a/couchpotato/core/downloaders/blackhole/main.py +++ b/couchpotato/core/downloaders/blackhole/main.py @@ -8,7 +8,7 @@ log = CPLog(__name__) class Blackhole(Downloader): - type = ['nzb', 'torrent'] + type = ['nzb', 'torrent', 'torrent_magnet'] def download(self, data = {}, movie = {}, manual = False, filedata = None): if self.isDisabled(manual) or (not self.isCorrectType(data.get('type')) or (not self.conf('use_for') in ['both', data.get('type')])): @@ -20,8 +20,16 @@ class Blackhole(Downloader): else: try: if not filedata or len(filedata) < 50: - log.error('No nzb/torrent available!') - return False + try: + if data.get('type') == 'torrent_magnet': + filedata = self.magnetToTorrent(data.get('url')) + data['type'] = 'torrent' + except: + log.error('Failed download torrent via magnet url: %s', traceback.format_exc()) + + if not filedata or len(filedata) < 50: + log.error('No nzb/torrent available: %s', data.get('url')) + return False fullPath = os.path.join(directory, self.createFileName(data, filedata, movie)) diff --git a/couchpotato/core/plugins/release/main.py b/couchpotato/core/plugins/release/main.py index 0abc065e..9046034c 100644 --- a/couchpotato/core/plugins/release/main.py +++ b/couchpotato/core/plugins/release/main.py @@ -170,7 +170,9 @@ class Release(Plugin): # Get matching provider provider = fireEvent('provider.belongs_to', item['url'], provider = item.get('provider'), single = True) - item['download'] = provider.download + + if item['type'] != 'torrent_magnet': + item['download'] = provider.download success = fireEvent('searcher.download', data = item, movie = rel.movie.to_dict({ 'profile': {'types': {'quality': {}}},