diff --git a/couchpotato/core/downloaders/base.py b/couchpotato/core/downloaders/base.py index 8156af9b..3b139e45 100644 --- a/couchpotato/core/downloaders/base.py +++ b/couchpotato/core/downloaders/base.py @@ -2,6 +2,7 @@ from couchpotato.core.event import addEvent from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin from couchpotato.environment import Env +from couchpotato.core.helpers.encoding import toSafeString import os log = CPLog(__name__) @@ -17,11 +18,11 @@ class Downloader(Plugin): def download(self, data = {}): pass - def createFileName(self, directory, data = {}, content, movie): - if "DOCTYPE nzb" not in content: + def createFileName(self, data, file, movie): + if "DOCTYPE nzb" not in file: 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(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) , 'rar')) + return os.path.join('%s%s.%s' % (toSafeString(data.get('name')), self.cpTag(movie) , data.get('type'))) def cpTag(self, movie): if Env.setting('enabled', 'renamer'): diff --git a/couchpotato/core/downloaders/blackhole/main.py b/couchpotato/core/downloaders/blackhole/main.py index 7afb9056..ebb97fd3 100644 --- a/couchpotato/core/downloaders/blackhole/main.py +++ b/couchpotato/core/downloaders/blackhole/main.py @@ -11,36 +11,37 @@ class Blackhole(Downloader): type = ['nzb', 'torrent'] 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')]): return directory = self.conf('directory') - if not directory or not os.path.isdir(directory): log.error('No directory set for blackhole %s download.' % data.get('type')) else: - try: - file = data.get('download')(url = data.get('url'), nzb_id = data.get('id')) - if "no nzb" in file: - log.error('No nzb available!') + try: + file = data.get('download')(url = data.get('url'), nzb_id = data.get('id')) - fullPath = self.createFileName(directory, data, file, movie) - - try: - 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 + if "no nzb" in file: + log.error('No nzb available!') + return False - except: - log.error('Failed to download to blackhole %s' % traceback.format_exc()) - pass + fullPath = os.path.join(directory, self.createFileName(data, file, movie)) - with open(fullPath, 'wb') as f: - f.write(file) - except: - log.debug('Failed to download file: %s' % data.get('name')) - return False + try: + if not os.path.isfile(fullPath): + log.info('Downloading %s to %s.' % (data.get('type'), fullPath)) + with open(fullPath, 'wb') as f: + 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 diff --git a/couchpotato/core/downloaders/sabnzbd/main.py b/couchpotato/core/downloaders/sabnzbd/main.py index 8d56a8fa..e07d3f43 100644 --- a/couchpotato/core/downloaders/sabnzbd/main.py +++ b/couchpotato/core/downloaders/sabnzbd/main.py @@ -44,13 +44,16 @@ class Sabnzbd(Downloader): 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: params['script'] = pp_script_fn url = cleanHost(self.conf('host')) + "api?" + urlencode(params) 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: log.error("Unable to connect to SAB: %s" % traceback.format_exc()) return False