|
|
@ -20,7 +20,7 @@ import threading |
|
|
|
|
|
|
|
import sickbeard |
|
|
|
from . import db |
|
|
|
from .helpers import try_int |
|
|
|
from .helpers import full_sanitize_scene_name, try_int |
|
|
|
|
|
|
|
from six import iteritems |
|
|
|
|
|
|
@ -30,6 +30,7 @@ if False: |
|
|
|
from .tv import TVShow, TVShowBase |
|
|
|
|
|
|
|
nameCache = {} |
|
|
|
sceneNameCache = {} |
|
|
|
nameCacheLock = threading.Lock() |
|
|
|
|
|
|
|
|
|
|
@ -49,7 +50,7 @@ def addNameToCache(name, tvid=0, prodid=0, season=-1): |
|
|
|
|
|
|
|
with nameCacheLock: |
|
|
|
# standardize the name we're using to account for small differences in providers |
|
|
|
name = sickbeard.helpers.full_sanitize_scene_name(name) |
|
|
|
name = full_sanitize_scene_name(name) |
|
|
|
if name not in nameCache: |
|
|
|
nameCache[name] = [int(tvid), int(prodid), season] |
|
|
|
|
|
|
@ -63,7 +64,7 @@ def retrieveNameFromCache(name): |
|
|
|
""" |
|
|
|
global nameCache |
|
|
|
|
|
|
|
name = sickbeard.helpers.full_sanitize_scene_name(name) |
|
|
|
name = full_sanitize_scene_name(name) |
|
|
|
try: |
|
|
|
if name in nameCache: |
|
|
|
return int(nameCache[name][0]), int(nameCache[name][1]) |
|
|
@ -72,37 +73,51 @@ def retrieveNameFromCache(name): |
|
|
|
return None, None |
|
|
|
|
|
|
|
|
|
|
|
def buildNameCache(show_obj=None): |
|
|
|
# type: (Optional[Union[TVShow, TVShowBase]]) -> None |
|
|
|
def buildNameCache(show_obj=None, update_only_scene=False): |
|
|
|
# type: (Optional[Union[TVShow, TVShowBase]], bool) -> None |
|
|
|
"""Adds all new name exceptions to the namecache memory and flushes any removed name exceptions |
|
|
|
|
|
|
|
:param show_obj : Only update name cache for this show object, otherwise update all |
|
|
|
:param update_only_scene: (optional) only update scene name cache |
|
|
|
""" |
|
|
|
global nameCache |
|
|
|
global nameCache, sceneNameCache |
|
|
|
with nameCacheLock: |
|
|
|
|
|
|
|
if show_obj: |
|
|
|
# search for only the requested show id and flush old show entries from namecache |
|
|
|
show_ids = {show_obj.tvid: [show_obj.prodid]} |
|
|
|
nameCache = dict([(k, v) for k, v in iteritems(nameCache) |
|
|
|
if not (v[0] == show_obj.tvid and v[1] == show_obj.prodid)]) |
|
|
|
if not update_only_scene: |
|
|
|
if show_obj: |
|
|
|
# search for only the requested show id and flush old show entries from namecache |
|
|
|
show_ids = {show_obj.tvid: [show_obj.prodid]} |
|
|
|
nameCache = dict([(k, v) for k, v in iteritems(nameCache) |
|
|
|
if not (v[0] == show_obj.tvid and v[1] == show_obj.prodid)]) |
|
|
|
sceneNameCache = dict([(k, v) for k, v in iteritems(sceneNameCache) |
|
|
|
if not (v[0] == show_obj.tvid and v[1] == show_obj.prodid)]) |
|
|
|
|
|
|
|
# add standard indexer name to namecache |
|
|
|
nameCache[full_sanitize_scene_name(show_obj.name)] = [show_obj.tvid, show_obj.prodid, -1] |
|
|
|
else: |
|
|
|
# generate list of production ids to look up in cache.db |
|
|
|
show_ids = {} |
|
|
|
for cur_show_obj in sickbeard.showList: |
|
|
|
show_ids.setdefault(cur_show_obj.tvid, []).append(cur_show_obj.prodid) |
|
|
|
|
|
|
|
# add all standard show indexer names to namecache |
|
|
|
nameCache = dict( |
|
|
|
[(full_sanitize_scene_name(cur_so.name), [cur_so.tvid, cur_so.prodid, -1]) |
|
|
|
for cur_so in sickbeard.showList if cur_so]) |
|
|
|
sceneNameCache = {} |
|
|
|
|
|
|
|
# add standard indexer name to namecache |
|
|
|
nameCache[sickbeard.helpers.full_sanitize_scene_name(show_obj.name)] = [show_obj.tvid, show_obj.prodid, -1] |
|
|
|
else: |
|
|
|
cacheDB = db.DBConnection() |
|
|
|
|
|
|
|
cache_results = [] |
|
|
|
if update_only_scene: |
|
|
|
# generate list of production ids to look up in cache.db |
|
|
|
show_ids = {} |
|
|
|
for cur_show_obj in sickbeard.showList: |
|
|
|
show_ids.setdefault(cur_show_obj.tvid, []).append(cur_show_obj.prodid) |
|
|
|
tmp_scene_name_cache = {} |
|
|
|
else: |
|
|
|
tmp_scene_name_cache = sceneNameCache.copy() |
|
|
|
|
|
|
|
# add all standard show indexer names to namecache |
|
|
|
nameCache = dict( |
|
|
|
[(sickbeard.helpers.full_sanitize_scene_name(cur_so.name), [cur_so.tvid, cur_so.prodid, -1]) |
|
|
|
for cur_so in sickbeard.showList if cur_so]) |
|
|
|
|
|
|
|
cacheDB = db.DBConnection() |
|
|
|
|
|
|
|
cache_results = [] |
|
|
|
for t, s in iteritems(show_ids): |
|
|
|
cache_results += cacheDB.select( |
|
|
|
'SELECT show_name, indexer AS tv_id, indexer_id AS prod_id, season' |
|
|
@ -114,8 +129,10 @@ def buildNameCache(show_obj=None): |
|
|
|
tvid = int(cache_result['tv_id']) |
|
|
|
prodid = int(cache_result['prod_id']) |
|
|
|
season = try_int(cache_result['season'], -1) |
|
|
|
name = sickbeard.helpers.full_sanitize_scene_name(cache_result['show_name']) |
|
|
|
nameCache[name] = [tvid, prodid, season] |
|
|
|
name = full_sanitize_scene_name(cache_result['show_name']) |
|
|
|
tmp_scene_name_cache[name] = [tvid, prodid, season] |
|
|
|
|
|
|
|
sceneNameCache = tmp_scene_name_cache |
|
|
|
|
|
|
|
|
|
|
|
def remove_from_namecache(tvid, prodid): |
|
|
|