From eed1bbf256aa180c8f2543460b5a3eb3aa792b63 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sun, 15 Jan 2012 21:56:11 +0100 Subject: [PATCH] Speedup movie scanning x 10 --- couchpotato/core/plugins/scanner/main.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/couchpotato/core/plugins/scanner/main.py b/couchpotato/core/plugins/scanner/main.py index dcd9416..399405f 100644 --- a/couchpotato/core/plugins/scanner/main.py +++ b/couchpotato/core/plugins/scanner/main.py @@ -180,17 +180,37 @@ class Scanner(Plugin): # files will be grouped first. leftovers = set(sorted(leftovers, reverse = True)) - # Create identifiers + + # Group files minus extension for identifier, group in movie_files.iteritems(): if identifier not in group['identifiers'] and len(identifier) > 0: group['identifiers'].append(identifier) - # Group the files based on the identifier + log.debug('Grouping files for: %s' % identifier) + + for file_path in group['unsorted_files']: + wo_ext = file_path[:-(len(getExt(file_path)) + 1)] + found_files = set([i for i in leftovers if wo_ext in i]) + group['unsorted_files'].extend(found_files) + leftovers = leftovers - found_files + + # Break if CP wants to shut down + if self.shuttingDown(): + break + + # Group the files based on the identifier + for identifier, group in movie_files.iteritems(): + log.debug('Grouping files for: %s' % identifier) + found_files = self.getGroupFiles(identifier, folder, leftovers) group['unsorted_files'].extend(found_files) # Remove the found files from the leftover stack leftovers = leftovers - found_files + # Break if CP wants to shut down + if self.shuttingDown(): + break + # Determine file types delete_identifier = [] @@ -490,7 +510,7 @@ class Scanner(Plugin): return False def getGroupFiles(self, identifier, folder, file_pile): - return set(filter(lambda s:identifier in self.createStringIdentifier(s, folder), file_pile)) + return set([i for i in file_pile if identifier in self.createStringIdentifier(i, folder)]) def createStringIdentifier(self, file_path, folder = '', exclude_filename = False):