2014-05-15 04:16:46 +00:00
|
|
|
# Author: Nic Wolfe <nic@wolfeden.ca>
|
|
|
|
# URL: http://code.google.com/p/sickbeard/
|
|
|
|
#
|
2014-05-23 12:37:22 +00:00
|
|
|
# This file is part of SickRage.
|
2014-05-15 04:16:46 +00:00
|
|
|
#
|
2014-05-23 12:37:22 +00:00
|
|
|
# SickRage is free software: you can redistribute it and/or modify
|
2014-05-15 04:16:46 +00:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
2014-05-23 12:37:22 +00:00
|
|
|
# SickRage is distributed in the hope that it will be useful,
|
2014-05-15 04:16:46 +00:00
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2014-05-23 12:37:22 +00:00
|
|
|
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
|
2014-05-15 04:16:46 +00:00
|
|
|
|
|
|
|
from __future__ import with_statement
|
2014-05-26 20:16:07 +00:00
|
|
|
|
2014-05-15 04:16:46 +00:00
|
|
|
import datetime
|
|
|
|
import threading
|
|
|
|
|
|
|
|
import sickbeard
|
|
|
|
from sickbeard import logger
|
|
|
|
from sickbeard import db
|
|
|
|
from sickbeard import common
|
|
|
|
from sickbeard import helpers
|
|
|
|
from sickbeard import exceptions
|
2014-06-27 00:13:41 +00:00
|
|
|
from sickbeard.exceptions import ex
|
|
|
|
|
2014-05-15 04:16:46 +00:00
|
|
|
|
|
|
|
class DailySearcher():
|
|
|
|
def __init__(self):
|
|
|
|
self.lock = threading.Lock()
|
|
|
|
|
|
|
|
self.amActive = False
|
|
|
|
|
2014-06-30 17:48:18 +00:00
|
|
|
def __del__(self):
|
|
|
|
pass
|
|
|
|
|
2014-05-19 17:40:25 +00:00
|
|
|
def run(self, force=False):
|
|
|
|
|
|
|
|
self.amActive = True
|
2014-05-18 15:33:31 +00:00
|
|
|
|
2014-06-27 00:13:41 +00:00
|
|
|
providers = [x for x in sickbeard.providers.sortedProviderList() if x.isActive() and not x.backlog_only]
|
|
|
|
for curProviderCount, curProvider in enumerate(providers):
|
|
|
|
|
|
|
|
try:
|
|
|
|
logger.log(u"Updating [" + curProvider.name + "} RSS cache ...")
|
|
|
|
curProvider.cache.updateCache()
|
|
|
|
except exceptions.AuthException, e:
|
|
|
|
logger.log(u"Authentication error: " + ex(e), logger.ERROR)
|
|
|
|
if curProviderCount != len(providers):
|
|
|
|
continue
|
|
|
|
break
|
|
|
|
except Exception, e:
|
|
|
|
logger.log(u"Error while updating cache for " + curProvider.name + ", skipping: " + ex(e), logger.ERROR)
|
|
|
|
if curProviderCount != len(providers):
|
|
|
|
continue
|
|
|
|
break
|
|
|
|
|
2014-05-22 03:12:15 +00:00
|
|
|
logger.log(u"Searching for coming episodes and 1 weeks worth of previously WANTED episodes ...")
|
2014-05-15 04:16:46 +00:00
|
|
|
|
2014-05-18 16:54:03 +00:00
|
|
|
fromDate = datetime.date.today() - datetime.timedelta(weeks=1)
|
2014-05-22 03:12:15 +00:00
|
|
|
curDate = datetime.date.today()
|
2014-05-15 04:16:46 +00:00
|
|
|
|
2014-06-21 22:46:59 +00:00
|
|
|
myDB = db.DBConnection()
|
|
|
|
sqlResults = myDB.select("SELECT * FROM tv_episodes WHERE status in (?,?) AND airdate >= ? AND airdate <= ?",
|
|
|
|
[common.UNAIRED, common.WANTED, fromDate.toordinal(), curDate.toordinal()])
|
2014-05-15 04:16:46 +00:00
|
|
|
|
2014-05-30 10:01:49 +00:00
|
|
|
sql_l = []
|
2014-05-18 12:59:42 +00:00
|
|
|
todaysEps = {}
|
2014-05-15 04:16:46 +00:00
|
|
|
for sqlEp in sqlResults:
|
|
|
|
|
|
|
|
try:
|
|
|
|
show = helpers.findCertainShow(sickbeard.showList, int(sqlEp["showid"]))
|
|
|
|
except exceptions.MultipleShowObjectsException:
|
|
|
|
logger.log(u"ERROR: expected to find a single show matching " + sqlEp["showid"])
|
2014-05-26 21:20:31 +00:00
|
|
|
break
|
2014-05-15 04:16:46 +00:00
|
|
|
|
2014-05-26 21:20:31 +00:00
|
|
|
if not show:
|
2014-05-15 04:16:46 +00:00
|
|
|
logger.log(u"Unable to find the show with ID " + str(
|
|
|
|
sqlEp["showid"]) + " in your show list! DB value was " + str(sqlEp), logger.ERROR)
|
2014-05-26 21:20:31 +00:00
|
|
|
break
|
2014-05-15 04:16:46 +00:00
|
|
|
|
|
|
|
ep = show.getEpisode(sqlEp["season"], sqlEp["episode"])
|
|
|
|
with ep.lock:
|
|
|
|
if ep.show.paused:
|
|
|
|
ep.status = common.SKIPPED
|
2014-06-30 15:57:32 +00:00
|
|
|
|
|
|
|
if ep.status == common.UNAIRED:
|
|
|
|
logger.log(u"New episode " + ep.prettyName() + " airs today, setting status to WANTED")
|
|
|
|
ep.status = common.WANTED
|
2014-05-15 04:16:46 +00:00
|
|
|
|
2014-05-18 12:59:42 +00:00
|
|
|
if ep.status == common.WANTED:
|
|
|
|
if show not in todaysEps:
|
|
|
|
todaysEps[show] = [ep]
|
|
|
|
else:
|
|
|
|
todaysEps[show].append(ep)
|
|
|
|
|
2014-05-30 11:06:51 +00:00
|
|
|
sql_l.append(ep.get_sql())
|
2014-05-30 10:01:49 +00:00
|
|
|
|
2014-05-30 11:42:31 +00:00
|
|
|
if sql_l:
|
2014-06-21 22:46:59 +00:00
|
|
|
myDB = db.DBConnection()
|
|
|
|
myDB.mass_action(sql_l)
|
2014-06-30 15:57:32 +00:00
|
|
|
|
2014-05-30 10:01:49 +00:00
|
|
|
|
2014-05-18 12:59:42 +00:00
|
|
|
if len(todaysEps):
|
|
|
|
for show in todaysEps:
|
|
|
|
segment = todaysEps[show]
|
2014-05-26 18:07:10 +00:00
|
|
|
|
|
|
|
# remove show from name cache if marked invalid
|
|
|
|
sickbeard.name_cache.clearCache(show)
|
|
|
|
|
2014-05-18 12:59:42 +00:00
|
|
|
dailysearch_queue_item = sickbeard.search_queue.DailySearchQueueItem(show, segment)
|
2014-05-26 20:16:07 +00:00
|
|
|
sickbeard.searchQueueScheduler.action.add_item(dailysearch_queue_item)
|
2014-05-18 12:59:42 +00:00
|
|
|
else:
|
2014-05-26 21:20:31 +00:00
|
|
|
logger.log(u"Could not find any needed episodes to search for ...")
|
|
|
|
|
|
|
|
self.amActive = False
|