mirror of
https://github.com/moparisthebest/SickRage
synced 2024-12-13 03:22:22 -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 = int(indexer)
|
||||
|
||||
if xem_refresh_needed(indexer_id, indexer):
|
||||
xem_refresh(indexer_id, indexer)
|
||||
xem_refresh(indexer_id, indexer)
|
||||
|
||||
myDB = db.DBConnection()
|
||||
|
||||
@ -270,8 +269,7 @@ def find_xem_absolute_numbering(indexer_id, indexer, absolute_number):
|
||||
indexer_id = int(indexer_id)
|
||||
indexer = int(indexer)
|
||||
|
||||
if xem_refresh_needed(indexer_id, indexer):
|
||||
xem_refresh(indexer_id, indexer)
|
||||
xem_refresh(indexer_id, indexer)
|
||||
|
||||
myDB = db.DBConnection()
|
||||
|
||||
@ -298,8 +296,7 @@ def get_indexer_numbering_for_xem(indexer_id, indexer, sceneSeason, sceneEpisode
|
||||
indexer_id = int(indexer_id)
|
||||
indexer = int(indexer)
|
||||
|
||||
if xem_refresh_needed(indexer_id, indexer):
|
||||
xem_refresh(indexer_id, indexer)
|
||||
xem_refresh(indexer_id, indexer)
|
||||
|
||||
myDB = db.DBConnection()
|
||||
|
||||
@ -327,8 +324,7 @@ def get_indexer_absolute_numbering_for_xem(indexer_id, indexer, sceneAbsoluteNum
|
||||
indexer_id = int(indexer_id)
|
||||
indexer = int(indexer)
|
||||
|
||||
if xem_refresh_needed(indexer_id, indexer):
|
||||
xem_refresh(indexer_id, indexer)
|
||||
xem_refresh(indexer_id, indexer)
|
||||
|
||||
myDB = db.DBConnection()
|
||||
|
||||
@ -383,8 +379,7 @@ def get_xem_numbering_for_show(indexer_id, indexer):
|
||||
indexer_id = int(indexer_id)
|
||||
indexer = int(indexer)
|
||||
|
||||
if xem_refresh_needed(indexer_id, indexer):
|
||||
xem_refresh(indexer_id, indexer)
|
||||
xem_refresh(indexer_id, indexer)
|
||||
|
||||
myDB = db.DBConnection()
|
||||
|
||||
@ -444,8 +439,7 @@ def get_xem_absolute_numbering_for_show(indexer_id, indexer):
|
||||
indexer_id = int(indexer_id)
|
||||
indexer = int(indexer)
|
||||
|
||||
if xem_refresh_needed(indexer_id, indexer):
|
||||
xem_refresh(indexer_id, indexer)
|
||||
xem_refresh(indexer_id, indexer)
|
||||
|
||||
myDB = db.DBConnection()
|
||||
|
||||
@ -462,30 +456,7 @@ def get_xem_absolute_numbering_for_show(indexer_id, indexer):
|
||||
|
||||
return result
|
||||
|
||||
|
||||
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):
|
||||
def xem_refresh(indexer_id, indexer, force=False):
|
||||
"""
|
||||
Refresh data from xem for a tv show
|
||||
|
||||
@ -497,69 +468,78 @@ def xem_refresh(indexer_id, indexer):
|
||||
indexer_id = int(indexer_id)
|
||||
indexer = int(indexer)
|
||||
|
||||
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()
|
||||
myDB = db.DBConnection()
|
||||
|
||||
if data is None or data == '':
|
||||
logger.log(u'No XEN data for show "%s on %s", trying TVTumbler' % (
|
||||
indexer_id, sickbeard.indexerApi(indexer).name,), logger.MESSAGE)
|
||||
data = requests.get("http://show-api.tvtumbler.com/api/thexem/all?id=%s&origin=%s&destination=scene" % (
|
||||
rows = myDB.select("SELECT last_refreshed FROM xem_refresh WHERE indexer = ? and indexer_id = ?",
|
||||
[indexer, indexer_id])
|
||||
if rows:
|
||||
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()
|
||||
|
||||
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
|
||||
logger.log(u'No XEN data for show "%s on %s", trying TVTumbler' % (
|
||||
indexer_id, sickbeard.indexerApi(indexer).name,), logger.MESSAGE)
|
||||
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
|
||||
myDB = db.DBConnection()
|
||||
result = data
|
||||
|
||||
ql = []
|
||||
if result:
|
||||
ql.append(["INSERT OR REPLACE INTO xem_refresh (indexer, indexer_id, last_refreshed) VALUES (?,?,?)",
|
||||
[indexer, indexer_id, time.time()]])
|
||||
if 'success' in result['result']:
|
||||
for entry in result['data']:
|
||||
if 'scene' in entry:
|
||||
ql.append([
|
||||
"UPDATE tv_episodes SET scene_season = ?, scene_episode = ?, scene_absolute_number = ? WHERE showid = ? AND season = ? AND episode = ?",
|
||||
[entry['scene']['season'],
|
||||
entry['scene']['episode'],
|
||||
entry['scene']['absolute'],
|
||||
indexer_id,
|
||||
entry[sickbeard.indexerApi(indexer).config['xem_origin']]['season'],
|
||||
entry[sickbeard.indexerApi(indexer).config['xem_origin']]['episode']
|
||||
]])
|
||||
if 'scene_2' in entry: # for doubles
|
||||
ql.append([
|
||||
"UPDATE tv_episodes SET scene_season = ?, scene_episode = ?, scene_absolute_number = ? WHERE showid = ? AND season = ? AND episode = ?",
|
||||
[entry['scene_2']['season'],
|
||||
entry['scene_2']['episode'],
|
||||
entry['scene_2']['absolute'],
|
||||
indexer_id,
|
||||
entry[sickbeard.indexerApi(indexer).config['xem_origin']]['season'],
|
||||
entry[sickbeard.indexerApi(indexer).config['xem_origin']]['episode']
|
||||
]])
|
||||
ql = []
|
||||
if result:
|
||||
ql.append(["INSERT OR REPLACE INTO xem_refresh (indexer, indexer_id, last_refreshed) VALUES (?,?,?)",
|
||||
[indexer, indexer_id, time.time()]])
|
||||
if 'success' in result['result']:
|
||||
for entry in result['data']:
|
||||
if 'scene' in entry:
|
||||
ql.append([
|
||||
"UPDATE tv_episodes SET scene_season = ?, scene_episode = ?, scene_absolute_number = ? WHERE showid = ? AND season = ? AND episode = ?",
|
||||
[entry['scene']['season'],
|
||||
entry['scene']['episode'],
|
||||
entry['scene']['absolute'],
|
||||
indexer_id,
|
||||
entry[sickbeard.indexerApi(indexer).config['xem_origin']]['season'],
|
||||
entry[sickbeard.indexerApi(indexer).config['xem_origin']]['episode']
|
||||
]])
|
||||
if 'scene_2' in entry: # for doubles
|
||||
ql.append([
|
||||
"UPDATE tv_episodes SET scene_season = ?, scene_episode = ?, scene_absolute_number = ? WHERE showid = ? AND season = ? AND episode = ?",
|
||||
[entry['scene_2']['season'],
|
||||
entry['scene_2']['episode'],
|
||||
entry['scene_2']['absolute'],
|
||||
indexer_id,
|
||||
entry[sickbeard.indexerApi(indexer).config['xem_origin']]['season'],
|
||||
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:
|
||||
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:
|
||||
logger.log(u"Empty lookup result - no XEM data for show %s on %s" % (
|
||||
indexer_id, sickbeard.indexerApi(indexer).name,), logger.DEBUG)
|
||||
except Exception, e:
|
||||
logger.log(u"Exception while refreshing XEM data for show " + str(indexer_id) + " on " + sickbeard.indexerApi(
|
||||
indexer).name + ": " + ex(e), logger.WARNING)
|
||||
logger.log(traceback.format_exc(), logger.DEBUG)
|
||||
return None
|
||||
logger.log(u"Empty lookup result - no XEM data for show %s on %s" % (
|
||||
indexer_id, sickbeard.indexerApi(indexer).name,), logger.DEBUG)
|
||||
except Exception, e:
|
||||
logger.log(u"Exception while refreshing XEM data for show " + str(indexer_id) + " on " + sickbeard.indexerApi(
|
||||
indexer).name + ": " + ex(e), logger.WARNING)
|
||||
logger.log(traceback.format_exc(), logger.DEBUG)
|
||||
return None
|
||||
|
||||
if ql:
|
||||
myDB.mass_action(ql)
|
||||
if ql:
|
||||
myDB.mass_action(ql)
|
||||
|
||||
# fix xem scene numbering issues
|
||||
# fix_xem_numbering(indexer_id, indexer)
|
||||
# fix xem scene numbering issues
|
||||
# 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",
|
||||
[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 self.default_status == 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
|
||||
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()
|
||||
|
||||
def _finishEarly(self):
|
||||
@ -417,6 +416,9 @@ class QueueItemRefresh(ShowQueueItem):
|
||||
self.show.updateMetadata()
|
||||
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
|
||||
|
||||
|
||||
@ -486,10 +488,6 @@ class QueueItemUpdate(ShowQueueItem):
|
||||
|
||||
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)
|
||||
try:
|
||||
self.show.loadFromIndexer(cache=not self.force)
|
||||
@ -533,9 +531,7 @@ class QueueItemUpdate(ShowQueueItem):
|
||||
if IndexerEpList == None:
|
||||
logger.log(u"No data returned from " + sickbeard.indexerApi(
|
||||
self.show.indexer).name + ", unable to update this show", logger.ERROR)
|
||||
|
||||
else:
|
||||
|
||||
# for each ep we found on TVDB delete it from the DB list
|
||||
for curSeason in IndexerEpList:
|
||||
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):
|
||||
|
||||
# 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:
|
||||
self.episodes[season] = {}
|
||||
|
@ -2962,6 +2962,9 @@ class Home:
|
||||
|
||||
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()
|
||||
|
||||
seasonResults = myDB.select(
|
||||
@ -3318,7 +3321,7 @@ class Home:
|
||||
|
||||
if do_update_exceptions:
|
||||
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])
|
||||
except exceptions.CantUpdateException, e:
|
||||
errors.append("Unable to force an update on scene exceptions of the show.")
|
||||
|
Loading…
Reference in New Issue
Block a user