Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Commit

Permalink
will now search for issues published in December, but dated in next y…
Browse files Browse the repository at this point in the history
…ear...also added some extra info to ComicRN.py
  • Loading branch information
evilhero committed Oct 9, 2012
1 parent a9936d4 commit 4c348c2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 21 deletions.
55 changes: 42 additions & 13 deletions mylar/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

from datetime import datetime

def search_init(ComicName, IssueNumber, ComicYear, SeriesYear):
def search_init(ComicName, IssueNumber, ComicYear, SeriesYear, IssueDate):
if ComicYear == None: ComicYear = '2012'
else: ComicYear = str(ComicYear)[:4]
##nzb provider selection##
Expand All @@ -57,15 +57,29 @@ def search_init(ComicName, IssueNumber, ComicYear, SeriesYear):
# --------
nzbpr = nzbp-1
findit = 'no'

#fix for issue dates between Dec/Jan
IssDt = str(IssueDate)[5:7]
if IssDt == "12":
ComicYearFix = str(int(ComicYear) + 1)
IssDateFix = "yes"
else:
IssDateFix = "no"

while (nzbpr >= 0 ):
if nzbprovider[nzbpr] == 'experimental':
#this is for experimental
nzbprov = 'experimental'
findit = NZB_SEARCH(ComicName, IssueNumber, ComicYear, SeriesYear, nzbprov, nzbpr)
findit = NZB_SEARCH(ComicName, IssueNumber, ComicYear, SeriesYear, nzbprov, nzbpr, IssDateFix)
if findit == 'yes':
break
else:
nzbpr-=1
if IssDateFix == "yes":
logger.info(u"Hang on - this issue was published between Dec/Jan of " + str(ComicYear) + "...adjusting to " + str(ComicYearFix) + " and retrying...")
findit = NZB_SEARCH(ComicName, IssueNumber, ComicYearFix, SeriesYear, nzbprov, nzbpr, IssDateFix)
if findit == 'yes':
break
nzbpr-=1

if nzbprovider[nzbpr] == 'nzb.su':
# ----
Expand All @@ -74,23 +88,35 @@ def search_init(ComicName, IssueNumber, ComicYear, SeriesYear):
#--LATER ?search.rss_find = RSS_SEARCH(ComicName, IssueNumber)
#if rss_find == 0:
nzbprov = 'nzb.su'
findit = NZB_SEARCH(ComicName, IssueNumber, ComicYear, SeriesYear, nzbprov, nzbpr)
findit = NZB_SEARCH(ComicName, IssueNumber, ComicYear, SeriesYear, nzbprov, nzbpr, IssDateFix)
if findit == 'yes':
break
else:
nzbpr-=1
if IssDateFix == "yes":
logger.info(u"Hang on - this issue was published between Dec/Jan of " + str(ComicYear) + "...adjusting to " + str(ComicYearFix) + " and retrying...")
findit = NZB_SEARCH(ComicName, IssueNumber, ComicYearFix, SeriesYear, nzbprov, nzbpr, IssDateFix)
if findit == 'yes':
break

nzbpr-=1
# ----

elif nzbprovider[nzbpr] == 'dognzb':
# this is for dognzb.com
#d = feedparser.parse("http://dognzb.cr/rss.cfm?r=" + str(dognzb_APIkey) + "&t=7030&num=100")
#RSS_SEARCH(ComicName, IssueNumber)
nzbprov = 'dognzb'
findit = NZB_SEARCH(ComicName, IssueNumber, ComicYear, SeriesYear, nzbprov, nzbpr)
findit = NZB_SEARCH(ComicName, IssueNumber, ComicYear, SeriesYear, nzbprov, nzbpr, IssDateFix)
if findit == 'yes':
break
else:
nzbpr-=1
if IssDateFix == "yes":
logger.info(u"Hang on - this issue was published between Dec/Jan of " + str(ComicYear) + "...adjusting to " + str(ComicYearFix) + " and retrying...")
findit = NZB_SEARCH(ComicName, IssueNumber, ComicYearFix, SeriesYear, nzbprov, nzbpr, IssDateFix)
if findit == 'yes':
break

