From ad0a1b1efec064f734912a507d3e80f6fce9869d Mon Sep 17 00:00:00 2001 From: Ruud Date: Sun, 14 Oct 2012 20:26:10 +0200 Subject: [PATCH] Pass all the renamed files when adding new release --- couchpotato/core/plugins/manage/main.py | 6 +++--- couchpotato/core/plugins/renamer/main.py | 4 ++-- couchpotato/core/plugins/scanner/main.py | 9 +++++---- couchpotato/core/plugins/trailer/main.py | 2 ++ couchpotato/core/providers/metadata/base.py | 1 + 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/couchpotato/core/plugins/manage/main.py b/couchpotato/core/plugins/manage/main.py index c5f3828..f09a127 100644 --- a/couchpotato/core/plugins/manage/main.py +++ b/couchpotato/core/plugins/manage/main.py @@ -2,7 +2,7 @@ from couchpotato.api import addApiView from couchpotato.core.event import fireEvent, addEvent, fireEventAsync from couchpotato.core.helpers.encoding import ss from couchpotato.core.helpers.request import jsonified, getParam -from couchpotato.core.helpers.variable import getTitle +from couchpotato.core.helpers.variable import getTitle, splitString from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin from couchpotato.environment import Env @@ -26,7 +26,7 @@ class Manage(Plugin): # Add files after renaming def after_rename(message = None, group = {}): return self.scanFilesToLibrary(folder = group['destination_dir'], files = group['renamed_files']) - addEvent('renamer.after', after_rename) + addEvent('renamer.after', after_rename, priority = 110) addApiView('manage.update', self.updateLibraryView, docs = { 'desc': 'Update the library by scanning for new movies', @@ -176,7 +176,7 @@ class Manage(Plugin): def directories(self): try: - return [x.strip() for x in self.conf('library', default = '').split('::')] + return splitString(self.conf('library', default = ''), '::') except: return [] diff --git a/couchpotato/core/plugins/renamer/main.py b/couchpotato/core/plugins/renamer/main.py index 60692a5..670e5d6 100644 --- a/couchpotato/core/plugins/renamer/main.py +++ b/couchpotato/core/plugins/renamer/main.py @@ -50,7 +50,7 @@ class Renamer(Plugin): return if self.renaming_started is True: - log.info('Renamer is disabled to avoid infinite looping of the same error.') + log.info('Renamer is already running, if you see this often, check the logs above for errors.') return # Check to see if the "to" folder is inside the "from" folder. @@ -379,7 +379,7 @@ class Renamer(Plugin): # Notify on download, search for trailers etc download_message = 'Downloaded %s (%s)' % (movie_title, replacements['quality']) - fireEventAsync('renamer.after', message = download_message, group = group) + fireEvent('renamer.after', message = download_message, group = group, in_order = True) # Break if CP wants to shut down if self.shuttingDown(): diff --git a/couchpotato/core/plugins/scanner/main.py b/couchpotato/core/plugins/scanner/main.py index a25a31c..d83d87d 100644 --- a/couchpotato/core/plugins/scanner/main.py +++ b/couchpotato/core/plugins/scanner/main.py @@ -86,7 +86,7 @@ class Scanner(Plugin): addEvent('scanner.name_year', self.getReleaseNameYear) addEvent('scanner.partnumber', self.getPartNumber) - def scan(self, folder = None, files = [], simple = False, newer_than = 0, on_found = None): + def scan(self, folder = None, files = None, simple = False, newer_than = 0, on_found = None): folder = ss(os.path.normpath(folder)) @@ -99,7 +99,8 @@ class Scanner(Plugin): leftovers = [] # Scan all files of the folder if no files are set - if len(files) == 0: + if not files: + check_file_date = True try: files = [] for root, dirs, walk_files in os.walk(folder): @@ -108,6 +109,7 @@ class Scanner(Plugin): except: log.error('Failed getting files from %s: %s', (folder, traceback.format_exc())) else: + check_file_date = False files = [ss(x) for x in files] db = get_session() @@ -237,7 +239,6 @@ class Scanner(Plugin): del path_identifiers[identifier] del delete_identifiers - # Make sure we remove older / still extracting files valid_files = {} while True and not self.shuttingDown(): @@ -261,7 +262,7 @@ class Scanner(Plugin): if file_too_new: break - if file_too_new: + if check_file_date and file_too_new: try: time_string = time.ctime(file_time[0]) except: diff --git a/couchpotato/core/plugins/trailer/main.py b/couchpotato/core/plugins/trailer/main.py index 8b9f1e1..9a32265 100644 --- a/couchpotato/core/plugins/trailer/main.py +++ b/couchpotato/core/plugins/trailer/main.py @@ -28,6 +28,8 @@ class Trailer(Plugin): else: log.debug('Trailer already exists: %s', destination) + group['renamed_files'].append(destination) + # Download first and break break diff --git a/couchpotato/core/providers/metadata/base.py b/couchpotato/core/providers/metadata/base.py index 078d7e1..d37ff78 100644 --- a/couchpotato/core/providers/metadata/base.py +++ b/couchpotato/core/providers/metadata/base.py @@ -49,6 +49,7 @@ class MetaDataBase(Plugin): shutil.copy2(content, name) else: self.createFile(name, content) + group['renamed_files'].append(name) except: log.error('Unable to create %s file: %s', (file_type, traceback.format_exc()))