|
@ -17,7 +17,7 @@ |
|
|
# along with SickRage. If not, see <http://www.gnu.org/licenses/>. |
|
|
# along with SickRage. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
|
|
|
|
|
import re |
|
|
import re |
|
|
import threading |
|
|
import time |
|
|
import sickbeard |
|
|
import sickbeard |
|
|
|
|
|
|
|
|
from lib import adba |
|
|
from lib import adba |
|
@ -26,6 +26,9 @@ from sickbeard import name_cache |
|
|
from sickbeard import logger |
|
|
from sickbeard import logger |
|
|
from sickbeard import db |
|
|
from sickbeard import db |
|
|
|
|
|
|
|
|
|
|
|
MAX_XEM_AGE_SECS = 86400 # 1 day |
|
|
|
|
|
MAX_ANIDB_AGE_SECS = 86400 # 1 day |
|
|
|
|
|
|
|
|
exceptionCache = {} |
|
|
exceptionCache = {} |
|
|
exceptionSeasonCache = {} |
|
|
exceptionSeasonCache = {} |
|
|
exceptionIndexerCache = {} |
|
|
exceptionIndexerCache = {} |
|
@ -228,35 +231,71 @@ def update_scene_exceptions(indexer_id, scene_exceptions): |
|
|
name_cache.clearCache() |
|
|
name_cache.clearCache() |
|
|
|
|
|
|
|
|
def _retrieve_anidb_mainnames(): |
|
|
def _retrieve_anidb_mainnames(): |
|
|
|
|
|
global MAX_ANIDB_AGE_SECS |
|
|
|
|
|
|
|
|
|
|
|
success = False |
|
|
|
|
|
|
|
|
anidb_mainNames = {} |
|
|
anidb_mainNames = {} |
|
|
for show in sickbeard.showList: |
|
|
|
|
|
if show.is_anime and show.indexer == 1: |
|
|
cacheDB = db.DBConnection('cache.db') |
|
|
try: |
|
|
|
|
|
anime = adba.Anime(None, name=show.name, tvdbid=show.indexerid, autoCorrectName=True) |
|
|
rows = cacheDB.select("SELECT last_refreshed FROM scene_exceptions_refresh WHERE list = ?", |
|
|
except: |
|
|
['anidb']) |
|
|
continue |
|
|
if rows: |
|
|
else: |
|
|
refresh = time.time() > (int(rows[0]['last_refreshed']) + MAX_ANIDB_AGE_SECS) |
|
|
if anime.name and anime.name != show.name: |
|
|
else: |
|
|
anidb_mainNames[show.indexerid] = [{anime.name: -1}] |
|
|
refresh = True |
|
|
|
|
|
|
|
|
|
|
|
if refresh: |
|
|
|
|
|
for show in sickbeard.showList: |
|
|
|
|
|
if show.is_anime and show.indexer == 1: |
|
|
|
|
|
try: |
|
|
|
|
|
anime = adba.Anime(None, name=show.name, tvdbid=show.indexerid, autoCorrectName=True) |
|
|
|
|
|
except: |
|
|
|
|
|
continue |
|
|
|
|
|
else: |
|
|
|
|
|
success = True |
|
|
|
|
|
|
|
|
|
|
|
if anime.name and anime.name != show.name: |
|
|
|
|
|
anidb_mainNames[show.indexerid] = [{anime.name: -1}] |
|
|
|
|
|
|
|
|
|
|
|
if success: |
|
|
|
|
|
cacheDB.action("INSERT OR REPLACE INTO scene_exceptions_refresh (list, last_refreshed) VALUES (?,?)", |
|
|
|
|
|
['anidb', time.time()]) |
|
|
|
|
|
|
|
|
return anidb_mainNames |
|
|
return anidb_mainNames |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _xem_excpetions_fetcher(indexer): |
|
|
def _xem_excpetions_fetcher(indexer): |
|
|
|
|
|
global MAX_XEM_AGE_SECS |
|
|
|
|
|
|
|
|
exception_dict = {} |
|
|
exception_dict = {} |
|
|
|
|
|
|
|
|
url = "http://thexem.de/map/allNames?origin=%s&seasonNumbers=1" % sickbeard.indexerApi(indexer).config['xem_origin'] |
|
|
cacheDB = db.DBConnection('cache.db') |
|
|
|
|
|
|
|
|
|
|
|
rows = cacheDB.select("SELECT last_refreshed FROM scene_exceptions_refresh WHERE list = ?", |
|
|
|
|
|
['xem']) |
|
|
|
|
|
if rows: |
|
|
|
|
|
refresh = time.time() > (int(rows[0]['last_refreshed']) + MAX_XEM_AGE_SECS) |
|
|
|
|
|
else: |
|
|
|
|
|
refresh = True |
|
|
|
|
|
|
|
|
|
|
|
if refresh: |
|
|
|
|
|
url = "http://thexem.de/map/allNames?origin=%s&seasonNumbers=1" % sickbeard.indexerApi(indexer).config['xem_origin'] |
|
|
|
|
|
|
|
|
|
|
|
url_data = helpers.getURL(url, json=True) |
|
|
|
|
|
if url_data is None: |
|
|
|
|
|
logger.log(u"Check scene exceptions update failed. Unable to get URL: " + url, logger.ERROR) |
|
|
|
|
|
return exception_dict |
|
|
|
|
|
|
|
|
url_data = helpers.getURL(url, json=True) |
|
|
if url_data['result'] == 'failure': |
|
|
if url_data is None: |
|
|
return exception_dict |
|
|
logger.log(u"Check scene exceptions update failed. Unable to get URL: " + url, logger.ERROR) |
|
|
|
|
|
return exception_dict |
|
|
|
|
|
|
|
|
|
|
|
if url_data['result'] == 'failure': |
|
|
cacheDB.action("INSERT OR REPLACE INTO scene_exceptions_refresh (list, last_refreshed) VALUES (?,?)", |
|
|
return exception_dict |
|
|
['xem', time.time()]) |
|
|
|
|
|
|
|
|
for indexerid, names in url_data['data'].items(): |
|
|
for indexerid, names in url_data['data'].items(): |
|
|
exception_dict[int(indexerid)] = names |
|
|
exception_dict[int(indexerid)] = names |
|
|
|
|
|
|
|
|
return exception_dict |
|
|
return exception_dict |
|
|
|
|
|
|
|
|