From 8a252bff64b2bb2d376673a0b00e9624d44aaf4c Mon Sep 17 00:00:00 2001 From: Ruud Date: Sun, 7 Jul 2013 13:00:38 +0200 Subject: [PATCH] Don't use parentdir for tagging --- couchpotato/core/downloaders/base.py | 6 +++-- couchpotato/core/downloaders/sabnzbd/__init__.py | 2 +- .../core/downloaders/transmission/__init__.py | 4 +-- couchpotato/core/downloaders/transmission/main.py | 13 ++++++---- couchpotato/core/downloaders/utorrent/__init__.py | 4 +-- couchpotato/core/downloaders/utorrent/main.py | 20 +++++++-------- couchpotato/core/plugins/renamer/main.py | 30 ++++++++++++++-------- 7 files changed, 47 insertions(+), 32 deletions(-) diff --git a/couchpotato/core/downloaders/base.py b/couchpotato/core/downloaders/base.py index adbfb7e..5e6db0e 100644 --- a/couchpotato/core/downloaders/base.py +++ b/couchpotato/core/downloaders/base.py @@ -86,7 +86,8 @@ class Downloader(Provider): return self.processComplete(item = item, delete_files = self.conf('delete_files', default = False)) return False - return + + return False def processComplete(self, item, delete_files): return @@ -149,7 +150,8 @@ class Downloader(Provider): if item and item.get('downloader') == self.getName(): self.pause(item, pause) return True - return + + return False def pause(self, item, pause): return diff --git a/couchpotato/core/downloaders/sabnzbd/__init__.py b/couchpotato/core/downloaders/sabnzbd/__init__.py index 8e132b7..781141e 100644 --- a/couchpotato/core/downloaders/sabnzbd/__init__.py +++ b/couchpotato/core/downloaders/sabnzbd/__init__.py @@ -47,7 +47,7 @@ config = [{ 'default': True, 'type': 'bool', 'description': 'Remove the NZB from history after it completed.', - }, + }, { 'name': 'delete_failed', 'default': True, diff --git a/couchpotato/core/downloaders/transmission/__init__.py b/couchpotato/core/downloaders/transmission/__init__.py index bca7eae..11528f3 100644 --- a/couchpotato/core/downloaders/transmission/__init__.py +++ b/couchpotato/core/downloaders/transmission/__init__.py @@ -49,14 +49,14 @@ config = [{ 'default': True, 'type': 'bool', 'description': '(Hard)link/copy after download is complete (if enabled in renamer), wait for seeding to finish before (re)moving and set the seeding goal from the torrent providers.', - }, + }, { 'name': 'remove_complete', 'label': 'Remove torrent', 'default': True, 'type': 'bool', 'description': 'Remove the torrent from Transmission after it finished seeding.', - }, + }, { 'name': 'delete_files', 'label': 'Remove files', diff --git a/couchpotato/core/downloaders/transmission/main.py b/couchpotato/core/downloaders/transmission/main.py index 46b9541..653343b 100644 --- a/couchpotato/core/downloaders/transmission/main.py +++ b/couchpotato/core/downloaders/transmission/main.py @@ -19,15 +19,17 @@ class Transmission(Downloader): type = ['torrent', 'torrent_magnet'] log = CPLog(__name__) trpc = None - + def connect(self): # Load host from config and split out port. host = self.conf('host').split(':') if not isInt(host[1]): log.error('Config properties are not filled in correctly, port is missing.') return False + if not self.trpc: self.trpc = TransmissionRPC(host[0], port = host[1], username = self.conf('username'), password = self.conf('password')) + return self.trpc def download(self, data, movie, filedata = None): @@ -58,7 +60,7 @@ class Transmission(Downloader): torrent_params['seedRatioMode'] = 1 if data.get('seed_time') and self.conf('seeding'): - torrent_params['seedIdleLimit'] = tryInt(data.get('seed_time'))*60 + torrent_params['seedIdleLimit'] = tryInt(data.get('seed_time')) * 60 torrent_params['seedIdleMode'] = 1 # Send request to Transmission @@ -89,8 +91,8 @@ class Transmission(Downloader): statuses = StatusList(self) return_params = { - 'fields': ['id', 'name', 'hashString', 'percentDone', 'status', 'eta', 'isStalled', 'isFinished', 'downloadDir', 'uploadRatio', 'secondsSeeding', 'seedIdleLimit'] - } + 'fields': ['id', 'name', 'hashString', 'percentDone', 'status', 'eta', 'isStalled', 'isFinished', 'downloadDir', 'uploadRatio', 'secondsSeeding', 'seedIdleLimit'] + } queue = self.trpc.get_alltorrents(return_params) if not (queue and queue.get('torrents')): @@ -98,7 +100,8 @@ class Transmission(Downloader): return False for item in queue['torrents']: - log.debug('name=%s / id=%s / downloadDir=%s / hashString=%s / percentDone=%s / status=%s / eta=%s / uploadRatio=%s / isFinished=%s', (item['name'], item['id'], item['downloadDir'], item['hashString'], item['percentDone'], item['status'], item['eta'], item['uploadRatio'], item['isFinished'])) + log.debug('name=%s / id=%s / downloadDir=%s / hashString=%s / percentDone=%s / status=%s / eta=%s / uploadRatio=%s / isFinished=%s', + (item['name'], item['id'], item['downloadDir'], item['hashString'], item['percentDone'], item['status'], item['eta'], item['uploadRatio'], item['isFinished'])) if not os.path.isdir(Env.setting('from', 'renamer')): log.error('Renamer "from" folder doesn\'t to exist.') diff --git a/couchpotato/core/downloaders/utorrent/__init__.py b/couchpotato/core/downloaders/utorrent/__init__.py index f2fcc13..025eb9a 100644 --- a/couchpotato/core/downloaders/utorrent/__init__.py +++ b/couchpotato/core/downloaders/utorrent/__init__.py @@ -42,14 +42,14 @@ config = [{ 'default': True, 'type': 'bool', 'description': '(Hard)links/copies after download is complete (if enabled in renamer), wait for seeding to finish before (re)moving.', - }, + }, { 'name': 'remove_complete', 'label': 'Remove torrent', 'default': True, 'type': 'bool', 'description': 'Remove the torrent from uTorrent after it finished seeding.', - }, + }, { 'name': 'delete_files', 'label': 'Remove files', diff --git a/couchpotato/core/downloaders/utorrent/main.py b/couchpotato/core/downloaders/utorrent/main.py index 738fbad..5a76654 100644 --- a/couchpotato/core/downloaders/utorrent/main.py +++ b/couchpotato/core/downloaders/utorrent/main.py @@ -76,11 +76,11 @@ class uTorrent(Downloader): if data.get('seed_ratio') and self.conf('seeding'): torrent_params['seed_override'] = 1 - torrent_params['seed_ratio'] = tryInt(tryFloat(data['seed_ratio'])*1000) + torrent_params['seed_ratio'] = tryInt(tryFloat(data['seed_ratio']) * 1000) if data.get('seed_time') and self.conf('seeding'): torrent_params['seed_override'] = 1 - torrent_params['seed_time'] = tryInt(data['seed_time'])*3600 + torrent_params['seed_time'] = tryInt(data['seed_time']) * 3600 # Convert base 32 to hex if len(torrent_hash) == 32: @@ -139,7 +139,7 @@ class uTorrent(Downloader): 'id': item[0], 'name': item[2], 'status': status, - 'seed_ratio': float(item[7])/1000, + 'seed_ratio': float(item[7]) / 1000, 'original_status': item[1], 'timeleft': str(timedelta(seconds = item[10])), 'folder': item[26], @@ -228,16 +228,16 @@ class uTorrentAPI(object): action = "action=unpause&hash=%s" % hash return self._request(action) - def stop_torrent(self, hash): - action = "action=stop&hash=%s" % hash - return self._request(action) + def stop_torrent(self, hash): + action = "action=stop&hash=%s" % hash + return self._request(action) - def remove_torrent(self, hash, remove_data = False): + def remove_torrent(self, hash, remove_data = False): if remove_data: action = "action=removedata&hash=%s" % hash else: - action = "action=remove&hash=%s" % hash - return self._request(action) + action = "action=remove&hash=%s" % hash + return self._request(action) def get_status(self): action = "list=1" @@ -270,5 +270,5 @@ class uTorrentAPI(object): if isinstance(settings_dict[key], bool): settings_dict[key] = 1 if settings_dict[key] else 0 - action = 'action=setsetting' + ''.join(['&s=%s&v=%s' % (key, value) for (key, value) in settings_dict.items()]) + action = 'action=setsetting' + ''.join(['&s=%s&v=%s' % (key, value) for (key, value) in settings_dict.items()]) return self._request(action) diff --git a/couchpotato/core/plugins/renamer/main.py b/couchpotato/core/plugins/renamer/main.py index 1070e4d..119e5d4 100644 --- a/couchpotato/core/plugins/renamer/main.py +++ b/couchpotato/core/plugins/renamer/main.py @@ -151,7 +151,7 @@ class Renamer(Plugin): # Add _UNKNOWN_ if no library item is connected if not group['library'] or not movie_title: - self.tagDir(group['parentdir'], 'unknown') + self.tagDir(group, 'unknown') continue # Rename the files using the library data else: @@ -361,7 +361,7 @@ class Renamer(Plugin): log.info('Better quality release already exists for %s, with quality %s', (movie.library.titles[0].title, release.quality.label)) # Add exists tag to the .ignore file - self.tagDir(group['parentdir'], 'exists') + self.tagDir(group, 'exists') # Notify on rename fail download_message = 'Renaming of %s (%s) canceled, exists in %s already.' % (movie.library.titles[0].title, group['meta_data']['quality']['label'], release.quality.label) @@ -412,7 +412,7 @@ class Renamer(Plugin): except: log.error('Failed removing %s: %s', (src, traceback.format_exc())) - self.tagDir(group['parentdir'], 'failed_remove') + self.tagDir(group, 'failed_remove') # Delete leftover folder from older releases for delete_folder in delete_folders: @@ -436,12 +436,12 @@ class Renamer(Plugin): group['renamed_files'].append(dst) except: log.error('Failed moving the file "%s" : %s', (os.path.basename(src), traceback.format_exc())) - self.tagDir(group['parentdir'], 'failed_rename') + self.tagDir(group, 'failed_rename') # Tag folder if it is in the 'from' folder and it will not be removed because it is a torrent if (movie_folder and self.conf('from') in movie_folder or not movie_folder) and \ self.conf('file_action') != 'move' and self.downloadIsTorrent(download_info): - self.tagDir(group['parentdir'], 'renamed_already') + self.tagDir(group, 'renamed_already') # Remove matching releases for release in remove_releases: @@ -489,9 +489,18 @@ class Renamer(Plugin): return rename_files # This adds a file to ignore / tag a release so it is ignored later - def tagDir(self, folder, tag): - if not os.path.isdir(folder) or not tag: - return + def tagDir(self, group, tag): + + ignore_file = None + if isinstance(group, (dict)): + for movie_file in sorted(list(group['files']['movie'])): + ignore_file = '%s.%s.ignore' % (os.path.splitext(movie_file)[0], tag) + break + else: + if not os.path.isdir(group) or not tag: + return + ignore_file = os.path.join(group, '%s.ignore' % tag) + text = """This file is from CouchPotato It has marked this release as "%s" @@ -499,7 +508,8 @@ This file hides the release from the renamer Remove it if you want it to be renamed (again, or at least let it try again) """ % tag - self.createFile(os.path.join(folder, '%s.ignore' % tag), text) + if ignore_file: + self.createFile(ignore_file, text) def untagDir(self, folder, tag = None): if not os.path.isdir(folder): @@ -808,4 +818,4 @@ Remove it if you want it to be renamed (again, or at least let it try again) if not group['files'].get('added'): return False return src in group['files']['added'] - +