summaryrefslogtreecommitdiffstats
path: root/abs/core/mythtv/stable-0.27/mythtv/tmdb3_query_limit.2.diff
diff options
context:
space:
mode:
Diffstat (limited to 'abs/core/mythtv/stable-0.27/mythtv/tmdb3_query_limit.2.diff')
-rw-r--r--abs/core/mythtv/stable-0.27/mythtv/tmdb3_query_limit.2.diff70
1 files changed, 70 insertions, 0 deletions
diff --git a/abs/core/mythtv/stable-0.27/mythtv/tmdb3_query_limit.2.diff b/abs/core/mythtv/stable-0.27/mythtv/tmdb3_query_limit.2.diff
new file mode 100644
index 0000000..7b44537
--- /dev/null
+++ b/abs/core/mythtv/stable-0.27/mythtv/tmdb3_query_limit.2.diff
@@ -0,0 +1,70 @@
+diff --git mythtv/bindings/python/tmdb3/tmdb3/request.py mythtv/bindings/python/tmdb3/tmdb3/request.py
+index 2de4cd5..1b6663d 100644
+--- src/mythtv/bindings/python/tmdb3/tmdb3/request.py
++++ src/mythtv/bindings/python/tmdb3/tmdb3/request.py
+@@ -16,6 +16,7 @@ from urllib import urlencode
+ import urllib2
+ import json
+ import os
++import time
+
+ DEBUG = False
+ cache = Cache(filename='pytmdb3.cache')
+@@ -113,21 +114,32 @@ class Request(urllib2.Request):
+ def readJSON(self):
+ """Parse result from specified URL as JSON data."""
+ url = self.get_full_url()
+- try:
+- # catch HTTP error from open()
+- data = json.load(self.open())
+- except TMDBHTTPError, e:
++ tries = 0
++ while tries < 100:
+ try:
+- # try to load whatever was returned
+- data = json.loads(e.response)
+- except:
+- # cannot parse json, just raise existing error
++ # catch HTTP error from open()
++ data = json.load(self.open())
++ break
++ except TMDBHTTPError, e:
++ try:
++ # try to load whatever was returned
++ data = json.loads(e.response)
++ except:
++ # cannot parse json, just raise existing error
++ raise e
++ else:
++ # Check for error code of 25 which means we are doing more than 40 requests per 10 seconds
++ if data.get('status_code', 1) ==25:
++ # Sleep and retry query.
++ if DEBUG:
++ print 'Retry after {0} seconds'.format(max(float(e.headers['retry-after']),10))
++ time.sleep(max(float(e.headers['retry-after']),10))
++ continue
++ else:
++ # response parsed, try to raise error from TMDB
++ handle_status(data, url)
++ # no error from TMDB, just raise existing error
+ raise e
+- else:
+- # response parsed, try to raise error from TMDB
+- handle_status(data, url)
+- # no error from TMDB, just raise existing error
+- raise e
+ handle_status(data, url)
+ if DEBUG:
+ import pprint
+diff --git mythtv/bindings/python/tmdb3/tmdb3/tmdb_exceptions.py mythtv/bindings/python/tmdb3/tmdb3/tmdb_exceptions.py
+index f85fbcf..5020c4a 100644
+--- src/mythtv/bindings/python/tmdb3/tmdb3/tmdb_exceptions.py
++++ src/mythtv/bindings/python/tmdb3/tmdb3/tmdb_exceptions.py
+@@ -96,6 +96,7 @@ class TMDBHTTPError(TMDBError):
+ def __init__(self, err):
+ self.httperrno = err.code
+ self.response = err.fp.read()
++ self.headers = err.headers
+ super(TMDBHTTPError, self).__init__(str(err))
+
+