mirror of
https://github.com/SickGear/SickGear.git
synced 2024-11-28 23:53:37 +00:00
Change add a retry backoff for downloading posters for person search tvmaze
This commit is contained in:
parent
9466d3f288
commit
1b90c4b0c5
1 changed files with 13 additions and 1 deletions
|
@ -84,6 +84,10 @@ from tornado.escape import utf8
|
||||||
from tornado.web import RequestHandler, StaticFileHandler, authenticated
|
from tornado.web import RequestHandler, StaticFileHandler, authenticated
|
||||||
from tornado.concurrent import run_on_executor
|
from tornado.concurrent import run_on_executor
|
||||||
|
|
||||||
|
from lib import requests
|
||||||
|
from lib.urllib3.util.retry import Retry
|
||||||
|
from lib.requests.adapters import HTTPAdapter
|
||||||
|
|
||||||
from lib import subliminal
|
from lib import subliminal
|
||||||
from lib.cfscrape import CloudflareScraper
|
from lib.cfscrape import CloudflareScraper
|
||||||
from lib.dateutil import tz, zoneinfo
|
from lib.dateutil import tz, zoneinfo
|
||||||
|
@ -10186,6 +10190,13 @@ class Cache(MainHandler):
|
||||||
|
|
||||||
|
|
||||||
class CachedImages(MainHandler):
|
class CachedImages(MainHandler):
|
||||||
|
download_session = CloudflareScraper.create_scraper()
|
||||||
|
retries = Retry(total=5,
|
||||||
|
backoff_factor=3,
|
||||||
|
status_forcelist=[429])
|
||||||
|
download_session.mount('http://', HTTPAdapter(max_retries=retries))
|
||||||
|
download_session.mount('https://', HTTPAdapter(max_retries=retries))
|
||||||
|
|
||||||
def set_default_headers(self):
|
def set_default_headers(self):
|
||||||
super(CachedImages, self).set_default_headers()
|
super(CachedImages, self).set_default_headers()
|
||||||
self.set_header('Cache-Control', 'no-cache, max-age=0')
|
self.set_header('Cache-Control', 'no-cache, max-age=0')
|
||||||
|
@ -10260,7 +10271,8 @@ class CachedImages(MainHandler):
|
||||||
except (BaseException, Exception):
|
except (BaseException, Exception):
|
||||||
poster_url = ''
|
poster_url = ''
|
||||||
if poster_url:
|
if poster_url:
|
||||||
sg_helpers.download_file(poster_url, image_file, nocache=True)
|
# try to rate limit tvmaze to some degree
|
||||||
|
sg_helpers.download_file(poster_url, image_file, nocache=True, session=CachedImages.download_session)
|
||||||
if tvmaze_image and not os.path.isfile(image_file):
|
if tvmaze_image and not os.path.isfile(image_file):
|
||||||
self.create_dummy_image(image_file, 'tvmaze')
|
self.create_dummy_image(image_file, 'tvmaze')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue