From 185a530b591bdcfcd5a0343be98638c69efefae7 Mon Sep 17 00:00:00 2001 From: mano3m <-> Date: Sat, 13 Apr 2013 12:45:47 +0200 Subject: [PATCH 1/4] only link for torrents not nzbs --- couchpotato/core/downloaders/base.py | 7 +++++++ couchpotato/core/plugins/renamer/__init__.py | 4 ++-- couchpotato/core/plugins/renamer/main.py | 13 ++++++++----- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/couchpotato/core/downloaders/base.py b/couchpotato/core/downloaders/base.py index 8ccc1369..a78e0b18 100644 --- a/couchpotato/core/downloaders/base.py +++ b/couchpotato/core/downloaders/base.py @@ -39,6 +39,13 @@ class Downloader(Provider): addEvent('download.enabled_types', self.getEnabledDownloadType) addEvent('download.status', self._getAllDownloadStatus) addEvent('download.remove_failed', self._removeFailed) + addEvent('download.downloader_type', self.getDownloaderType) + + def getDownloaderType(self, downloader): + if self.getName() == downloader: + return self.type + + return [] def getEnabledDownloadType(self): for download_type in self.type: diff --git a/couchpotato/core/plugins/renamer/__init__.py b/couchpotato/core/plugins/renamer/__init__.py index 90f5c980..f3f7f66c 100644 --- a/couchpotato/core/plugins/renamer/__init__.py +++ b/couchpotato/core/plugins/renamer/__init__.py @@ -114,11 +114,11 @@ config = [{ }, { 'name': 'file_action', - 'label': 'File Action', + 'label': 'Torrent File Action', 'default': 'move', 'type': 'dropdown', 'values': [('Move', 'move'), ('Copy', 'copy'), ('Hard link', 'hardlink'), ('Sym link', 'symlink'), ('Move & Sym link', 'move_symlink')], - 'description': 'Define which kind of file operation you want to use. Before you start using hard links or sym links, PLEASE read about their possible drawbacks.', + 'description': 'Define which kind of file operation you want to use for torrents. Before you start using hard links or sym links, PLEASE read about their possible drawbacks.', 'advanced': True, }, { diff --git a/couchpotato/core/plugins/renamer/main.py b/couchpotato/core/plugins/renamer/main.py index 87d9aaf3..807ee04c 100644 --- a/couchpotato/core/plugins/renamer/main.py +++ b/couchpotato/core/plugins/renamer/main.py @@ -118,7 +118,7 @@ class Renamer(Plugin): db = get_session() - # Get the release with the downloader ID that was downloded by the downloader + # Get the release with the downloader ID that was downloaded by the downloader download_info = None if download_id and downloader: rls = None @@ -137,6 +137,7 @@ class Renamer(Plugin): download_info = { 'imdb_id': rls.movie.library.identifier, 'quality': rls.quality.identifier, + 'is_torrent': any(downloader_type in fireEvent('download.downloader_type', downloader = downloader) for downloader_type in ['torrent', 'torrent_magnet']) } else: log.error('Download ID %s from downloader %s not found in releases', (download_id, downloader)) @@ -446,13 +447,13 @@ class Renamer(Plugin): self.makeDir(os.path.dirname(dst)) try: - self.moveFile(src, dst) + self.moveFile(src, dst, forcemove = not (download_info and download_info.get('is_torrent'))) group['renamed_files'].append(dst) except: log.error('Failed moving the file "%s" : %s', (os.path.basename(src), traceback.format_exc())) self.tagDir(group, 'failed_rename') - if self.conf('file_action') != 'move': + if self.conf('file_action') != 'move' and download_info and download_info.get('is_torrent'): self.tagDir(group, 'renamed already') # Remove matching releases @@ -518,10 +519,12 @@ Remove it if you want it to be renamed (again, or at least let it try again) self.createFile(ignore_file, text) - def moveFile(self, old, dest): + def moveFile(self, old, dest, forcemove = False): dest = ss(dest) try: - if self.conf('file_action') == 'hardlink': + if forcemove: + shutil.move(old, dest) + elif self.conf('file_action') == 'hardlink': link(old, dest) elif self.conf('file_action') == 'symlink': symlink(old, dest) From 2979a8edecb786330a135b13f58c4cbb8e4109b1 Mon Sep 17 00:00:00 2001 From: mano3m <-> Date: Fri, 19 Apr 2013 21:22:29 +0200 Subject: [PATCH 2/4] Cleanup --- couchpotato/core/plugins/renamer/main.py | 65 ++++++++++++++---------- 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/couchpotato/core/plugins/renamer/main.py b/couchpotato/core/plugins/renamer/main.py index 807ee04c..a8b39c7f 100644 --- a/couchpotato/core/plugins/renamer/main.py +++ b/couchpotato/core/plugins/renamer/main.py @@ -103,7 +103,7 @@ class Renamer(Plugin): # make sure the movie folder name is included in the search folder = None - movie_files = [] + files = [] if movie_folder: log.info('Scanning movie folder %s...', movie_folder) movie_folder = movie_folder.rstrip(os.path.sep) @@ -112,38 +112,17 @@ class Renamer(Plugin): # Get all files from the specified folder try: for root, folders, names in os.walk(movie_folder): - movie_files.extend([os.path.join(root, name) for name in names]) + files.extend([os.path.join(root, name) for name in names]) except: log.error('Failed getting files from %s: %s', (movie_folder, traceback.format_exc())) db = get_session() - # Get the release with the downloader ID that was downloaded by the downloader - download_info = None - if download_id and downloader: - rls = None - - rlsnfo_dwnlds = db.query(ReleaseInfo).filter_by(identifier = 'download_downloader', value = downloader).all() - rlsnfo_ids = db.query(ReleaseInfo).filter_by(identifier = 'download_id', value = download_id).all() - - for rlsnfo_dwnld in rlsnfo_dwnlds: - for rlsnfo_id in rlsnfo_ids: - if rlsnfo_id.release == rlsnfo_dwnld.release: - rls = rlsnfo_id.release - break - if rls: break - - if rls: - download_info = { - 'imdb_id': rls.movie.library.identifier, - 'quality': rls.quality.identifier, - 'is_torrent': any(downloader_type in fireEvent('download.downloader_type', downloader = downloader) for downloader_type in ['torrent', 'torrent_magnet']) - } - else: - log.error('Download ID %s from downloader %s not found in releases', (download_id, downloader)) + # Get the download info stored in the downloaded release + download_info = getDownloadInfo(download_id = download_id, downloader = downloader) groups = fireEvent('scanner.scan', folder = folder if folder else self.conf('from'), - files = movie_files, download_info = download_info, return_ignored = False, single = True) + files = files, download_info = download_info, return_ignored = False, single = True) destination = self.conf('to') folder_name = self.conf('folder_name') @@ -678,7 +657,7 @@ Remove it if you want it to be renamed (again, or at least let it try again) elif item['status'] == 'completed': log.info('Download of %s completed!', item['name']) if item['id'] and item['downloader'] and item['folder']: - fireEventAsync('renamer.scan', movie_folder = item['folder'], downloader = item['downloader'], download_id = item['id']) + fireEvent('renamer.scan', movie_folder = item['folder'], downloader = item['downloader'], download_id = item['id']) else: scan_required = True @@ -697,3 +676,35 @@ Remove it if you want it to be renamed (again, or at least let it try again) self.checking_snatched = False return True + +def getDownloadInfo(self, download_id, downloader): + + rls = None + download_info = None + + if download_id and downloader: + + db = get_session() + + rlsnfo_dwnlds = db.query(ReleaseInfo).filter_by(identifier = 'download_downloader', value = downloader).all() + rlsnfo_ids = db.query(ReleaseInfo).filter_by(identifier = 'download_id', value = download_id).all() + + for rlsnfo_dwnld in rlsnfo_dwnlds: + for rlsnfo_id in rlsnfo_ids: + if rlsnfo_id.release == rlsnfo_dwnld.release: + rls = rlsnfo_id.release + break + if rls: break + + if not rls: + log.error('Download ID %s from downloader %s not found in releases', (download_id, downloader)) + + if rls: + download_info = { + 'imdb_id': rls.movie.library.identifier, + 'quality': rls.quality.identifier, + 'is_torrent': any(downloader_type in fireEvent('download.downloader_type', downloader = downloader) for downloader_type in ['torrent', 'torrent_magnet']) + } + + return download_info + From b85942989dcd69e5ed8a3c4a9b38edd9081c89de Mon Sep 17 00:00:00 2001 From: mano3m <-> Date: Sun, 21 Apr 2013 23:46:21 +0200 Subject: [PATCH 3/4] Standardise failed status apply the failed status in case of a manual re-add and automatic try next release --- couchpotato/core/plugins/renamer/main.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/couchpotato/core/plugins/renamer/main.py b/couchpotato/core/plugins/renamer/main.py index a8b39c7f..47080cbc 100644 --- a/couchpotato/core/plugins/renamer/main.py +++ b/couchpotato/core/plugins/renamer/main.py @@ -647,13 +647,12 @@ Remove it if you want it to be renamed (again, or at least let it try again) pass elif item['status'] == 'failed': fireEvent('download.remove_failed', item, single = True) + rel.status_id = failed_status.get('id') + rel.last_edit = int(time.time()) + db.commit() if self.conf('next_on_failed'): fireEvent('searcher.try_next_release', movie_id = rel.movie_id) - else: - rel.status_id = failed_status.get('id') - rel.last_edit = int(time.time()) - db.commit() elif item['status'] == 'completed': log.info('Download of %s completed!', item['name']) if item['id'] and item['downloader'] and item['folder']: From 6ee68d1418204f5d504578226ee9ea42272cedc6 Mon Sep 17 00:00:00 2001 From: mano3m <-> Date: Fri, 26 Apr 2013 19:34:15 +0200 Subject: [PATCH 4/4] Fix getDownloadInfo --- couchpotato/core/plugins/renamer/main.py | 67 ++++++++++++------------ 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/couchpotato/core/plugins/renamer/main.py b/couchpotato/core/plugins/renamer/main.py index 47080cbc..a84f36e3 100644 --- a/couchpotato/core/plugins/renamer/main.py +++ b/couchpotato/core/plugins/renamer/main.py @@ -119,7 +119,7 @@ class Renamer(Plugin): db = get_session() # Get the download info stored in the downloaded release - download_info = getDownloadInfo(download_id = download_id, downloader = downloader) + download_info = self.getDownloadInfo(download_id = download_id, downloader = downloader) groups = fireEvent('scanner.scan', folder = folder if folder else self.conf('from'), files = files, download_info = download_info, return_ignored = False, single = True) @@ -355,7 +355,7 @@ class Renamer(Plugin): else: log.info('Better quality release already exists for %s, with quality %s', (movie.library.titles[0].title, release.quality.label)) - # Add _EXISTS_ to the parent dir + # Add exists tag to the .ignore file self.tagDir(group, 'exists') # Notify on rename fail @@ -376,7 +376,8 @@ class Renamer(Plugin): db.commit() # Remove leftover files - if self.conf('cleanup') and not self.conf('move_leftover') and remove_leftovers: + if self.conf('cleanup') and not self.conf('move_leftover') and remove_leftovers and \ + not (self.conf('file_action') != 'move' and download_info and download_info.get('is_torrent')): log.debug('Removing leftover files') for current_file in group['files']['leftover']: remove_files.append(current_file) @@ -676,34 +677,34 @@ Remove it if you want it to be renamed (again, or at least let it try again) return True -def getDownloadInfo(self, download_id, downloader): - - rls = None - download_info = None - - if download_id and downloader: - - db = get_session() - - rlsnfo_dwnlds = db.query(ReleaseInfo).filter_by(identifier = 'download_downloader', value = downloader).all() - rlsnfo_ids = db.query(ReleaseInfo).filter_by(identifier = 'download_id', value = download_id).all() - - for rlsnfo_dwnld in rlsnfo_dwnlds: - for rlsnfo_id in rlsnfo_ids: - if rlsnfo_id.release == rlsnfo_dwnld.release: - rls = rlsnfo_id.release - break - if rls: break - - if not rls: - log.error('Download ID %s from downloader %s not found in releases', (download_id, downloader)) - - if rls: - download_info = { - 'imdb_id': rls.movie.library.identifier, - 'quality': rls.quality.identifier, - 'is_torrent': any(downloader_type in fireEvent('download.downloader_type', downloader = downloader) for downloader_type in ['torrent', 'torrent_magnet']) - } - - return download_info + def getDownloadInfo(self, download_id, downloader): + + rls = None + download_info = None + + if download_id and downloader: + + db = get_session() + + rlsnfo_dwnlds = db.query(ReleaseInfo).filter_by(identifier = 'download_downloader', value = downloader).all() + rlsnfo_ids = db.query(ReleaseInfo).filter_by(identifier = 'download_id', value = download_id).all() + + for rlsnfo_dwnld in rlsnfo_dwnlds: + for rlsnfo_id in rlsnfo_ids: + if rlsnfo_id.release == rlsnfo_dwnld.release: + rls = rlsnfo_id.release + break + if rls: break + + if not rls: + log.error('Download ID %s from downloader %s not found in releases', (download_id, downloader)) + + if rls: + download_info = { + 'imdb_id': rls.movie.library.identifier, + 'quality': rls.quality.identifier, + 'is_torrent': any(downloader_type in fireEvent('download.downloader_type', downloader = downloader) for downloader_type in ['torrent', 'torrent_magnet']) + } + + return download_info