Fixed find propers.

Added ability to force a find propers search.
This commit is contained in:
echel0n 2014-05-19 10:40:25 -07:00
parent 621f790392
commit 854de69683
22 changed files with 107 additions and 37 deletions

View file

@ -29,7 +29,16 @@ Currently running<br />
<h3>Daily Search:</h3>
<a class="btn" href="$sbRoot/manage/manageSearches/forceSearch"><i class="icon-exclamation-sign"></i> Force</a>
#if not $searchStatus:
#if not $dailySearchStatus:
Not in progress<br />
#else:
In Progress<br />
#end if
<br />
<h3>Find Propers Search:</h3>
<a class="btn" href="$sbRoot/manage/manageSearches/forceFindPropers"><i class="icon-exclamation-sign"></i> Force</a>
#if not $findPropersStatus:
Not in progress<br />
#else:
In Progress<br />

View file

@ -26,7 +26,7 @@ from sickbeard import processTV
class PostProcesser():
def run(self):
def run(self, force=False):
if not sickbeard.PROCESS_AUTOMATICALLY:
return

View file

@ -38,7 +38,9 @@ class DailySearcher():
self.amActive = False
def run(self):
def run(self, force=False):
self.amActive = True
# remove names from cache that link back to active shows that we watch
sickbeard.name_cache.syncNameCache()

View file

@ -48,7 +48,7 @@ class GenericQueue:
self.queue.put(item)
return item
def run(self):
def run(self, force=False):
# only start a new task if one isn't already going
if self.thread == None or self.thread.isAlive() == False:

View file

