Use multiple torrent sources to convert hash. fix #802

This commit is contained in:
Ruud committed 2012-09-08 15:58:41 +02:00
1 parent 89c295b4ad
commit 89426d75ab
1 file changed
+14 -4
+14 -4
View File
@@ -5,15 +5,22 @@ from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin from couchpotato.core.plugins.base import Plugin
from couchpotato.environment import Env from couchpotato.environment import Env
import os import os
import random
import re import re
import traceback
log = CPLog(__name__) log = CPLog(__name__)
class Downloader(Plugin): class Downloader(Plugin):
type = [] type = []
torrent_sources = [
'http://torrage.com/torrent/%s.torrent',
'http://torrage.ws/torrent/%s.torrent',
'http://torcache.net/torrent/%s.torrent',
]
def __init__(self): def __init__(self):
addEvent('download', self.download) addEvent('download', self.download)
addEvent('download.status', self.getDownloadStatus) addEvent('download.status', self.getDownloadStatus)
@@ -55,14 +62,17 @@ class Downloader(Plugin):
if len(torrent_hash) == 32: if len(torrent_hash) == 32:
torrent_hash = b16encode(b32decode(torrent_hash)) torrent_hash = b16encode(b32decode(torrent_hash))
url = 'http://torrage.com/torrent/%s.torrent' % torrent_hash sources = self.torrent_sources
random.shuffle(sources)
for source in sources:
try: try:
filedata = self.urlopen(url) filedata = self.urlopen(source % torrent_hash, show_error = False)
return filedata return filedata
except: except:
log.error('Failed converting magnet url to torrent: %s, %s', (url, traceback.format_exc())) log.debug('Torrent hash "%s" wasn\'t found on: %s', (torrent_hash, source))
log.error('Failed converting magnet url to torrent: %s', (torrent_hash))
return False return False
def isDisabled(self, manual): def isDisabled(self, manual):