From 91332e06e5f4a3261ca2338539b806e0e8fbd8cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20K=C3=A5berg?= Date: Sun, 29 Sep 2013 01:45:24 +0200 Subject: [PATCH 1/4] add option to create sub directory --- couchpotato/core/downloaders/blackhole/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/couchpotato/core/downloaders/blackhole/__init__.py b/couchpotato/core/downloaders/blackhole/__init__.py index 290e8d43..5de8ac76 100644 --- a/couchpotato/core/downloaders/blackhole/__init__.py +++ b/couchpotato/core/downloaders/blackhole/__init__.py @@ -35,6 +35,13 @@ config = [{ 'type': 'dropdown', 'values': [('usenet & torrents', 'both'), ('usenet', 'nzb'), ('torrent', 'torrent')], }, + { + 'name': 'create_subdir', + 'default': 0, + 'type': 'bool', + 'advanced': True, + 'description': 'Create a sub directory when adding torrent to blackhole.', + }, { 'name': 'manual', 'default': 0, From e38d68c01934316d37311f4d000efaebe4a843d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20K=C3=A5berg?= Date: Sun, 29 Sep 2013 01:45:50 +0200 Subject: [PATCH 2/4] actual code --- couchpotato/core/downloaders/blackhole/main.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/couchpotato/core/downloaders/blackhole/main.py b/couchpotato/core/downloaders/blackhole/main.py index 9a5a6217..e3e070cc 100644 --- a/couchpotato/core/downloaders/blackhole/main.py +++ b/couchpotato/core/downloaders/blackhole/main.py @@ -35,6 +35,15 @@ class Blackhole(Downloader): fullPath = os.path.join(directory, self.createFileName(data, filedata, movie)) + if self.conf('create_subdir'): + try: + new_path = os.path.splitext(fullPath)[0] + if not os.path.exists(new_path): + os.makedirs(new_path) + fullPath = os.path.join(new_path, self.createFileName(data, filedata, movie)) + except: + log.error('Couldnt create sub dir, reverting to old one: %s', fullPath) + try: if not os.path.isfile(fullPath): log.info('Downloading %s to %s.', (data.get('protocol'), fullPath)) From 201185f7e7e6833436be4db51b101944bb32d949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20K=C3=A5berg?= Date: Sun, 29 Sep 2013 01:49:51 +0200 Subject: [PATCH 3/4] better english damnit! --- couchpotato/core/downloaders/blackhole/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/couchpotato/core/downloaders/blackhole/__init__.py b/couchpotato/core/downloaders/blackhole/__init__.py index 5de8ac76..6b5279a1 100644 --- a/couchpotato/core/downloaders/blackhole/__init__.py +++ b/couchpotato/core/downloaders/blackhole/__init__.py @@ -40,7 +40,7 @@ config = [{ 'default': 0, 'type': 'bool', 'advanced': True, - 'description': 'Create a sub directory when adding torrent to blackhole.', + 'description': 'Create a sub directory when saving the .nzb (or .torrent).', }, { 'name': 'manual', From 99c899ea3a22dfa7cedbbbb3bb9629d2d4956c51 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sun, 29 Sep 2013 10:06:12 +0200 Subject: [PATCH 4/4] Proper variable naming --- .../core/downloaders/blackhole/main.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/couchpotato/core/downloaders/blackhole/main.py b/couchpotato/core/downloaders/blackhole/main.py index e3e070cc..854860cd 100644 --- a/couchpotato/core/downloaders/blackhole/main.py +++ b/couchpotato/core/downloaders/blackhole/main.py @@ -33,26 +33,27 @@ class Blackhole(Downloader): log.error('No nzb/torrent available: %s', data.get('url')) return False - fullPath = os.path.join(directory, self.createFileName(data, filedata, movie)) + file_name = self.createFileName(data, filedata, movie) + full_path = os.path.join(directory, file_name) if self.conf('create_subdir'): try: - new_path = os.path.splitext(fullPath)[0] + new_path = os.path.splitext(full_path)[0] if not os.path.exists(new_path): os.makedirs(new_path) - fullPath = os.path.join(new_path, self.createFileName(data, filedata, movie)) + full_path = os.path.join(new_path, file_name) except: - log.error('Couldnt create sub dir, reverting to old one: %s', fullPath) + log.error('Couldnt create sub dir, reverting to old one: %s', full_path) try: - if not os.path.isfile(fullPath): - log.info('Downloading %s to %s.', (data.get('protocol'), fullPath)) - with open(fullPath, 'wb') as f: + if not os.path.isfile(full_path): + log.info('Downloading %s to %s.', (data.get('protocol'), full_path)) + with open(full_path, 'wb') as f: f.write(filedata) - os.chmod(fullPath, Env.getPermission('file')) + os.chmod(full_path, Env.getPermission('file')) return True else: - log.info('File %s already exists.', fullPath) + log.info('File %s already exists.', full_path) return True except: