From 7e23de42780c7474643da2f184141ed9f41470e2 Mon Sep 17 00:00:00 2001 From: bwq Date: Tue, 11 Oct 2011 23:35:35 +0200 Subject: [PATCH] blackhole --- couchpotato/core/downloaders/base.py | 8 ++++++-- .../core/downloaders/blackhole/main.py | 20 ++++++------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/couchpotato/core/downloaders/base.py b/couchpotato/core/downloaders/base.py index b9941c8f..8156af9b 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 +import os log = CPLog(__name__) @@ -16,8 +17,11 @@ class Downloader(Plugin): def download(self, data = {}): pass - def createFileExtension(self, data = {}, content): - pass + def createFileName(self, directory, data = {}, content, movie): + if "DOCTYPE nzb" not in content: + 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')) 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 32afc04f..7afb9056 100644 --- a/couchpotato/core/downloaders/blackhole/main.py +++ b/couchpotato/core/downloaders/blackhole/main.py @@ -10,12 +10,6 @@ class Blackhole(Downloader): type = ['nzb', 'torrent'] - def createFileExtension(self, data = {}, content): - if "DOCTYPE nzb" not in content: - if data.get('type') == 'nzb': - return 'rar' - return data.get('type') - 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')]): @@ -31,12 +25,15 @@ class Blackhole(Downloader): if "no nzb" in file: log.error('No nzb available!') - fileExtension = createFileExtension(data, file) - fullPath = os.path.join(directory, '%s%s.%s' % (toSafeString(data.get('name')), self.cpTag(movie) , fileExtension) + 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 + except: log.error('Failed to download to blackhole %s' % traceback.format_exc()) pass @@ -44,11 +41,6 @@ class Blackhole(Downloader): with open(fullPath, 'wb') as f: f.write(file) except: - log.debug('Failed download file: %s' % data.get('name')) + log.debug('Failed to download file: %s' % data.get('name')) return False - - return True - else: - log.info('File %s already exists.' % fullPath) - return True return False