nzbpr-=1
# ----
return findit

Expand Down Expand Up @@ -155,7 +181,7 @@ def RSS_Search(ComicName, IssueNumber):
print ("snatched " + str(ssabcount) + " out of " + str(tot) + " comics via rss...")
return ssabcount

def NZB_SEARCH(ComicName, IssueNumber, ComicYear, SeriesYear, nzbprov, nzbpr):
def NZB_SEARCH(ComicName, IssueNumber, ComicYear, SeriesYear, nzbprov, nzbpr, IssDateFix):
logger.info(u"Shhh be very quiet...I'm looking for " + ComicName + " issue: " + str(IssueNumber) + " using " + str(nzbprov))
if nzbprov == 'nzb.su':
apikey = mylar.NZBSU_APIKEY
Expand Down Expand Up @@ -392,7 +418,7 @@ def NZB_SEARCH(ComicName, IssueNumber, ComicYear, SeriesYear, nzbprov, nzbpr):
else:
#let's make the dir.
try:
os.makedirs(str(mylar.CACHE_DIR))
os.makedirs(str(mylar.CACHE_DIR))
logger.info(u"Cache Directory successfully created at: " + str(mylar.CACHE_DIR))
savefile = str(mylar.CACHE_DIR) + "/" + str(filenzb) + ".nzb"

Expand Down Expand Up @@ -539,8 +565,9 @@ def NZB_SEARCH(ComicName, IssueNumber, ComicYear, SeriesYear, nzbprov, nzbpr):
logger.info(u"More than one search provider given - trying next one.")
elif foundc == "no" and nzbpr == 0:
foundcomic.append("no")
logger.info(u"Couldn't find Issue " + str(IssueNumber) + " of " + str(ComicName) + "(" + str(comyear) + "). Status kept as wanted." )
break
if IssDateFix == "no":
logger.info(u"Couldn't find Issue " + str(IssueNumber) + " of " + str(ComicName) + "(" + str(comyear) + "). Status kept as wanted." )
break
return foundc

def searchforissue(issueid=None, new=False):
Expand All @@ -558,13 +585,14 @@ def searchforissue(issueid=None, new=False):
comic = myDB.action('SELECT * from comics WHERE ComicID=?', [result['ComicID']]).fetchone()
foundNZB = "none"
SeriesYear = comic['ComicYear']
IssueDate = result['IssueDate']
if result['IssueDate'] == None:
ComicYear = comic['ComicYear']
else:
ComicYear = str(result['IssueDate'])[:4]

if (mylar.NZBSU or mylar.DOGNZB or mylar.EXPERIMENTAL) and (mylar.SAB_HOST):
foundNZB = search_init(result['ComicName'], result['Issue_Number'], str(ComicYear), comic['ComicYear'])
foundNZB = search_init(result['ComicName'], result['Issue_Number'], str(ComicYear), comic['ComicYear'], IssueDate)
if foundNZB == "yes":
#print ("found!")
updater.foundsearch(result['ComicID'], result['IssueID'])
Expand All @@ -576,14 +604,15 @@ def searchforissue(issueid=None, new=False):
ComicID = result['ComicID']
comic = myDB.action('SELECT * FROM comics where ComicID=?', [ComicID]).fetchone()
SeriesYear = comic['ComicYear']
IssueDate = result['IssueDate']
if result['IssueDate'] == None:
IssueYear = comic['ComicYear']
else:
IssueYear = str(result['IssueDate'])[:4]

