From af92355e2ff5b44b9bc2648f56f10814c8b98467 Mon Sep 17 00:00:00 2001 From: Ruud Date: Thu, 16 Feb 2012 00:01:43 +0100 Subject: [PATCH] JSON errors and image not loading --- CouchPotato.py | 2 +- .../core/notifications/core/static/notification.js | 2 +- couchpotato/core/plugins/file/main.py | 26 ++++++++++++---------- couchpotato/core/plugins/library/main.py | 2 +- couchpotato/core/plugins/movie/static/search.js | 4 ++-- couchpotato/core/plugins/release/main.py | 2 +- couchpotato/core/providers/movie/imdbapi/main.py | 6 +++-- 7 files changed, 24 insertions(+), 20 deletions(-) diff --git a/CouchPotato.py b/CouchPotato.py index 98e2787..5c3592d 100755 --- a/CouchPotato.py +++ b/CouchPotato.py @@ -33,7 +33,7 @@ class Loader(object): self.log = CPLog(__name__) formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s', '%H:%M:%S') - hdlr = handlers.RotatingFileHandler(os.path.join(self.data_dir, 'logs', 'error.log'), 'a', 500000, 10) + hdlr = handlers.RotatingFileHandler(os.path.join(self.data_dir, 'error.log'), 'a', 500000, 10) hdlr.setLevel(logging.CRITICAL) hdlr.setFormatter(formatter) self.log.logger.addHandler(hdlr) diff --git a/couchpotato/core/notifications/core/static/notification.js b/couchpotato/core/notifications/core/static/notification.js index 5af7657..e96fdba 100644 --- a/couchpotato/core/notifications/core/static/notification.js +++ b/couchpotato/core/notifications/core/static/notification.js @@ -23,7 +23,7 @@ var NotificationBase = new Class({ self.request = Api.request('core_notifier.listener', { 'initialDelay': 100, 'delay': 3000, - 'onComplete': self.processData.bind(self) + 'onSuccess': self.processData.bind(self) }) self.request.startTimer() diff --git a/couchpotato/core/plugins/file/main.py b/couchpotato/core/plugins/file/main.py index 099246f..ba84baa 100644 --- a/couchpotato/core/plugins/file/main.py +++ b/couchpotato/core/plugins/file/main.py @@ -45,7 +45,8 @@ class FileManager(Plugin): self.createFile(dest, filedata, binary = True) return dest - def add(self, path = '', part = 1, type = (), available = 1, properties = {}): + def add(self, path = '', part = 1, type_tuple = (), available = 1, properties = {}): + type_id = self.getType(type_tuple).get('id') db = get_session() f = db.query(File).filter(File.path == toUnicode(path)).first() @@ -56,7 +57,7 @@ class FileManager(Plugin): f.path = toUnicode(path) f.part = part f.available = available - f.type_id = self.getType(type).id + f.type_id = type_id db.commit() @@ -64,23 +65,24 @@ class FileManager(Plugin): return file_dict - def getType(self, type): + def getType(self, type_tuple): db = get_session() - type, identifier = type + type_type, type_identifier = type_tuple - ft = db.query(FileType).filter_by(identifier = identifier).first() + ft = db.query(FileType).filter_by(identifier = type_identifier).first() if not ft: ft = FileType( - type = toUnicode(type), - identifier = identifier, - name = toUnicode(identifier[0].capitalize() + identifier[1:]) + type = toUnicode(type_type), + identifier = type_identifier, + name = toUnicode(type_identifier[0].capitalize() + type_identifier[1:]) ) - db.add(ft) db.commit() - return ft + type_dict = ft.to_dict() + db.remove() + return type_dict def getTypes(self): @@ -89,7 +91,7 @@ class FileManager(Plugin): results = db.query(FileType).all() types = [] - for type in results: - types.append(type.to_dict()) + for type_object in results: + types.append(type_object.to_dict()) return types diff --git a/couchpotato/core/plugins/library/main.py b/couchpotato/core/plugins/library/main.py index b5d38d9..4ceca11 100644 --- a/couchpotato/core/plugins/library/main.py +++ b/couchpotato/core/plugins/library/main.py @@ -102,7 +102,7 @@ class LibraryPlugin(Plugin): continue file_path = fireEvent('file.download', url = image, single = True) - file_obj = fireEvent('file.add', path = file_path, type = ('image', type), single = True) + file_obj = fireEvent('file.add', path = file_path, type_tuple = ('image', type), single = True) try: file_obj = db.query(File).filter_by(id = file_obj.get('id')).one() library.files.append(file_obj) diff --git a/couchpotato/core/plugins/movie/static/search.js b/couchpotato/core/plugins/movie/static/search.js index 4dedb4c..3f29d13 100644 --- a/couchpotato/core/plugins/movie/static/search.js +++ b/couchpotato/core/plugins/movie/static/search.js @@ -183,7 +183,7 @@ Block.Search.Item = new Class({ 'click': self.showOptions.bind(self) } }).adopt( - self.thumbnail = info.images.poster.length > 0 ? new Element('img.thumbnail', { + self.thumbnail = info.images && info.images.poster.length > 0 ? new Element('img.thumbnail', { 'src': info.images.poster[0] }) : null, new Element('div.info').adopt( @@ -288,7 +288,7 @@ Block.Search.Item = new Class({ self.options.adopt( new Element('div').adopt( - self.info.images.poster.length > 0 ? new Element('img.thumbnail', { + self.info.images && self.info.images.poster.length > 0 ? new Element('img.thumbnail', { 'src': self.info.images.poster[0] }) : null, self.info.in_wanted ? new Element('span.in_wanted', { diff --git a/couchpotato/core/plugins/release/main.py b/couchpotato/core/plugins/release/main.py index 9e92d16..9297dbb 100644 --- a/couchpotato/core/plugins/release/main.py +++ b/couchpotato/core/plugins/release/main.py @@ -79,7 +79,7 @@ class Release(Plugin): properties = {} # Check database and update/insert if necessary - return fireEvent('file.add', path = filepath, part = fireEvent('scanner.partnumber', file, single = True), type = Scanner.file_types.get(type), properties = properties, single = True) + return fireEvent('file.add', path = filepath, part = fireEvent('scanner.partnumber', file, single = True), type_tuple = Scanner.file_types.get(type), properties = properties, single = True) def delete(self): diff --git a/couchpotato/core/providers/movie/imdbapi/main.py b/couchpotato/core/providers/movie/imdbapi/main.py index 2834997..f238e7c 100644 --- a/couchpotato/core/providers/movie/imdbapi/main.py +++ b/couchpotato/core/providers/movie/imdbapi/main.py @@ -33,8 +33,9 @@ class IMDBAPI(MovieProvider): if cached: result = self.parseMovie(cached) log.info('Found: %s' % result['titles'][0] + ' (' + str(result['year']) + ')') + return [result] - return [result] + return [] def getInfo(self, identifier = None): @@ -44,8 +45,9 @@ class IMDBAPI(MovieProvider): if cached: result = self.parseMovie(cached) log.info('Found: %s' % result['titles'][0] + ' (' + str(result['year']) + ')') + return result - return result + return {} def parseMovie(self, movie):