From bb42bd1ad2bd4fc6a934cee3279560b561008859 Mon Sep 17 00:00:00 2001
From: Britney Fransen <brfransen@gmail.com>
Date: Wed, 11 Nov 2015 19:11:47 +0000
Subject: mythtv & mythplugins: update to latest -fixes

mythtv: update tmdb error 25 patch
---
 abs/core/mythtv/stable-0.27/git_src/git_hash       |  2 +-
 abs/core/mythtv/stable-0.27/mythplugins/PKGBUILD   |  2 +-
 abs/core/mythtv/stable-0.27/mythtv/PKGBUILD        |  8 +--
 .../stable-0.27/mythtv/tmdb3_query_limit.2.diff    | 70 ++++++++++++++++++++++
 .../mythtv/stable-0.27/mythtv/tmdb_error25.patch   | 55 -----------------
 5 files changed, 76 insertions(+), 61 deletions(-)
 create mode 100644 abs/core/mythtv/stable-0.27/mythtv/tmdb3_query_limit.2.diff
 delete mode 100644 abs/core/mythtv/stable-0.27/mythtv/tmdb_error25.patch

diff --git a/abs/core/mythtv/stable-0.27/git_src/git_hash b/abs/core/mythtv/stable-0.27/git_src/git_hash
index a53d40b..3ebe7b8 100644
--- a/abs/core/mythtv/stable-0.27/git_src/git_hash
+++ b/abs/core/mythtv/stable-0.27/git_src/git_hash
@@ -1 +1 @@
-68e51d6fd4fa25e985b21cb3a5b5ca6fce9aca9d
+acd481df3f5be108bd6de5f4be27ac50aedab162
diff --git a/abs/core/mythtv/stable-0.27/mythplugins/PKGBUILD b/abs/core/mythtv/stable-0.27/mythplugins/PKGBUILD
index 69f3ccf..127c5d3 100644
--- a/abs/core/mythtv/stable-0.27/mythplugins/PKGBUILD
+++ b/abs/core/mythtv/stable-0.27/mythplugins/PKGBUILD
@@ -9,7 +9,7 @@ pkgname=('mytharchive'
          'mythweather'
          'mythzoneminder')
 pkgver=0.27.5
-pkgrel=10
+pkgrel=11
 arch=('i686' 'x86_64')
 url="http://www.mythtv.org"
 license=('GPL')
diff --git a/abs/core/mythtv/stable-0.27/mythtv/PKGBUILD b/abs/core/mythtv/stable-0.27/mythtv/PKGBUILD
index 1e6a917..786ca3d 100644
--- a/abs/core/mythtv/stable-0.27/mythtv/PKGBUILD
+++ b/abs/core/mythtv/stable-0.27/mythtv/PKGBUILD
@@ -1,6 +1,6 @@
 pkgname=mythtv
 pkgver=0.27.5
-pkgrel=10
+pkgrel=11
 commit_hash=`cat ../git_src/git_hash`
 pkgdesc="A Homebrew PVR project $commit_hash"
 arch=('i686' 'x86_64')
@@ -23,10 +23,10 @@ patches=('myth_settings.patch'
          'videoAlwaysUseBookmark.patch'
          'fixQTvirtualkeyboard.patch'
          'suggestedstarttime.patch.v1'
-         'tmdb_error25.patch')
+         'tmdb3_query_limit.2.diff')
          #fixQTvirtualkeyboard.patch: https://code.mythtv.org/trac/ticket/12347
          #suggestedstarttime.patch.v1: http://code.mythtv.org/trac/ticket/11562   next mythfilldatabase run in mythweb
-         #tmdb_error25.patch: https://code.mythtv.org/trac/ticket/12455
+         #tmdb3_query_limit.2.diff: https://code.mythtv.org/trac/ticket/12455
 
 optdepends=()
 replaces=('mythvideo' 'myththemes')
@@ -109,5 +109,5 @@ md5sums=('5f3e43567e62afe17bad39f5a9b604cf'
          '41098e898361a5a3cde3eaae358482a8'
          'a853dff0f5c92ca58fcc1e389cd16266'
          '35a7fd3e3057691e3b1bf355bb9e8b16'
-         '5e645c3d0df38143c45f3e8fe24f1b6f'
+         'a41581e7b80093eeadabcf7d9d01fc19'
          '928de4b070d9f3b784d55c0db415eaf3')
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))
+ 
+ 
diff --git a/abs/core/mythtv/stable-0.27/mythtv/tmdb_error25.patch b/abs/core/mythtv/stable-0.27/mythtv/tmdb_error25.patch
deleted file mode 100644
index fc1a2fe..0000000
--- a/abs/core/mythtv/stable-0.27/mythtv/tmdb_error25.patch
+++ /dev/null
@@ -1,55 +0,0 @@
---- src/mythtv/bindings/python/tmdb3/tmdb3/request.py.orig	2015-09-29 16:11:52.436024705 +0000
-+++ src/mythtv/bindings/python/tmdb3/tmdb3/request.py	2015-09-29 16:13:24.297824407 +0000
-@@ -16,6 +16,7 @@
- import urllib2
- import json
- import os
-+import time
- 
- DEBUG = False
- cache = Cache(filename='pytmdb3.cache')
-@@ -113,21 +114,29 @@
-     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:
--            try:
--                # try to load whatever was returned
--                data = json.loads(e.response)
--            except:
--                # cannot parse json, 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
-+        while True:
-+           try:
-+              # 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 minute.
-+                 if data.get('status_code', 1) == 25:
-+                    # Sleep and retry query.
-+                    time.sleep(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
-         handle_status(data, url)
-         if DEBUG:
-             import pprint
-- 
cgit v0.12

