Browse Source

Change add 3 days cache for tmdb base info only.

tags/release_0.25.1
Prinz23 5 years ago
committed by JackDandy
parent
commit
c738b9181c
  1. 1
      CHANGES.md
  2. 15
      lib/sg_helpers.py
  3. 3
      sickbeard/metadata/generic.py
  4. 2
      sickbeard/webserve.py

1
CHANGES.md

@ -1,5 +1,6 @@
### 0.23.0 (2019-xx-xx xx:xx:xx UTC) ### 0.23.0 (2019-xx-xx xx:xx:xx UTC)
* Change add 3 days cache for tmdb base info only
* Change `Discordapp` to `Discord` in line with company change * Change `Discordapp` to `Discord` in line with company change
* Change remove `app` from URL when calling webhook * Change remove `app` from URL when calling webhook
* Change remind user when testing Notifications config / Discord to update URL * Change remind user when testing Notifications config / Discord to update URL

15
lib/sg_helpers.py

@ -20,6 +20,7 @@ import traceback
from exceptions_helper import ex, ConnectionSkipException from exceptions_helper import ex, ConnectionSkipException
from lib.cachecontrol import CacheControl, caches from lib.cachecontrol import CacheControl, caches
from lib.tmdbsimple.configuration import Configuration
from cfscrape import CloudflareScraper from cfscrape import CloudflareScraper
from send2trash import send2trash from send2trash import send2trash
@ -36,6 +37,10 @@ if False:
from typing import Any, AnyStr, Dict, NoReturn, integer_types, Iterable, Iterator, List, Optional, Tuple, Union from typing import Any, AnyStr, Dict, NoReturn, integer_types, Iterable, Iterator, List, Optional, Tuple, Union
from lxml_etree import etree from lxml_etree import etree
# global tmdb_info cache
_TMDB_INFO_CACHE = {'date': datetime.datetime(2000, 1, 1), 'data': None}
# Mapping error status codes to official W3C names # Mapping error status codes to official W3C names
http_error_code = { http_error_code = {
300: 'Multiple Choices', 300: 'Multiple Choices',
@ -1303,3 +1308,13 @@ def indent_xml(elem, level=0):
elem.text = ('%s' % elem.text).replace('\n', ' ') elem.text = ('%s' % elem.text).replace('\n', ' ')
if level and (not elem.tail or not elem.tail.strip()): if level and (not elem.tail or not elem.tail.strip()):
elem.tail = i elem.tail = i
def get_tmdb_info():
# type: (...) -> Dict
"""return tmdbsimple Configuration().info() or cached copy"""
global _TMDB_INFO_CACHE
# only retrieve info data if older then 3 days
if 3 < (datetime.datetime.now() - _TMDB_INFO_CACHE['date']).days or not _TMDB_INFO_CACHE['data']:
_TMDB_INFO_CACHE = {'date': datetime.datetime.now(), 'data': Configuration().info()}
return _TMDB_INFO_CACHE['data']

3
sickbeard/metadata/generic.py

@ -1089,8 +1089,7 @@ class GenericMetadata(object):
# get TMDB configuration info # get TMDB configuration info
TMDB.API_KEY = sickbeard.TMDB_API_KEY TMDB.API_KEY = sickbeard.TMDB_API_KEY
config = TMDB.Configuration() response = sg_helpers.get_tmdb_info()
response = config.info()
base_url = response['images']['base_url'] base_url = response['images']['base_url']
sizes = response['images']['poster_sizes'] sizes = response['images']['poster_sizes']

2
sickbeard/webserve.py

@ -8390,7 +8390,7 @@ class CachedImages(MainHandler):
tmdbimage = True tmdbimage = True
try: try:
TMDB.API_KEY = sickbeard.TMDB_API_KEY TMDB.API_KEY = sickbeard.TMDB_API_KEY
tmdbconfig = TMDB.Configuration().info() tmdbconfig = sg_helpers.get_tmdb_info()
images = TMDB.TV(helpers.try_int(tmdbid)).images() images = TMDB.TV(helpers.try_int(tmdbid)).images()
s = '%s%s%s' % (tmdbconfig['images']['base_url'], tmdbconfig['images']['poster_sizes'][3], s = '%s%s%s' % (tmdbconfig['images']['base_url'], tmdbconfig['images']['poster_sizes'][3],
sorted(images['posters'], key=lambda x: x['vote_average'], sorted(images['posters'], key=lambda x: x['vote_average'],

Loading…
Cancel
Save