Magnet link improvements

This commit is contained in:
Ruud
2012-08-26 22:43:00 +02:00
parent 442444a95a
commit d64150d6a7
3 changed files with 28 additions and 4 deletions
+14
View File
@@ -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)
+11 -3
View File
@@ -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))
+3 -1
View File
@@ -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': {}}},