mirror of
https://github.com/SickGear/SickGear.git
synced 2024-12-11 05:33:37 +00:00
Updated scene exception code for checking when last refreshed.
This commit is contained in:
parent
e0e10dd289
commit
c25da850ab
4 changed files with 26 additions and 43 deletions
|
@ -119,3 +119,5 @@ class QueueItem(threading.Thread):
|
|||
"""Implementing Classes should call this"""
|
||||
|
||||
self.inProgress = False
|
||||
|
||||
threading.currentThread().name = self.name
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
import re
|
||||
import time
|
||||
import threading
|
||||
import datetime
|
||||
import sickbeard
|
||||
|
||||
from lib import adba
|
||||
|
@ -42,16 +43,16 @@ def shouldRefresh(list):
|
|||
myDB = db.DBConnection('cache.db')
|
||||
rows = myDB.select("SELECT last_refreshed FROM scene_exceptions_refresh WHERE list = ?", [list])
|
||||
if rows:
|
||||
return time.time() > (int(rows[0]['last_refreshed']) + MAX_REFRESH_AGE_SECS)
|
||||
lastRefresh = int(rows[0]['last_refreshed'])
|
||||
return int(time.mktime(datetime.datetime.today().timetuple())) > lastRefresh + MAX_REFRESH_AGE_SECS
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def setLastRefresh(list):
|
||||
myDB = db.DBConnection('cache.db')
|
||||
myDB.action("INSERT OR REPLACE INTO scene_exceptions_refresh (list, last_refreshed) VALUES (?,?)",
|
||||
[list, time.time()])
|
||||
|
||||
myDB.upsert("scene_exceptions_refresh",
|
||||
{'last_refreshed': int(time.mktime(datetime.datetime.today().timetuple()))},
|
||||
{'list': list})
|
||||
|
||||
def get_scene_exceptions(indexer_id, season=-1):
|
||||
"""
|
||||
|
|
|
@ -343,22 +343,24 @@ def filterSearchResults(show, season, results):
|
|||
|
||||
def searchForNeededEpisodes(show, episodes):
|
||||
foundResults = {}
|
||||
|
||||
didSearch = False
|
||||
|
||||
# ask all providers for any episodes it finds
|
||||
origThreadName = threading.currentThread().name
|
||||
providers = [x for x in sickbeard.providers.sortedProviderList() if x.isActive() and not x.backlog_only]
|
||||
if not len(providers):
|
||||
logger.log(u"No NZB/Torrent providers found or enabled in the sickrage config. Please check your settings.",
|
||||
logger.ERROR)
|
||||
return
|
||||
|
||||
origThreadName = threading.currentThread().name
|
||||
for curProviderCount, curProvider in enumerate(providers):
|
||||
if curProvider.anime_only and not show.is_anime:
|
||||
logger.log(u"" + str(show.name) + " is not an anime skiping ...")
|
||||
continue
|
||||
|
||||
threading.currentThread().name = origThreadName + " :: [" + curProvider.name + "]"
|
||||
|
||||
try:
|
||||
logger.log(u"Searching RSS cache ...")
|
||||
threading.currentThread().name = origThreadName + " :: [" + curProvider.name + "]"
|
||||
curFoundResults = curProvider.searchRSS(episodes)
|
||||
threading.currentThread().name = origThreadName
|
||||
except exceptions.AuthException, e:
|
||||
logger.log(u"Authentication error: " + ex(e), logger.ERROR)
|
||||
if curProviderCount != len(providers):
|
||||
|
@ -406,6 +408,12 @@ def searchProviders(show, season, episodes, manualSearch=False):
|
|||
foundResults = {}
|
||||
finalResults = []
|
||||
|
||||
providers = [x for x in sickbeard.providers.sortedProviderList() if x.isActive()]
|
||||
if not len(providers):
|
||||
logger.log(u"No NZB/Torrent providers found or enabled in the sickrage config. Please check your settings.",
|
||||
logger.ERROR)
|
||||
return
|
||||
|
||||
# check if we want to search for season packs instead of just season/episode
|
||||
seasonSearch = False
|
||||
if not manualSearch:
|
||||
|
@ -413,20 +421,12 @@ def searchProviders(show, season, episodes, manualSearch=False):
|
|||
if len(seasonEps) == len(episodes):
|
||||
seasonSearch = True
|
||||
|
||||
providers = [x for x in sickbeard.providers.sortedProviderList() if x.isActive()]
|
||||
|
||||
if not len(providers):
|
||||
logger.log(u"No NZB/Torrent providers found or enabled in the sickrage config. Please check your settings.",
|
||||
logger.ERROR)
|
||||
return
|
||||
|
||||
origThreadName = threading.currentThread().name
|
||||
for providerNum, provider in enumerate(providers):
|
||||
if provider.anime_only and not show.is_anime:
|
||||
logger.log(u"" + str(show.name) + " is not an anime skiping ...")
|
||||
continue
|
||||
|
||||
threading.currentThread().name = origThreadName + " :: [" + provider.name + "]"
|
||||
foundResults.setdefault(provider.name, {})
|
||||
searchCount = 0
|
||||
|
||||
|
@ -443,7 +443,9 @@ def searchProviders(show, season, episodes, manualSearch=False):
|
|||
logger.log(u"Searching for episodes we need from " + show.name + " Season " + str(season))
|
||||
|
||||
try:
|
||||
threading.currentThread().name = origThreadName + " :: [" + provider.name + "]"
|
||||
searchResults = provider.findSearchResults(show, season, episodes, search_mode, manualSearch)
|
||||
threading.currentThread().name = origThreadName
|
||||
except exceptions.AuthException, e:
|
||||
logger.log(u"Authentication error: " + ex(e), logger.ERROR)
|
||||
break
|
||||
|
|
|
@ -106,9 +106,6 @@ class DailySearchQueueItem(generic_queue.QueueItem):
|
|||
logger.log("Beginning daily search for [" + self.show.name + "]")
|
||||
foundResults = search.searchForNeededEpisodes(self.show, self.segment)
|
||||
|
||||
# reset thread back to original name
|
||||
threading.currentThread().name = self.name
|
||||
|
||||
if not len(foundResults):
|
||||
logger.log(u"No needed episodes found during daily search for [" + self.show.name + "]")
|
||||
else:
|
||||
|
@ -123,11 +120,9 @@ class DailySearchQueueItem(generic_queue.QueueItem):
|
|||
generic_queue.QueueItem.finish(self)
|
||||
except Exception:
|
||||
logger.log(traceback.format_exc(), logger.DEBUG)
|
||||
threading.currentThread().name = self.name
|
||||
|
||||
self.finish()
|
||||
|
||||
|
||||
class ManualSearchQueueItem(generic_queue.QueueItem):
|
||||
def __init__(self, show, segment):
|
||||
generic_queue.QueueItem.__init__(self, 'Manual Search', MANUAL_SEARCH)
|
||||
|
@ -144,9 +139,6 @@ class ManualSearchQueueItem(generic_queue.QueueItem):
|
|||
logger.log("Beginning manual search for [" + self.segment.prettyName() + "]")
|
||||
searchResult = search.searchProviders(self.show, self.segment.season, [self.segment], True)
|
||||
|
||||
# reset thread back to original name
|
||||
threading.currentThread().name = self.name
|
||||
|
||||
if searchResult:
|
||||
# just use the first result for now
|
||||
logger.log(u"Downloading " + searchResult[0].name + " from " + searchResult[0].provider.name)
|
||||
|
@ -163,16 +155,11 @@ class ManualSearchQueueItem(generic_queue.QueueItem):
|
|||
|
||||
except Exception:
|
||||
logger.log(traceback.format_exc(), logger.DEBUG)
|
||||
threading.currentThread().name = self.name
|
||||
|
||||
self.finish()
|
||||
|
||||
def finish(self):
|
||||
# don't let this linger if something goes wrong
|
||||
if self.success is None:
|
||||
self.success = False
|
||||
|
||||
generic_queue.QueueItem.finish(self)
|
||||
self.finish()
|
||||
|
||||
|
||||
class BacklogQueueItem(generic_queue.QueueItem):
|
||||
|
@ -197,9 +184,6 @@ class BacklogQueueItem(generic_queue.QueueItem):
|
|||
logger.log("Beginning backlog search for [" + self.show.name + "]")
|
||||
searchResult = search.searchProviders(self.show, season, wantedEps, False)
|
||||
|
||||
# reset thread back to original name
|
||||
threading.currentThread().name = self.name
|
||||
|
||||
if searchResult:
|
||||
for result in searchResult:
|
||||
# just use the first result for now
|
||||
|
@ -208,12 +192,10 @@ class BacklogQueueItem(generic_queue.QueueItem):
|
|||
|
||||
# give the CPU a break
|
||||
time.sleep(common.cpu_presets[sickbeard.CPU_PRESET])
|
||||
|
||||
else:
|
||||
logger.log(u"No needed episodes found during backlog search for [" + self.show.name + "]")
|
||||
except Exception:
|
||||
logger.log(traceback.format_exc(), logger.DEBUG)
|
||||
threading.currentThread().name = self.name
|
||||
|
||||
self.finish()
|
||||
|
||||
|
@ -246,9 +228,6 @@ class FailedQueueItem(generic_queue.QueueItem):
|
|||
|
||||
searchResult = search.searchProviders(self.show, season, [epObj], True)
|
||||
|
||||
# reset thread back to original name
|
||||
threading.currentThread().name = self.name
|
||||
|
||||
if searchResult:
|
||||
for result in searchResult:
|
||||
# just use the first result for now
|
||||
|
@ -262,6 +241,5 @@ class FailedQueueItem(generic_queue.QueueItem):
|
|||
logger.log(u"No valid episode found to retry for [" + epObj.prettyName() + "]")
|
||||
except Exception:
|
||||
logger.log(traceback.format_exc(), logger.DEBUG)
|
||||
threading.currentThread().name = self.name
|
||||
|
||||
self.finish()
|
Loading…
Reference in a new issue