Blackhole and Sabnzbd support handling rars now (some providers already

use them, might be handy for in the future as well).
This commit is contained in:
bwq committed 2011-10-12 01:06:25 +02:00
1 parent 7e23de4278
commit 5551480703
3 files changed
+32 -27

No files matched your search

+5 -4
View File
@@ -2,6 +2,7 @@ from couchpotato.core.event import addEvent
from couchpotato.core.logger import CPLog 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
from couchpotato.core.helpers.encoding import toSafeString
import os import os
log = CPLog(__name__) log = CPLog(__name__)
@@ -17,11 +18,11 @@ class Downloader(Plugin):
def download(self, data = {}): def download(self, data = {}):
pass pass
def createFileName(self, directory, data = {}, content, movie): def createFileName(self, data, file, movie):
if "DOCTYPE nzb" not in content: if "DOCTYPE nzb" not in file:
if data.get('type') == 'nzb': if data.get('type') == 'nzb':
return os.path.join(directory, '%s%s.%s' % (toSafeString(data.get('name')), self.cpTag(movie) , 'rar') return os.path.join('%s%s.%s' % (toSafeString(data.get('name')), self.cpTag(movie) , 'rar'))
return os.path.join(directory, '%s%s.%s' % (toSafeString(data.get('name')), self.cpTag(movie) , data.get('type')) return os.path.join('%s%s.%s' % (toSafeString(data.get('name')), self.cpTag(movie) , data.get('type')))
def cpTag(self, movie): def cpTag(self, movie):
if Env.setting('enabled', 'renamer'): if Env.setting('enabled', 'renamer'):
+23 -22
View File
@@ -11,36 +11,37 @@ class Blackhole(Downloader):
type = ['nzb', 'torrent'] type = ['nzb', 'torrent']
def download(self, data = {}, movie = {}): def download(self, data = {}, movie = {}):
if self.isDisabled() or not self.isCorrectType(data.get('type') or not self.conf('use_for') in ['both', data.get('type')]): if self.isDisabled() or not self.isCorrectType(data.get('type') or not self.conf('use_for') in ['both', data.get('type')]):
return return
directory = self.conf('directory') directory = self.conf('directory')
if not directory or not os.path.isdir(directory): if not directory or not os.path.isdir(directory):
log.error('No directory set for blackhole %s download.' % data.get('type')) log.error('No directory set for blackhole %s download.' % data.get('type'))
else: else:
try: try:
file = data.get('download')(url = data.get('url'), nzb_id = data.get('id')) file = data.get('download')(url = data.get('url'), nzb_id = data.get('id'))
if "no nzb" in file:
log.error('No nzb available!')
fullPath = self.createFileName(directory, data, file, movie) if "no nzb" in file:
log.error('No nzb available!')
try: return False
if not os.path.isfile(fullPath):
log.info('Downloading %s to %s.' % (data.get('type'), fullPath))
else:
log.info('File %s already exists.' % fullPath)
return True
except: fullPath = os.path.join(directory, self.createFileName(data, file, movie))
log.error('Failed to download to blackhole %s' % traceback.format_exc())
pass
with open(fullPath, 'wb') as f: try:
f.write(file) if not os.path.isfile(fullPath):
except: log.info('Downloading %s to %s.' % (data.get('type'), fullPath))
log.debug('Failed to download file: %s' % data.get('name')) with open(fullPath, 'wb') as f:
return False f.write(file)
return True
else:
log.info('File %s already exists.' % fullPath)
return True
except:
log.error('Failed to download to blackhole %s' % traceback.format_exc())
pass
except:
log.debug('Failed to download file: %s' % data.get('name'))
return False
return False return False
+4 -1
View File
@@ -44,13 +44,16 @@ class Sabnzbd(Downloader):
nzb_file = data.get('download')(url = data.get('url'), nzb_id = data.get('id')) nzb_file = data.get('download')(url = data.get('url'), nzb_id = data.get('id'))
# If it's a .rar, it adds the .rar extension, otherwise it stays .nzb
nzb_filename = self.createFileName(data, nzb_file, movie)
if pp: if pp:
params['script'] = pp_script_fn params['script'] = pp_script_fn
url = cleanHost(self.conf('host')) + "api?" + urlencode(params) url = cleanHost(self.conf('host')) + "api?" + urlencode(params)
try: try:
data = self.urlopen(url, params = {"nzbfile": (params['nzbname'] + ".nzb", nzb_file)}, multipart = True) data = self.urlopen(url, params = {"nzbfile": (nzb_filename, nzb_file)}, multipart = True)
except Exception: except Exception:
log.error("Unable to connect to SAB: %s" % traceback.format_exc()) log.error("Unable to connect to SAB: %s" % traceback.format_exc())
return False return False