2014-05-15 00:16:46 -04:00
|
|
|
# Author: Nic Wolfe <nic@wolfeden.ca>
|
|
|
|
# URL: http://code.google.com/p/sickbeard/
|
|
|
|
#
|
|
|
|
# This file is part of Sick Beard.
|
|
|
|
#
|
|
|
|
# Sick Beard is free software: you can redistribute it and/or modify
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# Sick Beard is distributed in the hope that it will be useful,
|
|
|
|
# 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
|
|
|
|
# along with Sick Beard. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
from __future__ import with_statement
|
|
|
|
import time
|
|
|
|
import datetime
|
|
|
|
import threading
|
|
|
|
import traceback
|
|
|
|
|
|
|
|
import sickbeard
|
|
|
|
from sickbeard import logger
|
|
|
|
from sickbeard import db
|
|
|
|
from sickbeard import common
|
|
|
|
from sickbeard import helpers
|
|
|
|
from sickbeard import exceptions
|
|
|
|
from sickbeard.exceptions import ex
|
|
|
|
from sickbeard.search import pickBestResult, snatchEpisode
|
|
|
|
from sickbeard import generic_queue
|
|
|
|
|
|
|
|
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-05-17 14:14:48 -04:00
|
|
|
# remove names from cache that link back to active shows that we watch
|
|
|
|
sickbeard.name_cache.syncNameCache()
|
|
|
|
|
2014-05-18 11:33:31 -04:00
|
|
|
logger.log(u"Updating RSS cache ...")
|
|
|
|
|
|
|
|
origThreadName = threading.currentThread().name
|
|
|
|
providers = [x for x in sickbeard.providers.sortedProviderList() if x.isActive()]
|
|
|
|
for curProviderCount, curProvider in enumerate(providers):
|
|
|
|
threading.currentThread().name = origThreadName + " :: [" + curProvider.name + "]"
|
|
|
|
|
2014-05-18 14:21:18 -04:00
|
|
|
try:
|
|
|
|
curProvider.cache.updateCache()
|
|
|
|
except exceptions.AuthException, e:
|
|
|
|
logger.log(u"Authentication error: " + ex(e), logger.ERROR)
|
|
|
|
continue
|
2014-05-18 11:33:31 -04:00
|
|
|
|
2014-05-18 08:59:42 -04:00
|
|
|
logger.log(u"Checking to see if any shows have wanted episodes available for the last week ...")
|
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-18 13:14:21 -04:00
|
|
|
toDate = datetime.date.today() + datetime.timedelta(days=1)
|
2014-05-15 00:16:46 -04:00
|
|
|
|
|
|
|
myDB = db.DBConnection()
|
2014-05-18 13:14:21 -04:00
|
|
|
sqlResults = myDB.select("SELECT * FROM tv_episodes WHERE status in (?,?) AND airdate >= ? AND airdate < ?",
|
2014-05-18 12:54:03 -04:00
|
|
|
[common.UNAIRED, common.WANTED, fromDate.toordinal(), toDate.toordinal()])
|
2014-05-15 00:16:46 -04:00
|
|
|
|
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"])
|
|
|
|
return None
|
|
|
|
|
|
|
|
if show == None:
|
|
|
|
logger.log(u"Unable to find the show with ID " + str(
|
|
|
|
sqlEp["showid"]) + " in your show list! DB value was " + str(sqlEp), logger.ERROR)
|
|
|
|
return None
|
|
|
|
|
|
|
|
ep = show.getEpisode(sqlEp["season"], sqlEp["episode"])
|
|
|
|
with ep.lock:
|
|
|
|
if ep.show.paused:
|
|
|
|
ep.status = common.SKIPPED
|
|
|
|
else:
|
2014-05-18 08:59:42 -04:00
|
|
|
if ep.status == common.UNAIRED:
|
|
|
|
ep.status = common.WANTED
|
2014-05-15 00:16:46 -04:00
|
|
|
|
2014-05-18 08:59:42 -04:00
|
|
|
ep.saveToDB()
|
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-18 11:33:31 -04:00
|
|
|
# reset thread name back to original
|
|
|
|
threading.currentThread().name = origThreadName
|
|
|
|
|
2014-05-18 08:59:42 -04:00
|
|
|
if len(todaysEps):
|
|
|
|
for show in todaysEps:
|
|
|
|
segment = todaysEps[show]
|
|
|
|
dailysearch_queue_item = sickbeard.search_queue.DailySearchQueueItem(show, segment)
|
|
|
|
sickbeard.searchQueueScheduler.action.add_item(dailysearch_queue_item) #@UndefinedVariable
|
|
|
|
else:
|
|
|
|
logger.log(u"Could not find any wanted show episodes going back 1 week at this current time ...")
|