@ -19,6 +19,7 @@
import time
import datetime
import operator
import threading
import sickbeard
@ -37,6 +38,7 @@ from name_parser.parser import NameParser, InvalidNameException
class ProperFinder():
def __init__(self):
self.amActive = False
self.updateInterval = datetime.timedelta(hours=1)
check_propers_interval = {'15m': 15, '45m': 45, '90m': 90, '4h': 4*60, 'daily': 24*60}
@ -44,7 +46,7 @@ class ProperFinder():
if sickbeard.CHECK_PROPERS_INTERVAL == curInterval:
self.updateInterval = datetime.timedelta(minutes = check_propers_interval[curInterval])
def run(self):
def run(self, force=False):
if not sickbeard.DOWNLOAD_PROPERS:
return
@ -57,16 +59,19 @@ class ProperFinder():
hourDiff = datetime.datetime.today().time().hour - updateTime.hour
dayDiff = (datetime.date.today() - self._get_lastProperSearch()).days
if sickbeard.CHECK_PROPERS_INTERVAL == "daily":
if sickbeard.CHECK_PROPERS_INTERVAL == "daily" and not force:
# if it's less than an interval after the update time then do an update
if not (hourDiff >= 0 and hourDiff < self.updateInterval.seconds / 3600 or dayDiff >= 1):
return
logger.log(u"Beginning the search for new propers")
self.amActive = True
propers = self._getProperList()
self._downloadPropers(propers)
if propers:
self._downloadPropers(propers)
self._set_lastProperSearch(datetime.datetime.today().toordinal())
@ -76,15 +81,16 @@ class ProperFinder():
else:
logger.log(u"%sin ~%s" % (msg, sickbeard.CHECK_PROPERS_INTERVAL))
def _getProperList(self):
self.amActive = False
def _getProperList(self):
propers = {}
# for each provider get a list of the propers
for curProvider in providers.sortedProviderList():
if not curProvider.isActive():
continue
# for each provider get a list of the
origThreadName = threading.currentThread().name
providers = [x for x in sickbeard.providers.sortedProviderList() if x.isActive()]
for curProvider in providers:
threading.currentThread().name = origThreadName + " :: [" + curProvider.name + "]"
search_date = datetime.datetime.today() - datetime.timedelta(days=2)
@ -97,25 +103,21 @@ class ProperFinder():
# if they haven't been added by a different provider than add the proper to the list
for x in curPropers:
showObj = helpers.findCertainShow(sickbeard.showList, x.indexerid)
if not showObj:
logger.log(u"Unable to find the show in our watch list " + str(x.name), logger.DEBUG)
continue
name = self._genericName(x.name)
if not name in propers:
logger.log(u"Found new proper: " + x.name, logger.DEBUG)
x.provider = curProvider
propers[name] = x
# reset thread name back to original
threading.currentThread().name = origThreadName
# take the list of unique propers and get it sorted by
sortedPropers = sorted(propers.values(), key=operator.attrgetter('date'), reverse=True)
finalPropers = []
for curProper in sortedPropers:
in_cache = False
# parse the file name
try:
myParser = NameParser(False)
parse_result = myParser.parse(curProper.name)
@ -126,23 +128,51 @@ class ProperFinder():
if not parse_result.series_name:
continue
cacheResult = sickbeard.name_cache.retrieveNameFromCache(parse_result.series_name)
if cacheResult:
in_cache = True
curProper.indexerid = int(cacheResult)
elif cacheResult == 0:
return None
if not curProper.indexerid:
showResult = helpers.searchDBForShow(parse_result.series_name)
if showResult:
curProper.indexerid = int(showResult[0])
if not curProper.indexerid:
for curShow in sickbeard.showList:
if show_name_helpers.isGoodResult(curProper.name, curShow, False):
curProper.indexerid = curShow.indexerid
break
showObj = None
if curProper.indexerid:
showObj = helpers.findCertainShow(sickbeard.showList, curProper.indexerid)
if not showObj:
sickbeard.name_cache.addNameToCache(parse_result.series_name, 0)
continue
if not in_cache:
sickbeard.name_cache.addNameToCache(parse_result.series_name, curProper.indexerid)
# scene numbering -> indexer numbering
parse_result = parse_result.convert(showObj)
if not parse_result.episode_numbers:
logger.log(
u"Ignoring " + curProper.name + " because it's for a full season rather than specific episode",
logger.DEBUG)
continue
# populate our Proper instance
if parse_result.air_by_date or parse_result.sports:
curProper.season = -1
curProper.episode = parse_result.air_date or parse_result.sports_event_date
else:
curProper.scene_season = parse_result.season_number if parse_result.season_number != None else 1
curProper.scene_episode = parse_result.episode_numbers[0]
curProper.season = parse_result.season_number if parse_result.season_number != None else 1
curProper.episode = parse_result.episode_numbers[0]
curProper.quality = Quality.nameQuality(curProper.name)
@ -214,11 +244,6 @@ class ProperFinder():
logger.log(u"Unable to find episode with date " + str(
curProper.episode) + " for show " + parse_result.series_name + ", skipping", logger.WARNING)
continue
else:
# items stored in cache are scene numbered, convert before lookups
epObj = showObj.getEpisode(curProper.season, curProper.episode)
curProper.season = epObj.season
curProper.episode = epObj.episode
# check if we actually want this proper (if it's the right quality)
sqlResults = db.DBConnection().select(

View file

@ -317,6 +317,7 @@ class HDTorrentsProvider(generic.TorrentProvider):
for sqlshow in sqlResults:
self.show = curshow = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if not self.show: continue
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
searchString = self._get_episode_search_strings(curEp, add_string='PROPER|REPACK')

View file

@ -262,6 +262,7 @@ class IPTorrentsProvider(generic.TorrentProvider):
for sqlshow in sqlResults:
self.show = curshow = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if not self.show: continue
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
searchString = self._get_episode_search_strings(curEp, add_string='PROPER|REPACK')

View file

@ -396,6 +396,7 @@ class KATProvider(generic.TorrentProvider):
for sqlshow in sqlResults:
self.show = curshow = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if not self.show: continue
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
searchString = self._get_episode_search_strings(curEp, add_string='PROPER|REPACK')

View file

@ -310,6 +310,7 @@ class NextGenProvider(generic.TorrentProvider):
for sqlshow in sqlResults:
self.show = curshow = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if not self.show: continue
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
searchString = self._get_episode_search_strings(curEp, add_string='PROPER|REPACK')

View file

@ -287,6 +287,7 @@ class PublicHDProvider(generic.TorrentProvider):
for sqlshow in sqlResults:
self.show = curshow = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if not self.show: continue
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
searchString = self._get_episode_search_strings(curEp, add_string='PROPER|REPACK')

View file

@ -302,6 +302,7 @@ class SCCProvider(generic.TorrentProvider):
for sqlshow in sqlResults:
self.show = curshow = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if not self.show: continue
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
searchString = self._get_episode_search_strings(curEp, add_string='PROPER|REPACK')

View file

@ -238,6 +238,7 @@ class SpeedCDProvider(generic.TorrentProvider):
for sqlshow in sqlResults:
self.show = curshow = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if not self.show: continue
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
searchString = self._get_episode_search_strings(curEp, add_string='PROPER|REPACK')

View file

@ -376,6 +376,7 @@ class ThePirateBayProvider(generic.TorrentProvider):
for sqlshow in sqlResults:
self.show = curshow = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if not self.show: continue
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
searchString = self._get_episode_search_strings(curEp, add_string='PROPER|REPACK')

View file

@ -265,6 +265,7 @@ class TorrentDayProvider(generic.TorrentProvider):
for sqlshow in sqlResults:
self.show = curshow = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if not self.show: continue
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
searchString = self._get_episode_search_strings(curEp, add_string='PROPER|REPACK')

View file

@ -261,6 +261,7 @@ class TorrentLeechProvider(generic.TorrentProvider):
for sqlshow in sqlResults:
self.show = curshow = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if not self.show: continue
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
searchString = self._get_episode_search_strings(curEp, add_string='PROPER|REPACK')

View file

@ -44,6 +44,7 @@ class Scheduler:
self.initThread()
self.abort = False
self.force = False
def initThread(self):
if self.thread == None or not self.thread.isAlive():
@ -55,6 +56,7 @@ class Scheduler:
def forceRun(self):
if not self.action.amActive:
self.lastRun = datetime.datetime.fromordinal(1)
self.force = True
return True
return False
@ -70,7 +72,7 @@ class Scheduler:
if not self.silent:
logger.log(u"Starting new thread: " + self.threadName, logger.DEBUG)
self.action.run()
self.action.run(self.force)
except Exception, e:
logger.log(u"Exception generated in thread " + self.threadName + ": " + ex(e), logger.ERROR)
logger.log(repr(traceback.format_exc()), logger.DEBUG)
@ -80,4 +82,7 @@ class Scheduler:
self.thread = None
return
if self.force:
self.force = False
time.sleep(1)

View file

@ -184,7 +184,7 @@ class BacklogSearcher:
myDB.action("UPDATE info SET last_backlog=" + str(when))
def run(self):
def run(self, force=False):
try:
self.searchBacklog()
except:

View file

@ -67,6 +67,13 @@ class SearchQueue(generic_queue.GenericQueue):
return True
return False
def is_dailysearch_in_progress(self):
queue = [x for x in self.queue.queue] + [self.currentItem]
for cur_item in queue:
if isinstance(cur_item, DailySearchQueueItem):
return True
return False
def add_item(self, item):
if isinstance(item, DailySearchQueueItem) and not self.is_in_queue(item.show, item.segment):

View file

@ -86,7 +86,7 @@ class SubtitlesFinder():
The SubtitlesFinder will be executed every hour but will not necessarly search
and download subtitles. Only if the defined rule is true
"""
def run(self):
def run(self, force=False):
# TODO: Put that in the __init__ before starting the thread?
if not sickbeard.USE_SUBTITLES:
logger.log(u'Subtitles support disabled', logger.DEBUG)

View file

@ -32,7 +32,7 @@ class TraktChecker():
self.todoWanted = []
self.todoBacklog = []
def run(self):
def run(self, force=False):
if sickbeard.TRAKT_USE_WATCHLIST:
self.todoWanted = [] #its about to all get re-added
if len(sickbeard.ROOT_DIRS.split('|')) < 2:

View file

@ -57,7 +57,7 @@ class CheckVersion():
else:
self.updater = None
def run(self):
def run(self, force=False):
updated = None
if self.check_for_new_version():
if sickbeard.AUTO_UPDATE:

View file

@ -206,7 +206,8 @@ class ManageSearches:
#t.backlogPI = sickbeard.backlogSearchScheduler.action.getProgressIndicator()
t.backlogPaused = sickbeard.searchQueueScheduler.action.is_backlog_paused() # @UndefinedVariable
t.backlogRunning = sickbeard.searchQueueScheduler.action.is_backlog_in_progress() # @UndefinedVariable
t.searchStatus = sickbeard.dailySearchScheduler.action.amActive # @UndefinedVariable
t.dailySearchStatus = sickbeard.searchQueueScheduler.action.is_dailysearch_in_progress() # @UndefinedVariable
t.findPropersStatus = sickbeard.properFinderScheduler.action.amActive # @UndefinedVariable
t.submenu = ManageMenu()
@ -231,7 +232,18 @@ class ManageSearches:
result = sickbeard.dailySearchScheduler.forceRun()
if result:
logger.log(u"Daily search forced")
ui.notifications.message('Daily search for new releases started')
ui.notifications.message('Daily search started')
redirect("/manage/manageSearches/")
@cherrypy.expose
def forceFindPropers(self):
# force it to run the next time it looks
result = sickbeard.properFinderScheduler.forceRun()
if result:
logger.log(u"Find propers search forced")
ui.notifications.message('Find propers search started')
redirect("/manage/manageSearches/")