mirror of
https://github.com/moparisthebest/SickRage
synced 2024-11-16 14:25:02 -05:00
Scene numbering now updates every 1 hour or is forced when needed so that searches always have up-to-date information before hand.
This commit is contained in:
parent
a2439c8c64
commit
1abef89b29
@ -241,8 +241,7 @@ def find_xem_numbering(indexer_id, indexer, season, episode):
|
|||||||
indexer_id = int(indexer_id)
|
indexer_id = int(indexer_id)
|
||||||
indexer = int(indexer)
|
indexer = int(indexer)
|
||||||
|
|
||||||
if xem_refresh_needed(indexer_id, indexer):
|
xem_refresh(indexer_id, indexer)
|
||||||
xem_refresh(indexer_id, indexer)
|
|
||||||
|
|
||||||
myDB = db.DBConnection()
|
myDB = db.DBConnection()
|
||||||
|
|
||||||
@ -270,8 +269,7 @@ def find_xem_absolute_numbering(indexer_id, indexer, absolute_number):
|
|||||||
indexer_id = int(indexer_id)
|
indexer_id = int(indexer_id)
|
||||||
indexer = int(indexer)
|
indexer = int(indexer)
|
||||||
|
|
||||||
if xem_refresh_needed(indexer_id, indexer):
|
xem_refresh(indexer_id, indexer)
|
||||||
xem_refresh(indexer_id, indexer)
|
|
||||||
|
|
||||||
myDB = db.DBConnection()
|
myDB = db.DBConnection()
|
||||||
|
|
||||||
@ -298,8 +296,7 @@ def get_indexer_numbering_for_xem(indexer_id, indexer, sceneSeason, sceneEpisode
|
|||||||
indexer_id = int(indexer_id)
|
indexer_id = int(indexer_id)
|
||||||
indexer = int(indexer)
|
indexer = int(indexer)
|
||||||
|
|
||||||
if xem_refresh_needed(indexer_id, indexer):
|
xem_refresh(indexer_id, indexer)
|
||||||
xem_refresh(indexer_id, indexer)
|
|
||||||
|
|
||||||
myDB = db.DBConnection()
|
myDB = db.DBConnection()
|
||||||
|
|
||||||
@ -327,8 +324,7 @@ def get_indexer_absolute_numbering_for_xem(indexer_id, indexer, sceneAbsoluteNum
|
|||||||
indexer_id = int(indexer_id)
|
indexer_id = int(indexer_id)
|
||||||
indexer = int(indexer)
|
indexer = int(indexer)
|
||||||
|
|
||||||
if xem_refresh_needed(indexer_id, indexer):
|
xem_refresh(indexer_id, indexer)
|
||||||
xem_refresh(indexer_id, indexer)
|
|
||||||
|
|
||||||
myDB = db.DBConnection()
|
myDB = db.DBConnection()
|
||||||
|
|
||||||
@ -383,8 +379,7 @@ def get_xem_numbering_for_show(indexer_id, indexer):
|
|||||||
indexer_id = int(indexer_id)
|
indexer_id = int(indexer_id)
|
||||||
indexer = int(indexer)
|
indexer = int(indexer)
|
||||||
|
|
||||||
if xem_refresh_needed(indexer_id, indexer):
|
xem_refresh(indexer_id, indexer)
|
||||||
xem_refresh(indexer_id, indexer)
|
|
||||||
|
|
||||||
myDB = db.DBConnection()
|
myDB = db.DBConnection()
|
||||||
|
|
||||||
@ -444,8 +439,7 @@ def get_xem_absolute_numbering_for_show(indexer_id, indexer):
|
|||||||
indexer_id = int(indexer_id)
|
indexer_id = int(indexer_id)
|
||||||
indexer = int(indexer)
|
indexer = int(indexer)
|
||||||
|
|
||||||
if xem_refresh_needed(indexer_id, indexer):
|
xem_refresh(indexer_id, indexer)
|
||||||
xem_refresh(indexer_id, indexer)
|
|
||||||
|
|
||||||
myDB = db.DBConnection()
|
myDB = db.DBConnection()
|
||||||
|
|
||||||
@ -462,30 +456,7 @@ def get_xem_absolute_numbering_for_show(indexer_id, indexer):
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def xem_refresh(indexer_id, indexer, force=False):
|
||||||
def xem_refresh_needed(indexer_id, indexer):
|
|
||||||
"""
|
|
||||||
Is a refresh needed on a show?
|
|
||||||
|
|
||||||
@param indexer_id: int
|
|
||||||
@return: bool
|
|
||||||
"""
|
|
||||||
if indexer_id is None:
|
|
||||||
return False
|
|
||||||
|
|
||||||
indexer_id = int(indexer_id)
|
|
||||||
indexer = int(indexer)
|
|
||||||
|
|
||||||
myDB = db.DBConnection()
|
|
||||||
rows = myDB.select("SELECT last_refreshed FROM xem_refresh WHERE indexer = ? and indexer_id = ?",
|
|
||||||
[indexer, indexer_id])
|
|
||||||
if rows:
|
|
||||||
return time.time() > (int(rows[0]['last_refreshed']) + MAX_XEM_AGE_SECS)
|
|
||||||
else:
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def xem_refresh(indexer_id, indexer):
|
|
||||||
"""
|
"""
|
||||||
Refresh data from xem for a tv show
|
Refresh data from xem for a tv show
|
||||||
|
|
||||||
@ -497,69 +468,78 @@ def xem_refresh(indexer_id, indexer):
|
|||||||
indexer_id = int(indexer_id)
|
indexer_id = int(indexer_id)
|
||||||
indexer = int(indexer)
|
indexer = int(indexer)
|
||||||
|
|
||||||
try:
|
myDB = db.DBConnection()
|
||||||
logger.log(
|
|
||||||
u'Looking up XEM scene mapping for show %s on %s' % (indexer_id, sickbeard.indexerApi(indexer).name,),
|
|
||||||
logger.DEBUG)
|
|
||||||
data = requests.get("http://thexem.de/map/all?id=%s&origin=%s&destination=scene" % (
|
|
||||||
indexer_id, sickbeard.indexerApi(indexer).config['xem_origin'],), verify=False).json()
|
|
||||||
|
|
||||||
if data is None or data == '':
|
rows = myDB.select("SELECT last_refreshed FROM xem_refresh WHERE indexer = ? and indexer_id = ?",
|
||||||
logger.log(u'No XEN data for show "%s on %s", trying TVTumbler' % (
|
[indexer, indexer_id])
|
||||||
indexer_id, sickbeard.indexerApi(indexer).name,), logger.MESSAGE)
|
if rows:
|
||||||
data = requests.get("http://show-api.tvtumbler.com/api/thexem/all?id=%s&origin=%s&destination=scene" % (
|
refresh = time.time() > (int(rows[0]['last_refreshed']) + MAX_XEM_AGE_SECS)
|
||||||
|
else:
|
||||||
|
refresh = True
|
||||||
|
|
||||||
|
if refresh or force:
|
||||||
|
try:
|
||||||
|
logger.log(
|
||||||
|
u'Looking up XEM scene mapping for show %s on %s' % (indexer_id, sickbeard.indexerApi(indexer).name,),
|
||||||
|
logger.DEBUG)
|
||||||
|
data = requests.get("http://thexem.de/map/all?id=%s&origin=%s&destination=scene" % (
|
||||||
indexer_id, sickbeard.indexerApi(indexer).config['xem_origin'],), verify=False).json()
|
indexer_id, sickbeard.indexerApi(indexer).config['xem_origin'],), verify=False).json()
|
||||||
|
|
||||||
if data is None or data == '':
|
if data is None or data == '':
|
||||||
logger.log(u'TVTumbler also failed for show "%s on %s". giving up.' % (indexer_id, indexer,),
|
logger.log(u'No XEN data for show "%s on %s", trying TVTumbler' % (
|
||||||
logger.MESSAGE)
|
indexer_id, sickbeard.indexerApi(indexer).name,), logger.MESSAGE)
|
||||||
return None
|
data = requests.get("http://show-api.tvtumbler.com/api/thexem/all?id=%s&origin=%s&destination=scene" % (
|
||||||
|
indexer_id, sickbeard.indexerApi(indexer).config['xem_origin'],), verify=False).json()
|
||||||
|
if data is None or data == '':
|
||||||
|
logger.log(u'TVTumbler also failed for show "%s on %s". giving up.' % (indexer_id, indexer,),
|
||||||
|
logger.MESSAGE)
|
||||||
|
return None
|
||||||
|
|
||||||
result = data
|
result = data
|
||||||
myDB = db.DBConnection()
|
|
||||||
|
|
||||||
ql = []
|
ql = []
|
||||||
if result:
|
if result:
|
||||||
ql.append(["INSERT OR REPLACE INTO xem_refresh (indexer, indexer_id, last_refreshed) VALUES (?,?,?)",
|
ql.append(["INSERT OR REPLACE INTO xem_refresh (indexer, indexer_id, last_refreshed) VALUES (?,?,?)",
|
||||||
[indexer, indexer_id, time.time()]])
|
[indexer, indexer_id, time.time()]])
|
||||||
if 'success' in result['result']:
|
if 'success' in result['result']:
|
||||||
for entry in result['data']:
|
for entry in result['data']:
|
||||||
if 'scene' in entry:
|
if 'scene' in entry:
|
||||||
ql.append([
|
ql.append([
|
||||||
"UPDATE tv_episodes SET scene_season = ?, scene_episode = ?, scene_absolute_number = ? WHERE showid = ? AND season = ? AND episode = ?",
|
"UPDATE tv_episodes SET scene_season = ?, scene_episode = ?, scene_absolute_number = ? WHERE showid = ? AND season = ? AND episode = ?",
|
||||||
[entry['scene']['season'],
|
[entry['scene']['season'],
|
||||||
entry['scene']['episode'],
|
entry['scene']['episode'],
|
||||||
entry['scene']['absolute'],
|
entry['scene']['absolute'],
|
||||||
indexer_id,
|
indexer_id,
|
||||||
entry[sickbeard.indexerApi(indexer).config['xem_origin']]['season'],
|
entry[sickbeard.indexerApi(indexer).config['xem_origin']]['season'],
|
||||||
entry[sickbeard.indexerApi(indexer).config['xem_origin']]['episode']
|
entry[sickbeard.indexerApi(indexer).config['xem_origin']]['episode']
|
||||||
]])
|
]])
|
||||||
if 'scene_2' in entry: # for doubles
|
if 'scene_2' in entry: # for doubles
|
||||||
ql.append([
|
ql.append([
|
||||||
"UPDATE tv_episodes SET scene_season = ?, scene_episode = ?, scene_absolute_number = ? WHERE showid = ? AND season = ? AND episode = ?",
|
"UPDATE tv_episodes SET scene_season = ?, scene_episode = ?, scene_absolute_number = ? WHERE showid = ? AND season = ? AND episode = ?",
|
||||||
[entry['scene_2']['season'],
|
[entry['scene_2']['season'],
|
||||||
entry['scene_2']['episode'],
|
entry['scene_2']['episode'],
|
||||||
entry['scene_2']['absolute'],
|
entry['scene_2']['absolute'],
|
||||||
indexer_id,
|
indexer_id,
|
||||||
entry[sickbeard.indexerApi(indexer).config['xem_origin']]['season'],
|
entry[sickbeard.indexerApi(indexer).config['xem_origin']]['season'],
|
||||||
entry[sickbeard.indexerApi(indexer).config['xem_origin']]['episode']
|
entry[sickbeard.indexerApi(indexer).config['xem_origin']]['episode']
|
||||||
]])
|
]])
|
||||||
|
else:
|
||||||
|
logger.log(u'Failed to get XEM scene data for show %s from %s because "%s"' % (
|
||||||
|
indexer_id, sickbeard.indexerApi(indexer).name, result['message']), logger.DEBUG)
|
||||||
else:
|
else:
|
||||||
logger.log(u'Failed to get XEM scene data for show %s from %s because "%s"' % (
|
logger.log(u"Empty lookup result - no XEM data for show %s on %s" % (
|
||||||
indexer_id, sickbeard.indexerApi(indexer).name, result['message']), logger.DEBUG)
|
indexer_id, sickbeard.indexerApi(indexer).name,), logger.DEBUG)
|
||||||
else:
|
except Exception, e:
|
||||||
logger.log(u"Empty lookup result - no XEM data for show %s on %s" % (
|
logger.log(u"Exception while refreshing XEM data for show " + str(indexer_id) + " on " + sickbeard.indexerApi(
|
||||||
indexer_id, sickbeard.indexerApi(indexer).name,), logger.DEBUG)
|
indexer).name + ": " + ex(e), logger.WARNING)
|
||||||
except Exception, e:
|
logger.log(traceback.format_exc(), logger.DEBUG)
|
||||||
logger.log(u"Exception while refreshing XEM data for show " + str(indexer_id) + " on " + sickbeard.indexerApi(
|
return None
|
||||||
indexer).name + ": " + ex(e), logger.WARNING)
|
|
||||||
logger.log(traceback.format_exc(), logger.DEBUG)
|
|
||||||
return None
|
|
||||||
|
|
||||||
if ql:
|
if ql:
|
||||||
myDB.mass_action(ql)
|
myDB.mass_action(ql)
|
||||||
|
|
||||||
# fix xem scene numbering issues
|
# fix xem scene numbering issues
|
||||||
# fix_xem_numbering(indexer_id, indexer)
|
# fix_xem_numbering(indexer_id, indexer)
|
||||||
|
|
||||||
|
|
||||||
def fix_xem_numbering(indexer_id, indexer):
|
def fix_xem_numbering(indexer_id, indexer):
|
||||||
|
@ -369,10 +369,6 @@ class QueueItemAdd(ShowQueueItem):
|
|||||||
myDB.action("UPDATE tv_episodes SET status = ? WHERE status = ? AND showid = ? AND season != 0",
|
myDB.action("UPDATE tv_episodes SET status = ? WHERE status = ? AND showid = ? AND season != 0",
|
||||||
[self.default_status, SKIPPED, self.show.indexerid])
|
[self.default_status, SKIPPED, self.show.indexerid])
|
||||||
|
|
||||||
# Load XEM data to DB for show
|
|
||||||
if sickbeard.scene_numbering.xem_refresh_needed(self.show.indexerid, self.show.indexer):
|
|
||||||
sickbeard.scene_numbering.xem_refresh(self.show.indexerid, self.show.indexer)
|
|
||||||
|
|
||||||
# if they started with WANTED eps then run the backlog
|
# if they started with WANTED eps then run the backlog
|
||||||
if self.default_status == WANTED:
|
if self.default_status == WANTED:
|
||||||
logger.log(u"Launching backlog for this show since its episodes are WANTED")
|
logger.log(u"Launching backlog for this show since its episodes are WANTED")
|
||||||
@ -387,6 +383,9 @@ class QueueItemAdd(ShowQueueItem):
|
|||||||
# if there are specific episodes that need to be added by trakt
|
# if there are specific episodes that need to be added by trakt
|
||||||
sickbeard.traktWatchListCheckerSchedular.action.manageNewShow(self.show)
|
sickbeard.traktWatchListCheckerSchedular.action.manageNewShow(self.show)
|
||||||
|
|
||||||
|
# Load XEM data to DB for show
|
||||||
|
sickbeard.scene_numbering.xem_refresh(self.show.indexerid, self.show.indexer, force=True)
|
||||||
|
|
||||||
self.finish()
|
self.finish()
|
||||||
|
|
||||||
def _finishEarly(self):
|
def _finishEarly(self):
|
||||||
@ -417,6 +416,9 @@ class QueueItemRefresh(ShowQueueItem):
|
|||||||
self.show.updateMetadata()
|
self.show.updateMetadata()
|
||||||
self.show.populateCache()
|
self.show.populateCache()
|
||||||
|
|
||||||
|
# Load XEM data to DB for show
|
||||||
|
sickbeard.scene_numbering.xem_refresh(self.show.indexerid, self.show.indexer, force=self.force)
|
||||||
|
|
||||||
self.inProgress = False
|
self.inProgress = False
|
||||||
|
|
||||||
|
|
||||||
@ -486,10 +488,6 @@ class QueueItemUpdate(ShowQueueItem):
|
|||||||
|
|
||||||
logger.log(u"Beginning update of " + self.show.name)
|
logger.log(u"Beginning update of " + self.show.name)
|
||||||
|
|
||||||
# Load XEM data to DB for show
|
|
||||||
if sickbeard.scene_numbering.xem_refresh_needed(self.show.indexerid, self.show.indexer) or self.force:
|
|
||||||
sickbeard.scene_numbering.xem_refresh(self.show.indexerid, self.show.indexer)
|
|
||||||
|
|
||||||
logger.log(u"Retrieving show info from " + sickbeard.indexerApi(self.show.indexer).name + "", logger.DEBUG)
|
logger.log(u"Retrieving show info from " + sickbeard.indexerApi(self.show.indexer).name + "", logger.DEBUG)
|
||||||
try:
|
try:
|
||||||
self.show.loadFromIndexer(cache=not self.force)
|
self.show.loadFromIndexer(cache=not self.force)
|
||||||
@ -533,9 +531,7 @@ class QueueItemUpdate(ShowQueueItem):
|
|||||||
if IndexerEpList == None:
|
if IndexerEpList == None:
|
||||||
logger.log(u"No data returned from " + sickbeard.indexerApi(
|
logger.log(u"No data returned from " + sickbeard.indexerApi(
|
||||||
self.show.indexer).name + ", unable to update this show", logger.ERROR)
|
self.show.indexer).name + ", unable to update this show", logger.ERROR)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
# for each ep we found on TVDB delete it from the DB list
|
# for each ep we found on TVDB delete it from the DB list
|
||||||
for curSeason in IndexerEpList:
|
for curSeason in IndexerEpList:
|
||||||
for curEpisode in IndexerEpList[curSeason]:
|
for curEpisode in IndexerEpList[curSeason]:
|
||||||
|
@ -198,8 +198,7 @@ class TVShow(object):
|
|||||||
def getEpisode(self, season=None, episode=None, file=None, noCreate=False, absolute_number=None):
|
def getEpisode(self, season=None, episode=None, file=None, noCreate=False, absolute_number=None):
|
||||||
|
|
||||||
# Load XEM data to DB for show
|
# Load XEM data to DB for show
|
||||||
if sickbeard.scene_numbering.xem_refresh_needed(self.indexerid, self.indexer):
|
sickbeard.scene_numbering.xem_refresh(self.indexerid, self.indexer)
|
||||||
sickbeard.scene_numbering.xem_refresh(self.indexerid, self.indexer)
|
|
||||||
|
|
||||||
if not season in self.episodes:
|
if not season in self.episodes:
|
||||||
self.episodes[season] = {}
|
self.episodes[season] = {}
|
||||||
|
@ -2962,6 +2962,9 @@ class Home:
|
|||||||
|
|
||||||
showObj.exceptions = scene_exceptions.get_scene_exceptions(showObj.indexerid)
|
showObj.exceptions = scene_exceptions.get_scene_exceptions(showObj.indexerid)
|
||||||
|
|
||||||
|
# Update scene numbering in DB
|
||||||
|
sickbeard.scene_numbering.xem_refresh(showObj.indexerid, showObj.indexer, True)
|
||||||
|
|
||||||
myDB = db.DBConnection()
|
myDB = db.DBConnection()
|
||||||
|
|
||||||
seasonResults = myDB.select(
|
seasonResults = myDB.select(
|
||||||
@ -3318,7 +3321,7 @@ class Home:
|
|||||||
|
|
||||||
if do_update_exceptions:
|
if do_update_exceptions:
|
||||||
try:
|
try:
|
||||||
scene_exceptions.update_scene_exceptions(showObj.indexerid, exceptions_list) # @UndefinedVariable
|
scene_exceptions.update_scene_exceptions(showObj.indexerid, exceptions_list, force=True) # @UndefinedVariable
|
||||||
time.sleep(cpu_presets[sickbeard.CPU_PRESET])
|
time.sleep(cpu_presets[sickbeard.CPU_PRESET])
|
||||||
except exceptions.CantUpdateException, e:
|
except exceptions.CantUpdateException, e:
|
||||||
errors.append("Unable to force an update on scene exceptions of the show.")
|
errors.append("Unable to force an update on scene exceptions of the show.")
|
||||||
|
Loading…
Reference in New Issue
Block a user