2014-03-10 05:18:05 +00:00
|
|
|
# Author: Tyler Fenby <tylerfenby@gmail.com>
|
|
|
|
# URL: http://code.google.com/p/sickbeard/
|
|
|
|
#
|
2014-05-23 12:37:22 +00:00
|
|
|
# This file is part of SickRage.
|
2014-03-10 05:18:05 +00:00
|
|
|
#
|
2014-05-23 12:37:22 +00:00
|
|
|
# SickRage is free software: you can redistribute it and/or modify
|
2014-03-10 05:18:05 +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-03-10 05:18:05 +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
|
|
|
|
|
|
|
|
from __future__ import with_statement
|
|
|
|
|
|
|
|
import sickbeard
|
|
|
|
from sickbeard import logger
|
|
|
|
from sickbeard import exceptions
|
|
|
|
from sickbeard import show_name_helpers
|
|
|
|
from sickbeard import search_queue
|
2014-07-06 13:11:04 +00:00
|
|
|
from sickbeard.name_parser.parser import NameParser, InvalidNameException, InvalidShowException
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
class FailedProcessor(object):
|
|
|
|
"""Take appropriate action when a download fails to complete"""
|
|
|
|
|
|
|
|
def __init__(self, dirName, nzbName):
|
|
|
|
"""
|
|
|
|
dirName: Full path to the folder of the failed download
|
|
|
|
nzbName: Full name of the nzb file that failed
|
|
|
|
"""
|
|
|
|
self.dir_name = dirName
|
|
|
|
self.nzb_name = nzbName
|
|
|
|
|
|
|
|
self.log = ""
|
|
|
|
|
|
|
|
def process(self):
|
|
|
|
self._log(u"Failed download detected: (" + str(self.nzb_name) + ", " + str(self.dir_name) + ")")
|
|
|
|
|
|
|
|
releaseName = show_name_helpers.determineReleaseName(self.dir_name, self.nzb_name)
|
|
|
|
if releaseName is None:
|
|
|
|
self._log(u"Warning: unable to find a valid release name.", logger.WARNING)
|
|
|
|
raise exceptions.FailedProcessingFailed()
|
|
|
|
|
|
|
|
try:
|
2014-05-31 10:35:57 +00:00
|
|
|
parser = NameParser(False, convert=True)
|
|
|
|
parsed = parser.parse(releaseName)
|
2014-03-10 05:18:05 +00:00
|
|
|
except InvalidNameException:
|
2014-07-15 02:00:53 +00:00
|
|
|
self._log(u"Error: release name is invalid: " + releaseName, logger.DEBUG)
|
2014-03-10 05:18:05 +00:00
|
|
|
raise exceptions.FailedProcessingFailed()
|
2014-07-06 13:11:04 +00:00
|
|
|
except InvalidShowException:
|
2014-07-15 02:00:53 +00:00
|
|
|
self._log(u"Error: unable to parse release name " + releaseName + " into a valid show", logger.DEBUG)
|
|
|
|
raise exceptions.FailedProcessingFailed()
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
logger.log(u"name_parser info: ", logger.DEBUG)
|
|
|
|
logger.log(u" - " + str(parsed.series_name), logger.DEBUG)
|
|
|
|
logger.log(u" - " + str(parsed.season_number), logger.DEBUG)
|
|
|
|
logger.log(u" - " + str(parsed.episode_numbers), logger.DEBUG)
|
|
|
|
logger.log(u" - " + str(parsed.extra_info), logger.DEBUG)
|
|
|
|
logger.log(u" - " + str(parsed.release_group), logger.DEBUG)
|
|
|
|
logger.log(u" - " + str(parsed.air_date), logger.DEBUG)
|
2014-05-30 07:36:47 +00:00
|
|
|
|
2014-03-19 14:59:34 +00:00
|
|
|
for episode in parsed.episode_numbers:
|
2014-09-07 04:36:23 +00:00
|
|
|
segment = parsed.show.getEpisode(parsed.season_number, episode)
|
2014-05-03 09:23:26 +00:00
|
|
|
|
2014-09-17 10:24:54 +00:00
|
|
|
cur_failed_queue_item = search_queue.FailedQueueItem(parsed.show, [segment])
|
2014-09-07 04:36:23 +00:00
|
|
|
sickbeard.searchQueueScheduler.action.add_item(cur_failed_queue_item)
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
def _log(self, message, level=logger.MESSAGE):
|
|
|
|
"""Log to regular logfile and save for return for PP script log"""
|
|
|
|
logger.log(message, level)
|
2014-05-02 10:09:17 +00:00
|
|
|
self.log += message + "\n"
|