foundNZB = "none"
if (mylar.NZBSU or mylar.DOGNZB or mylar.EXPERIMENTAL) and (mylar.SAB_HOST):
foundNZB = search_init(result['ComicName'], result['Issue_Number'], str(IssueYear), comic['ComicYear'])
foundNZB = search_init(result['ComicName'], result['Issue_Number'], str(IssueYear), comic['ComicYear'], IssueDate)
if foundNZB == "yes":
#print ("found!")
updater.foundsearch(ComicID=result['ComicID'], IssueID=result['IssueID'])
Expand Down
10 changes: 5 additions & 5 deletions mylar/webserve.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ def markissues(self, ComicID=None, action=None, **args):
myDB.upsert("issues", newValueDict, controlValueDict)
if action == 'Skipped': pass
elif action == 'Wanted':
foundcoms = search.search_init(mi['ComicName'], mi['Issue_Number'], mi['IssueDate'][:4], miyr['ComicYear'])
foundcoms = search.search_init(mi['ComicName'], mi['Issue_Number'], mi['IssueDate'][:4], miyr['ComicYear'], mi['IssueDate'])
#searcher.searchforissue(mbid, new=False)
elif action == 'WantedNew':
foundcoms = search.search_init(mi['ComicName'], mi['Issue_Number'], mi['IssueDate'][:4], miyr['ComicYear'])
foundcoms = search.search_init(mi['ComicName'], mi['Issue_Number'], mi['IssueDate'][:4], miyr['ComicYear'], mi['IssueDate'])
#searcher.searchforissue(mbid, new=True)
if foundcoms == "yes":
logger.info(u"Found " + mi['ComicName'] + " issue: " + mi['Issue_Number'] + " ! Marking as Snatched...")
Expand Down Expand Up @@ -212,7 +212,7 @@ def queueissue(self, mode, ComicName=None, ComicID=None, ComicYear=None, ComicIs
ComicYear = str(cyear['SHIPDATE'])[:4]
if ComicYear == '': ComicYear = "2012"
logger.info(u"Marking " + ComicName + " " + ComicIssue + " as wanted...")
foundcom = search.search_init(ComicName, ComicIssue, ComicYear, SeriesYear=None)
foundcom = search.search_init(ComicName, ComicIssue, ComicYear, SeriesYear=None, cyear['SHIPDATE'])
if foundcom == "yes":
logger.info(u"Downloaded " + ComicName + " " + ComicIssue )
return
Expand All @@ -227,12 +227,12 @@ def queueissue(self, mode, ComicName=None, ComicID=None, ComicYear=None, ComicIs
newStatus = {"Status": "Wanted"}
myDB.upsert("issues", newStatus, controlValueDict)
#for future reference, the year should default to current year (.datetime)
issues = myDB.action("SELECT IssueDate FROM issues WHERE IssueID=?", [IssueID]).fetchone()
if ComicYear == None:
issues = myDB.action("SELECT IssueDate FROM issues WHERE IssueID=?", [IssueID]).fetchone()
ComicYear = str(issues['IssueDate'])[:4]
miyr = myDB.action("SELECT ComicYear FROM comics WHERE ComicID=?", [ComicID]).fetchone()
SeriesYear = miyr['ComicYear']
foundcom = search.search_init(ComicName, ComicIssue, ComicYear, SeriesYear)
foundcom = search.search_init(ComicName, ComicIssue, ComicYear, SeriesYear, issues['IssueDate'])
#print ("foundcom:" + str(foundcom))
if foundcom == "yes":
# file check to see if issue exists and update 'have' count
Expand Down
11 changes: 8 additions & 3 deletions sabnzbd/ComicRN.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
# directory of your SABnzbd install.

# In SABnzbd:
# create a category - call it whatever you want (ie.Comics).
# point the default dir to wherever you want - but make sure it is identical
# to the "Path to root of Comics directory" indicated in CONFIG below.
# Create a category - call it whatever you want (ie.Comics).
# Point the default dir to wherever you want - but make sure it is identical
# to the Mylar - "Comic Location" as indicated in the comdir CONFIG option
# below. Not doing this will mean that downloads that this script processed
# probably won't get marked as being present in Mylar.

# In Mylar:
# Sabnzbd tab (in the Configuration):
Expand Down Expand Up @@ -234,10 +236,13 @@
if maindir is not "/" or maindir is not comdir:
shutil.rmtree(maindir)
print ("Removed useless directory: " + maindir)
print ("Result: Completed")
else:
print ("incorrect directory passed to Removal: " + maindir)
print ("Result: FAIL - incorrect directory.")
else:
print ("Could not find a match for : " + str(comyx) )
print ("I compared it to : " + str(confile) )
print ("Result: FAIL - could not locate comic")
countit+=1

0 comments on commit 4c348c2

Please sign in to comment.