2014-05-15 00:16:46 -04:00
|
|
|
# Author: Nic Wolfe <nic@wolfeden.ca>
|
|
|
|
# URL: http://code.google.com/p/sickbeard/
|
|
|
|
#
|
2014-05-23 08:37:22 -04:00
|
|
|
# This file is part of SickRage.
|
2014-05-15 00:16:46 -04:00
|
|
|
#
|
2014-05-23 08:37:22 -04:00
|
|
|
# SickRage is free software: you can redistribute it and/or modify
|
2014-05-15 00:16:46 -04: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 08:37:22 -04:00
|
|
|
# SickRage is distributed in the hope that it will be useful,
|
2014-05-15 00:16:46 -04: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 08:37:22 -04:00
|
|
|
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
|
2014-05-15 00:16:46 -04:00
|
|
|
|
|
|
|
from __future__ import with_statement
|
2014-05-26 16:16:07 -04:00
|
|
|
|
2014-05-15 00:16:46 -04: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-26 20:13:41 -04:00
|
|
|
from sickbeard.exceptions import ex
|
|
|
|
|
2014-05-15 00:16:46 -04:00
|
|
|
|
|
|
|
class DailySearcher():
|
|
|
|
def __init__(self):
|
|
|
|
self.lock = threading.Lock()
|
|
|
|
|
|
|
|
self.amActive = False
|
|
|
|
|
2014-05-19 13:40:25 -04:00
|
|
|
def run(self, force=False):
|
|
|
|
|
|
|
|
self.amActive = True
|
2014-05-18 11:33:31 -04:00
|
|
|
|
2014-06-26 20:13:41 -04: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-21 23:12:15 -04:00
|
|
|
logger.log(u"Searching for coming episodes and 1 weeks worth of previously WANTED episodes ...")
|
2014-05-15 00:16:46 -04:00
|
|
|
|
2014-05-18 12:54:03 -04:00
|
|
|
fromDate = datetime.date.today() - datetime.timedelta(weeks=1)
|
2014-05-21 23:12:15 -04:00
|
|
|
curDate = datetime.date.today()
|
2014-05-15 00:16:46 -04:00
|
|
|
|
2014-06-21 18:46:59 -04: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 00:16:46 -04:00
|
|
|
|
2014-05-30 06:01:49 -04:00
|
|
|
sql_l = []
|
2014-05-18 08:59:42 -04:00
|
|
|
todaysEps = {}
|
2014-05-15 00:16:46 -04: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 17:20:31 -04:00
|
|
|
break
|
2014-05-15 00:16:46 -04:00
|
|
|
|
2014-05-26 17:20:31 -04:00
|
|
|
if not show:
|
2014-05-15 00:16:46 -04: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 17:20:31 -04:00
|
|
|
break
|
2014-05-15 00:16:46 -04:00
|
|
|
|
|
|
|
ep = show.getEpisode(sqlEp["season"], sqlEp["episode"])
|
|
|
|
with ep.lock:
|
|
|
|
if ep.show.paused:
|
|
|
|
ep.status = common.SKIPPED
|
2014-06-30 11:57:32 -04: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 00:16:46 -04:00
|
|
|
|
2014-05-18 08:59:42 -04:00
|
|
|
if ep.status == common.WANTED:
|
|
|
|
if show not in todaysEps:
|
|
|
|
todaysEps[show] = [ep]
|
|
|
|
else:
|
|
|
|
todaysEps[show].append(ep)
|
|
|
|
|
2014-05-30 07:06:51 -04:00
|
|
|
sql_l.append(ep.get_sql())
|
2014-05-30 06:01:49 -04:00
|
|
|
|
2014-05-30 07:42:31 -04:00
|
|
|
if sql_l:
|
2014-06-21 18:46:59 -04:00
|
|
|
myDB = db.DBConnection()
|
|
|
|
myDB.mass_action(sql_l)
|
2014-06-30 11:57:32 -04:00
|
|
|
|
2014-05-30 06:01:49 -04:00
|
|
|
|
2014-05-18 08:59:42 -04:00
|
|
|
if len(todaysEps):
|
|
|
|
for show in todaysEps:
|
|
|
|
segment = todaysEps[show]
|
2014-05-26 14:07:10 -04:00
|
|
|
|
2014-05-18 08:59:42 -04:00
|
|
|
dailysearch_queue_item = sickbeard.search_queue.DailySearchQueueItem(show, segment)
|
2014-05-26 16:16:07 -04:00
|
|
|
sickbeard.searchQueueScheduler.action.add_item(dailysearch_queue_item)
|
2014-05-18 08:59:42 -04:00
|
|
|
else:
|
2014-05-26 17:20:31 -04:00
|
|
|
logger.log(u"Could not find any needed episodes to search for ...")
|
|
|
|
|
|
|
|
self.amActive = False
|