From dd24eb8893dac88efb5159ce331d67e5da119ece Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 20 Dec 2014 18:49:35 +0100 Subject: [PATCH 1/7] Revert "Give response back to the main thread on api calls" This reverts commit 576bcb9f4b389d271da6a88addb50405c8f21dff. Conflicts: couchpotato/api.py --- couchpotato/api.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/couchpotato/api.py b/couchpotato/api.py index 2ce4312c..cd01197a 100644 --- a/couchpotato/api.py +++ b/couchpotato/api.py @@ -7,7 +7,6 @@ import urllib from couchpotato.core.helpers.request import getParams from couchpotato.core.logger import CPLog -from tornado.ioloop import IOLoop from tornado.web import RequestHandler, asynchronous @@ -34,7 +33,7 @@ def run_async(func): def run_handler(route, kwargs, callback = None): try: res = api[route](**kwargs) - IOLoop.current().add_callback(callback, res, route) + callback(res, route) except: log.error('Failed doing api request "%s": %s', (route, traceback.format_exc())) callback({'success': False, 'error': 'Failed returning results'}, route) From 3bf2d844a0922f659b4305858fb3c8001901958a Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 20 Dec 2014 20:13:49 +0100 Subject: [PATCH 2/7] Release api lock on connection close or finish fix #4372 --- couchpotato/api.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/couchpotato/api.py b/couchpotato/api.py index cd01197a..27a8efcb 100644 --- a/couchpotato/api.py +++ b/couchpotato/api.py @@ -7,6 +7,7 @@ import urllib from couchpotato.core.helpers.request import getParams from couchpotato.core.logger import CPLog +from tornado.ioloop import IOLoop from tornado.web import RequestHandler, asynchronous @@ -33,7 +34,7 @@ def run_async(func): def run_handler(route, kwargs, callback = None): try: res = api[route](**kwargs) - callback(res, route) + IOLoop.current().add_callback(callback, res, route) except: log.error('Failed doing api request "%s": %s', (route, traceback.format_exc())) callback({'success': False, 'error': 'Failed returning results'}, route) @@ -83,10 +84,11 @@ def addNonBlockApiView(route, func_tuple, docs = None, **kwargs): # Blocking API handler class ApiHandler(RequestHandler): + route = None @asynchronous def get(self, route, *args, **kwargs): - route = route.strip('/') + self.route = route = route.strip('/') if not api.get(route): self.write('API call doesn\'t seem to exist') self.finish() @@ -123,10 +125,18 @@ class ApiHandler(RequestHandler): except: log.error('Failed write error "%s": %s', (route, traceback.format_exc())) - api_locks[route].release() + self.unlock() post = get + def on_connection_close(self): + self.unlock() + super(ApiHandler, self).on_connection_close() + + def on_finish(self): + self.unlock() + super(ApiHandler, self).on_finish() + def taskFinished(self, result, route): if not self.request.connection.stream.closed(): @@ -150,7 +160,11 @@ class ApiHandler(RequestHandler): try: self.finish({'success': False, 'error': 'Failed returning results'}) except: pass - api_locks[route].release() + self.unlock() + + def unlock(self): + try: api_locks[self.route].release() + except: pass def addApiView(route, func, static = False, docs = None, **kwargs): From ffcd36cbf4878d53a526a93004711344dee2c5e7 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 20 Dec 2014 21:45:15 +0100 Subject: [PATCH 3/7] IOLoop callback hanging --- couchpotato/api.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/couchpotato/api.py b/couchpotato/api.py index 27a8efcb..3c8275dc 100644 --- a/couchpotato/api.py +++ b/couchpotato/api.py @@ -7,7 +7,6 @@ import urllib from couchpotato.core.helpers.request import getParams from couchpotato.core.logger import CPLog -from tornado.ioloop import IOLoop from tornado.web import RequestHandler, asynchronous @@ -34,7 +33,7 @@ def run_async(func): def run_handler(route, kwargs, callback = None): try: res = api[route](**kwargs) - IOLoop.current().add_callback(callback, res, route) + callback(res, route) except: log.error('Failed doing api request "%s": %s', (route, traceback.format_exc())) callback({'success': False, 'error': 'Failed returning results'}, route) @@ -129,14 +128,6 @@ class ApiHandler(RequestHandler): post = get - def on_connection_close(self): - self.unlock() - super(ApiHandler, self).on_connection_close() - - def on_finish(self): - self.unlock() - super(ApiHandler, self).on_finish() - def taskFinished(self, result, route): if not self.request.connection.stream.closed(): From a6e49098c8fcee78958c18bb3fa9daf4bed37ff2 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 20 Dec 2014 22:15:27 +0100 Subject: [PATCH 4/7] Add robots.txt --- couchpotato/__init__.py | 9 +++++++++ couchpotato/templates/login.html | 1 + 2 files changed, 10 insertions(+) diff --git a/couchpotato/__init__.py b/couchpotato/__init__.py index daa93bcc..9df16122 100644 --- a/couchpotato/__init__.py +++ b/couchpotato/__init__.py @@ -40,6 +40,8 @@ class WebHandler(BaseHandler): return try: + if route == 'robots.txt': + self.set_header('Content-Type', 'text/plain') self.write(views[route]()) except: log.error("Failed doing web request '%s': %s", (route, traceback.format_exc())) @@ -60,6 +62,13 @@ def index(): addView('', index) +# Web view +def robots(): + return 'User-agent: * \n' \ + 'Disallow: /' +addView('robots.txt', robots) + + # API docs def apiDocs(): routes = list(api.keys()) diff --git a/couchpotato/templates/login.html b/couchpotato/templates/login.html index e33db2d7..c30ab6bd 100644 --- a/couchpotato/templates/login.html +++ b/couchpotato/templates/login.html @@ -6,6 +6,7 @@ + {% for url in fireEvent('clientscript.get_styles', as_html = True, location = 'front', single = True) %} {% end %} From b0d1fe5c33bf098c1fd99546ed41576b29f0a0fb Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 20 Dec 2014 22:17:43 +0100 Subject: [PATCH 5/7] Return false if no media is found on try_next fix #4345 --- couchpotato/core/media/movie/searcher.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/couchpotato/core/media/movie/searcher.py b/couchpotato/core/media/movie/searcher.py index 11aa975d..6d3ee836 100755 --- a/couchpotato/core/media/movie/searcher.py +++ b/couchpotato/core/media/movie/searcher.py @@ -394,8 +394,9 @@ class MovieSearcher(SearcherBase, MovieTypeBase): log.info('Trying next release for: %s', getTitle(media)) self.single(media, manual = manual, force_download = force_download) - return True - + return True + + return False except: log.error('Failed searching for next release: %s', traceback.format_exc()) return False From 4a6b45c65c60c9f1ec5300ec877dd621a9fc80c6 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 20 Dec 2014 22:24:00 +0100 Subject: [PATCH 6/7] SCC not finding seeders --- couchpotato/core/media/_base/providers/torrent/sceneaccess.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/couchpotato/core/media/_base/providers/torrent/sceneaccess.py b/couchpotato/core/media/_base/providers/torrent/sceneaccess.py index e172f6ad..17c98915 100644 --- a/couchpotato/core/media/_base/providers/torrent/sceneaccess.py +++ b/couchpotato/core/media/_base/providers/torrent/sceneaccess.py @@ -42,6 +42,7 @@ class Base(TorrentProvider): link = result.find('td', attrs = {'class': 'ttr_name'}).find('a') url = result.find('td', attrs = {'class': 'td_dl'}).find('a') + seeders = result.find('td', attrs = {'class': 'ttr_seeders'}).find('a') leechers = result.find('td', attrs = {'class': 'ttr_leechers'}).find('a') torrent_id = link['href'].replace('details?id=', '') @@ -51,7 +52,7 @@ class Base(TorrentProvider): 'url': self.urls['download'] % url['href'], 'detail_url': self.urls['detail'] % torrent_id, 'size': self.parseSize(result.find('td', attrs = {'class': 'ttr_size'}).contents[0]), - 'seeders': tryInt(result.find('td', attrs = {'class': 'ttr_seeders'}).find('a').string), + 'seeders': tryInt(seeders.string) if seeders else 0, 'leechers': tryInt(leechers.string) if leechers else 0, 'get_more_info': self.getMoreInfo, }) From 6d5882001a96ede03b4dc66fb53a80258da5565f Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 20 Dec 2014 22:32:18 +0100 Subject: [PATCH 7/7] Notificaton.list not returning anything fix #4348 --- couchpotato/core/notifications/core/main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/couchpotato/core/notifications/core/main.py b/couchpotato/core/notifications/core/main.py index fa8e9a7e..4055c413 100644 --- a/couchpotato/core/notifications/core/main.py +++ b/couchpotato/core/notifications/core/main.py @@ -110,11 +110,11 @@ class CoreNotifier(Notification): if limit_offset: splt = splitString(limit_offset) - limit = splt[0] - offset = 0 if len(splt) is 1 else splt[1] - results = db.get_many('notification', limit = limit, offset = offset, with_doc = True) + limit = tryInt(splt[0]) + offset = tryInt(0 if len(splt) is 1 else splt[1]) + results = db.all('notification', limit = limit, offset = offset, with_doc = True) else: - results = db.get_many('notification', limit = 200, with_doc = True) + results = db.all('notification', limit = 200, with_doc = True) notifications = [] for n in results: