mirror of
https://github.com/SickGear/SickGear.git
synced 2024-12-03 18:03: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
|
@ -118,4 +118,6 @@ class QueueItem(threading.Thread):
|
||||||
def finish(self):
|
def finish(self):
|
||||||
"""Implementing Classes should call this"""
|
"""Implementing Classes should call this"""
|
||||||
|
|
||||||
self.inProgress = False
|
self.inProgress = False
|
||||||
|
|
||||||
|
threading.currentThread().name = self.name
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
|
import datetime
|
||||||
import sickbeard
|
import sickbeard
|
||||||
|
|
||||||
from lib import adba
|
from lib import adba
|
||||||
|
@ -42,16 +43,16 @@ def shouldRefresh(list):
|
||||||
myDB = db.DBConnection('cache.db')
|
myDB = db.DBConnection('cache.db')
|
||||||
rows = myDB.select("SELECT last_refreshed FROM scene_exceptions_refresh WHERE list = ?", [list])
|
rows = myDB.select("SELECT last_refreshed FROM scene_exceptions_refresh WHERE list = ?", [list])
|
||||||
if rows:
|
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:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def setLastRefresh(list):
|
def setLastRefresh(list):
|
||||||
myDB = db.DBConnection('cache.db')
|
myDB = db.DBConnection('cache.db')
|
||||||
myDB.action("INSERT OR REPLACE INTO scene_exceptions_refresh (list, last_refreshed) VALUES (?,?)",
|
myDB.upsert("scene_exceptions_refresh",
|
||||||
[list, time.time()])
|
{'last_refreshed': int(time.mktime(datetime.datetime.today().timetuple()))},
|
||||||
|
{'list': list})
|
||||||
|
|
||||||
def get_scene_exceptions(indexer_id, season=-1):
|
def get_scene_exceptions(indexer_id, season=-1):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -343,22 +343,24 @@ def filterSearchResults(show, season, results):
|
||||||
|
|
||||||
def searchForNeededEpisodes(show, episodes):
|
def searchForNeededEpisodes(show, episodes):
|
||||||
foundResults = {}
|
foundResults = {}
|
||||||
|
|
||||||
didSearch = False
|
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]
|
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):
|
for curProviderCount, curProvider in enumerate(providers):
|
||||||
if curProvider.anime_only and not show.is_anime:
|
if curProvider.anime_only and not show.is_anime:
|
||||||
logger.log(u"" + str(show.name) + " is not an anime skiping ...")
|
logger.log(u"" + str(show.name) + " is not an anime skiping ...")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
threading.currentThread().name = origThreadName + " :: [" + curProvider.name + "]"
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
logger.log(u"Searching RSS cache ...")
|
threading.currentThread().name = origThreadName + " :: [" + curProvider.name + "]"
|
||||||
curFoundResults = curProvider.searchRSS(episodes)
|
curFoundResults = curProvider.searchRSS(episodes)
|
||||||
|
threading.currentThread().name = origThreadName
|
||||||
except exceptions.AuthException, e:
|
except exceptions.AuthException, e:
|
||||||
logger.log(u"Authentication error: " + ex(e), logger.ERROR)
|
logger.log(u"Authentication error: " + ex(e), logger.ERROR)
|
||||||
if curProviderCount != len(providers):
|
if curProviderCount != len(providers):
|
||||||
|
@ -406,6 +408,12 @@ def searchProviders(show, season, episodes, manualSearch=False):
|
||||||
foundResults = {}
|
foundResults = {}
|
||||||
finalResults = []
|
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
|
# check if we want to search for season packs instead of just season/episode
|
||||||
seasonSearch = False
|
seasonSearch = False
|
||||||
if not manualSearch:
|
if not manualSearch:
|
||||||
|
@ -413,20 +421,12 @@ def searchProviders(show, season, episodes, manualSearch=False):
|
||||||
if len(seasonEps) == len(episodes):
|
if len(seasonEps) == len(episodes):
|
||||||
seasonSearch = True
|
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
|
origThreadName = threading.currentThread().name
|
||||||
for providerNum, provider in enumerate(providers):
|
for providerNum, provider in enumerate(providers):
|
||||||
if provider.anime_only and not show.is_anime:
|
if provider.anime_only and not show.is_anime:
|
||||||
logger.log(u"" + str(show.name) + " is not an anime skiping ...")
|
logger.log(u"" + str(show.name) + " is not an anime skiping ...")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
threading.currentThread().name = origThreadName + " :: [" + provider.name + "]"
|
|
||||||
foundResults.setdefault(provider.name, {})
|
foundResults.setdefault(provider.name, {})
|
||||||
searchCount = 0
|
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))
|
logger.log(u"Searching for episodes we need from " + show.name + " Season " + str(season))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
threading.currentThread().name = origThreadName + " :: [" + provider.name + "]"
|
||||||
searchResults = provider.findSearchResults(show, season, episodes, search_mode, manualSearch)
|
searchResults = provider.findSearchResults(show, season, episodes, search_mode, manualSearch)
|
||||||
|
threading.currentThread().name = origThreadName
|
||||||
except exceptions.AuthException, e:
|
except exceptions.AuthException, e:
|
||||||
logger.log(u"Authentication error: " + ex(e), logger.ERROR)
|
logger.log(u"Authentication error: " + ex(e), logger.ERROR)
|
||||||
break
|
break
|
||||||
|
|
|
@ -106,9 +106,6 @@ class DailySearchQueueItem(generic_queue.QueueItem):
|
||||||
logger.log("Beginning daily search for [" + self.show.name + "]")
|
logger.log("Beginning daily search for [" + self.show.name + "]")
|
||||||
foundResults = search.searchForNeededEpisodes(self.show, self.segment)
|
foundResults = search.searchForNeededEpisodes(self.show, self.segment)
|
||||||
|
|
||||||
# reset thread back to original name
|
|
||||||
threading.currentThread().name = self.name
|
|
||||||
|
|
||||||
if not len(foundResults):
|
if not len(foundResults):
|
||||||
logger.log(u"No needed episodes found during daily search for [" + self.show.name + "]")
|
logger.log(u"No needed episodes found during daily search for [" + self.show.name + "]")
|
||||||
else:
|
else:
|
||||||
|
@ -123,11 +120,9 @@ class DailySearchQueueItem(generic_queue.QueueItem):
|
||||||
generic_queue.QueueItem.finish(self)
|
generic_queue.QueueItem.finish(self)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.log(traceback.format_exc(), logger.DEBUG)
|
logger.log(traceback.format_exc(), logger.DEBUG)
|
||||||
threading.currentThread().name = self.name
|
|
||||||
|
|
||||||
self.finish()
|
self.finish()
|
||||||
|
|
||||||
|
|
||||||
class ManualSearchQueueItem(generic_queue.QueueItem):
|
class ManualSearchQueueItem(generic_queue.QueueItem):
|
||||||
def __init__(self, show, segment):
|
def __init__(self, show, segment):
|
||||||
generic_queue.QueueItem.__init__(self, 'Manual Search', MANUAL_SEARCH)
|
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() + "]")
|
logger.log("Beginning manual search for [" + self.segment.prettyName() + "]")
|
||||||
searchResult = search.searchProviders(self.show, self.segment.season, [self.segment], True)
|
searchResult = search.searchProviders(self.show, self.segment.season, [self.segment], True)
|
||||||
|
|
||||||
# reset thread back to original name
|
|
||||||
threading.currentThread().name = self.name
|
|
||||||
|
|
||||||
if searchResult:
|
if searchResult:
|
||||||
# just use the first result for now
|
# just use the first result for now
|
||||||
logger.log(u"Downloading " + searchResult[0].name + " from " + searchResult[0].provider.name)
|
logger.log(u"Downloading " + searchResult[0].name + " from " + searchResult[0].provider.name)
|
||||||
|
@ -163,16 +155,11 @@ class ManualSearchQueueItem(generic_queue.QueueItem):
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.log(traceback.format_exc(), logger.DEBUG)
|
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:
|
if self.success is None:
|
||||||
self.success = False
|
self.success = False
|
||||||
|
|
||||||
generic_queue.QueueItem.finish(self)
|
self.finish()
|
||||||
|
|
||||||
|
|
||||||
class BacklogQueueItem(generic_queue.QueueItem):
|
class BacklogQueueItem(generic_queue.QueueItem):
|
||||||
|
@ -197,9 +184,6 @@ class BacklogQueueItem(generic_queue.QueueItem):
|
||||||
logger.log("Beginning backlog search for [" + self.show.name + "]")
|
logger.log("Beginning backlog search for [" + self.show.name + "]")
|
||||||
searchResult = search.searchProviders(self.show, season, wantedEps, False)
|
searchResult = search.searchProviders(self.show, season, wantedEps, False)
|
||||||
|
|
||||||
# reset thread back to original name
|
|
||||||
threading.currentThread().name = self.name
|
|
||||||
|
|
||||||
if searchResult:
|
if searchResult:
|
||||||
for result in searchResult:
|
for result in searchResult:
|
||||||
# just use the first result for now
|
# just use the first result for now
|
||||||
|
@ -208,12 +192,10 @@ class BacklogQueueItem(generic_queue.QueueItem):
|
||||||
|
|
||||||
# give the CPU a break
|
# give the CPU a break
|
||||||
time.sleep(common.cpu_presets[sickbeard.CPU_PRESET])
|
time.sleep(common.cpu_presets[sickbeard.CPU_PRESET])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logger.log(u"No needed episodes found during backlog search for [" + self.show.name + "]")
|
logger.log(u"No needed episodes found during backlog search for [" + self.show.name + "]")
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.log(traceback.format_exc(), logger.DEBUG)
|
logger.log(traceback.format_exc(), logger.DEBUG)
|
||||||
threading.currentThread().name = self.name
|
|
||||||
|
|
||||||
self.finish()
|
self.finish()
|
||||||
|
|
||||||
|
@ -246,9 +228,6 @@ class FailedQueueItem(generic_queue.QueueItem):
|
||||||
|
|
||||||
searchResult = search.searchProviders(self.show, season, [epObj], True)
|
searchResult = search.searchProviders(self.show, season, [epObj], True)
|
||||||
|
|
||||||
# reset thread back to original name
|
|
||||||
threading.currentThread().name = self.name
|
|
||||||
|
|
||||||
if searchResult:
|
if searchResult:
|
||||||
for result in searchResult:
|
for result in searchResult:
|
||||||
# just use the first result for now
|
# 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() + "]")
|
logger.log(u"No valid episode found to retry for [" + epObj.prettyName() + "]")
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.log(traceback.format_exc(), logger.DEBUG)
|
logger.log(traceback.format_exc(), logger.DEBUG)
|
||||||
threading.currentThread().name = self.name
|
|
||||||
|
|
||||||
self.finish()
|
self.finish()
|
Loading…
Reference in a new issue