diff --git a/couchpotato/core/event.py b/couchpotato/core/event.py index edab2139..46b76187 100644 --- a/couchpotato/core/event.py +++ b/couchpotato/core/event.py @@ -7,6 +7,11 @@ import traceback log = CPLog(__name__) events = {} +def runHandler(name, handler, *args, **kwargs): + try: + return handler(*args, **kwargs) + except: + log.error('Error in event "%s", that wasn\'nt caught: %s' % (name, traceback.format_exc())) def addEvent(name, handler, priority = 0): @@ -20,13 +25,10 @@ def addEvent(name, handler, priority = 0): try: parent = handler.im_self parent.beforeCall(handler) - try: - h = handler(*args, **kwargs) - except: - log.error('Error in event %s, that wasn\'nt caught: %s' % (name, traceback.format_exc())) + h = runHandler(name, handler, *args, **kwargs) parent.afterCall(handler) except: - h = handler(*args, **kwargs) + h = runHandler(name, handler, *args, **kwargs) return h diff --git a/couchpotato/core/plugins/release/main.py b/couchpotato/core/plugins/release/main.py index e8af0c02..90825350 100644 --- a/couchpotato/core/plugins/release/main.py +++ b/couchpotato/core/plugins/release/main.py @@ -60,10 +60,10 @@ class Release(Plugin): added_file = self.saveFile(file, type = type, include_media_info = type is 'movie') try: added_file = db.query(File).filter_by(id = added_file.get('id')).one() - Relea.files.append(added_file) + rel.files.append(added_file) db.commit() except Exception, e: - log.debug('Failed to attach "%s" to Relea: %s' % (file, e)) + log.debug('Failed to attach "%s" to release: %s' % (file, e)) db.remove() @@ -77,7 +77,7 @@ class Release(Plugin): properties = {} # Check database and update/insert if necessary - return fireEvent('file.add', path = file, part = fireEvent('scanner.partnumber', file, single = True), type = Scanner.file_types[type], properties = properties, single = True) + return fireEvent('file.add', path = file, part = fireEvent('scanner.partnumber', file, single = True), type = Scanner.file_types.get(type), properties = properties, single = True) def delete(self): diff --git a/couchpotato/core/plugins/renamer/main.py b/couchpotato/core/plugins/renamer/main.py index 96c9ccde..1fcec62e 100644 --- a/couchpotato/core/plugins/renamer/main.py +++ b/couchpotato/core/plugins/renamer/main.py @@ -280,7 +280,7 @@ class Renamer(Plugin): log.info('Removing release %s' % release) # Add this release to the library - fireEvent('scanner.files', folder = destination, files = rename_files) + fireEvent('scanner.files', folder = destination, files = [x for x in rename_files.itervalues()]) # Search for trailers etc fireEventAsync('renamer.after', group) diff --git a/couchpotato/core/plugins/scanner/main.py b/couchpotato/core/plugins/scanner/main.py index 6f7742ec..649d9771 100644 --- a/couchpotato/core/plugins/scanner/main.py +++ b/couchpotato/core/plugins/scanner/main.py @@ -1,7 +1,7 @@ from couchpotato import get_session from couchpotato.core.event import fireEvent, addEvent from couchpotato.core.helpers.encoding import toUnicode, simplifyString -from couchpotato.core.helpers.variable import getExt, getImdb +from couchpotato.core.helpers.variable import getExt, getImdb, tryInt from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin from couchpotato.core.settings.model import File @@ -38,6 +38,7 @@ class Scanner(Plugin): 'nfo': ('nfo', 'nfo'), 'movie': ('video', 'movie'), 'backdrop': ('image', 'backdrop'), + 'leftover': ('leftover', 'leftover'), } codecs = { @@ -196,11 +197,13 @@ class Scanner(Plugin): # Check if movie is fresh and maybe still unpacking, ignore files new then 1 minute file_too_new = False for file in group['unsorted_files']: - if os.path.getmtime(file) > time.time() - 60: - file_too_new = True + file_time = os.path.getmtime(file) + if file_time > time.time() - 60: + file_too_new = tryInt(time.time() - file_time) + break if file_too_new: - log.info('Files seem to be still unpacking or just unpacked, ignoring for now: %s' % identifier) + log.info('Files seem to be still unpacking or just unpacked (%s), ignoring for now: %s' % (file_time, identifier)) delete_identifier.append(identifier) continue