self._log('Failed download has been detected: '+self.nzb_name+' in '+self.nzb_folder)
#since this has already been passed through the search module, which holds the IssueID in the nzblog,
#let's find the matching nzbname and pass it the IssueID in order to mark it as Failed and then return
#to the search module and continue trucking along.
nzbname=self.nzb_name
#remove extensions from nzb_name if they somehow got through (Experimental most likely)
extensions=('.cbr','.cbz')
ifnzbname.lower().endswith(extensions):
fd,ext=os.path.splitext(nzbname)
self._log("Removed extension from nzb: "+ext)
nzbname=re.sub(str(ext),'',str(nzbname))
#replace spaces
nzbname=re.sub('','.',str(nzbname))
nzbname=re.sub('[\,\:\?]','',str(nzbname))
nzbname=re.sub('[\&]','and',str(nzbname))
logger.fdebug(module+' After conversions, nzbname is : '+str(nzbname))
self._log("nzbname: "+str(nzbname))
nzbiss=myDB.selectone("SELECT * from nzblog WHERE nzbname=?",[nzbname]).fetchone()
ifnzbissisNone:
self._log("Failure - could not initially locate nzbfile in my database to rename.")
logger.fdebug(module+' Failure - could not locate nzbfile initially')
# if failed on spaces, change it all to decimals and try again.
nzbname=re.sub('_','.',str(nzbname))
self._log("trying again with this nzbname: "+str(nzbname))
logger.fdebug(module+' Trying to locate nzbfile again with nzbname of : '+str(nzbname))
nzbiss=myDB.selectone("SELECT * from nzblog WHERE nzbname=?",[nzbname]).fetchone()
ifnzbissisNone:
logger.error(module+' Unable to locate downloaded file to rename. PostProcessing aborted.')
self._log('Unable to locate downloaded file to rename. PostProcessing aborted.')
self.valreturn.append({"self.log":self.log,
"mode":'stop'})
returnself.queue.put(self.valreturn)
else:
self._log("I corrected and found the nzb as : "+str(nzbname))
logger.fdebug(module+' Auto-corrected and found the nzb as : '+str(nzbname))
issueid=nzbiss['IssueID']
else:
issueid=nzbiss['IssueID']
logger.fdebug(module+' Issueid: '+str(issueid))
sarc=nzbiss['SARC']
#use issueid to get publisher, series, year, issue number
else:
issueid=self.issueid
nzbiss=myDB.selectone("SELECT * from nzblog WHERE IssueID=?",[issueid]).fetchone()
ifnzbissisNone:
logger.info(module+' Cannot locate corresponding record in download history. This will be implemented soon.')
self.valreturn.append({"self.log":self.log,
"mode":'stop'})
returnself.queue.put(self.valreturn)
nzbname=nzbiss['NZBName']
# find the provider.
self.prov=nzbiss['PROVIDER']
logger.info(module+' Provider: '+self.prov)
# grab the id.
self.id=nzbiss['ID']
logger.info(module+' ID: '+self.id)
annchk="no"
if'annual'innzbname.lower():
logger.info(module+' Annual detected.')
annchk="yes"
issuenzb=myDB.selectone("SELECT * from annuals WHERE IssueID=? AND ComicName NOT NULL",[issueid]).fetchone()
else:
issuenzb=myDB.selectone("SELECT * from issues WHERE IssueID=? AND ComicName NOT NULL",[issueid]).fetchone()
ifissuenzbisnotNone:
logger.info(module+' issuenzb found.')
ifhelpers.is_number(issueid):
sandwich=int(issuenzb['IssueID'])
else:
logger.info(module+' issuenzb not found.')
#if it's non-numeric, it contains a 'G' at the beginning indicating it's a multi-volume
#using GCD data. Set sandwich to 1 so it will bypass and continue post-processing.
if'S'inissueid:
sandwich=issueid
elif'G'inissueidor'-'inissueid:
sandwich=1
ifhelpers.is_number(sandwich):
ifsandwich<900000:
# if sandwich is less than 900000 it's a normal watchlist download. Bypass.
pass
else:
logger.info('Failed download handling for story-arcs and one-off\'s are not supported yet. Be patient!')
self._log(' Unable to locate downloaded file to rename. PostProcessing aborted.')
self.valreturn.append({"self.log":self.log,
"mode":'stop'})
returnself.queue.put(self.valreturn)
comicid=issuenzb['ComicID']
issuenumOG=issuenzb['Issue_Number']
logger.info(module+' Successfully detected as : '+issuenzb['ComicName']+' issue: '+str(issuenzb['Issue_Number'])+' that was downloaded using '+self.prov)
self._log('Successfully detected as : '+issuenzb['ComicName']+' issue: '+str(issuenzb['Issue_Number'])+' downloaded using '+self.prov)
logger.info(module+' Marking as a Failed Download.')
self._log('Marking as a Failed Download.')
ctrlVal={"IssueID":issueid}
Vals={"Status":'Failed'}
myDB.upsert("issues",Vals,ctrlVal)
ctrlVal={"ID":self.id,
"Provider":self.prov,
"NZBName":nzbname}
Vals={"Status":'Failed',
"ComicName":issuenzb['ComicName'],
"Issue_Number":issuenzb['Issue_Number']}
myDB.upsert("failed",Vals,ctrlVal)
logger.info(module+' Successfully marked as Failed.')
self._log('Successfully marked as Failed.')
ifmylar.FAILED_AUTO:
logger.info(module+' Sending back to search to see if we can find something that will not fail.')
self._log('Sending back to search to see if we can find something better that will not fail.')
self.valreturn.append({"self.log":self.log,
"mode":'retry',
"issueid":issueid,
"comicid":comicid,
"comicname":issuenzb['ComicName'],
"issuenumber":issuenzb['Issue_Number'],
"annchk":annchk})
returnself.queue.put(self.valreturn)
else:
logger.info(module+' Stopping search here as automatic handling of failed downloads is not enabled *hint*')
self._log('Stopping search here as automatic handling of failed downloads is not enabled *hint*')