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
|
2014-07-24 16:12:29 +00:00
|
|
|
import traceback
|
2014-05-15 04:16:46 +00:00
|
|
|
|
|
|
|
import sickbeard
|
|
|
|
from sickbeard import logger
|
|
|
|
from sickbeard import db
|
|
|
|
from sickbeard import common
|
|
|
|
from sickbeard import helpers
|
|
|
|
from sickbeard import exceptions
|
2014-11-05 11:33:05 +00:00
|
|
|
from sickbeard import network_timezones
|
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-05-19 17:40:25 +00:00
|
|
|
def run(self, force=False):
|
|
|
|
|
|
|
|
self.amActive = True
|
2014-05-18 15:33:31 +00:00
|
|
|
|
2014-09-15 08:57:50 +00:00
|
|
|
logger.log(u"Searching for new released episodes ...")
|
2014-07-24 19:05:49 +00:00
|
|
|
|
2014-11-05 11:33:05 +00:00
|
|
|
if not network_timezones.network_dict:
|
|
|
|
network_timezones.update_network_dict()
|
|
|
|
|
|
|
|
if network_timezones.network_dict:
|
|
|
|
curDate = (datetime.date.today() + datetime.timedelta(days=1)).toordinal()
|
|
|
|
else:
|
|
|
|
curDate = (datetime.date.today() - datetime.timedelta(days=2)).toordinal()
|
|
|
|
|
|
|
|
curTime = datetime.datetime.now(network_timezones.sb_timezone)
|
2014-06-27 00:13:41 +00:00
|
|
|
|
2014-08-30 08:47:00 +00:00
|
|
|
myDB = db.DBConnection()
|
|
|
|
sqlResults = myDB.select("SELECT * FROM tv_episodes WHERE status = ? AND season > 0 AND airdate <= ?",
|
|
|
|
[common.UNAIRED, curDate])
|
2014-07-24 16:12:29 +00:00
|
|
|
|
2014-08-30 08:47:00 +00:00
|
|
|
sql_l = []
|
2014-09-07 05:01:24 +00:00
|
|
|
show = None
|
|
|
|
|
2014-08-30 08:47:00 +00:00
|
|
|
for sqlEp in sqlResults:
|
2014-06-27 00:13:41 +00:00
|
|
|
try:
|
2014-09-15 08:28:11 +00:00
|
|
|
if not show or int(sqlEp["showid"]) != show.indexerid:
|
2014-09-07 05:01:24 +00:00
|
|
|
show = helpers.findCertainShow(sickbeard.showList, int(sqlEp["showid"]))
|
|
|
|
|
2014-09-25 15:12:16 +00:00
|
|
|
# for when there is orphaned series in the database but not loaded into our showlist
|
|
|
|
if not show:
|
|
|
|
continue
|
|
|
|
|
2014-08-30 08:47:00 +00:00
|
|
|
except exceptions.MultipleShowObjectsException:
|
2014-11-05 11:33:05 +00:00
|
|
|
logger.log(u"ERROR: expected to find a single show matching " + str(sqlEp['showid']))
|
|
|
|
continue
|
|
|
|
|
|
|
|
try:
|
|
|
|
end_time = network_timezones.parse_date_time(sqlEp['airdate'], show.airs, show.network) + datetime.timedelta(minutes=helpers.tryInt(show.runtime, 60))
|
|
|
|
# filter out any episodes that haven't aried yet
|
|
|
|
if end_time > curTime:
|
|
|
|
continue
|
|
|
|
except:
|
|
|
|
# if an error occured assume the episode hasn't aired yet
|
2014-07-24 16:12:29 +00:00
|
|
|
continue
|
2014-05-15 04:16:46 +00:00
|
|
|
|
2014-08-30 08:47:00 +00:00
|
|
|
ep = show.getEpisode(int(sqlEp["season"]), int(sqlEp["episode"]))
|
|
|
|
with ep.lock:
|
|
|
|
if ep.show.paused:
|
|
|
|
ep.status = common.SKIPPED
|
|
|
|
else:
|
|
|
|
ep.status = common.WANTED
|
2014-05-15 04:16:46 +00:00
|
|
|
|
2014-08-30 08:47:00 +00:00
|
|
|
sql_l.append(ep.get_sql())
|
2014-09-15 08:57:50 +00:00
|
|
|
else:
|
|
|
|
logger.log(u"No new released episodes found ...")
|
2014-06-30 15:57:32 +00:00
|
|
|
|
2014-08-30 08:47:00 +00:00
|
|
|
if len(sql_l) > 0:
|
2014-07-24 19:05:49 +00:00
|
|
|
myDB = db.DBConnection()
|
2014-08-30 08:47:00 +00:00
|
|
|
myDB.mass_action(sql_l)
|
|
|
|
|
2014-09-20 12:03:48 +00:00
|
|
|
# queue episode for daily search
|
|
|
|
dailysearch_queue_item = sickbeard.search_queue.DailySearchQueueItem()
|
|
|
|
sickbeard.searchQueueScheduler.action.add_item(dailysearch_queue_item)
|
2014-06-30 15:57:32 +00:00
|
|
|
|
2014-05-26 21:20:31 +00:00
|
|
|
self.amActive = False
|