diff --git a/mylar/Failed.py b/mylar/Failed.py index 1999d7d2..e1879558 100644 --- a/mylar/Failed.py +++ b/mylar/Failed.py @@ -247,3 +247,40 @@ class FailedProcessor(object): else: logger.info(module + ' result has a status of ' + chk_fail['status'] + '. I am not sure what to do now.') return "nope" + + def markFailed(self): + #use this to forcibly mark a single issue as being Failed (ie. if a search result is sent to a client, but the result + #ends up passing in a 404 or something that makes it so that the download can't be initiated). + module = '[FAILED-DOWNLOAD]' + + myDB = db.DBConnection() + + logger.info(module + ' Marking as a Failed Download.') + + logger.fdebug(module + 'nzb_name: ' + self.nzb_name) + logger.fdebug(module + 'issueid: ' + str(self.issueid)) + logger.fdebug(module + 'nzb_id: ' + str(self.id)) + logger.fdebug(module + 'prov: ' + self.prov) + + if 'annual' in self.nzb_name.lower(): + logger.info(module + ' Annual detected.') + annchk = "yes" + issuenzb = myDB.selectone("SELECT * from annuals WHERE IssueID=? AND ComicName NOT NULL", [self.issueid]).fetchone() + else: + issuenzb = myDB.selectone("SELECT * from issues WHERE IssueID=? AND ComicName NOT NULL", [self.issueid]).fetchone() + + + ctrlVal = {"IssueID": self.issueid} + Vals = {"Status": 'Failed'} + myDB.upsert("issues", Vals, ctrlVal) + + ctrlVal = {"ID": self.id, + "Provider": self.prov, + "NZBName": self.nzb_name} + Vals = {"Status": 'Failed', + "ComicName": issuenzb['ComicName'], + "Issue_Number": issuenzb['Issue_Number']} + myDB.upsert("failed", Vals, ctrlVal) + + logger.info(module + ' Successfully marked as Failed.') + diff --git a/mylar/search.py b/mylar/search.py index 7b179c2b..199775bf 100755 --- a/mylar/search.py +++ b/mylar/search.py @@ -1693,8 +1693,12 @@ def searcher(nzbprov, nzbname, comicinfo, link, IssueID, ComicID, tmpprov, direc rcheck = rsscheck.torsend2client(ComicName, IssueNumber, comyear, link, nzbprov) if rcheck == "fail": - logger.error("Unable to send torrent - check logs and settings.") - return "torrent-fail" + if mylar.FAILED_DOWNLOAD_HANDLING: + logger.error('Unable to send torrent to client. Assuming incomplete link - sending to Failed Handler and continuing search.') + return FailedMark(ComicID=ComicID, IssueID=IssueID, id=nzbid, nzbname=nzbname, prov=nzbprov) + else: + logger.error('Unable to send torrent - check logs and settings (this would be marked as a BAD torrent if Failed Handling was enabled)') + return "torrent-fail" if mylar.TORRENT_LOCAL: sent_to = "your local Watch folder" else: @@ -1828,3 +1832,13 @@ def notify_snatch(nzbname, sent_to, modcomicname, comyear, IssueNumber, nzbprov) pushbullet.notify(snline=snline,snatched=nzbname,sent_to=sent_to,prov=nzbprov) return + +def FailedMark(IssueID, ComicID, id, nzbname, prov): + # Used to pass a failed attempt at sending a download to a client, to the failed handler, and then back again to continue searching. + + from mylar import Failed + + FailProcess = Failed.FailedProcessor(issueid=IssueID, comicid=ComicID, id=id, nzb_name=nzbname, prov=prov) + Markit = FailProcess.markFailed() + + return "torrent-fail"