IMP: Alternate File Naming can now be configured on a per-series basis, which will rename series' accordingly when manual renaming or post-processing (both downloaded & manual), FIX: Will now better handle filenames that contain a # to denote an issue numbering (file-checking), FIX: When manually renaming, if issue numbering had a trailing decimal would error out, FIX: When parsing search results, if an nzb had a ' in the title, would be incorrectly accounted for - will now be able to match these series' more reliably

This commit is contained in:
evilhero 2015-01-24 03:33:54 -05:00
parent 91e41039a6
commit e80c39c085
7 changed files with 86 additions and 47 deletions

View File

@ -293,6 +293,13 @@
<small>Alternate comic names to be searched in case naming is different (ie. Hack/Slash = hack-slash)</small>
</div>
<div class="row">
<label>Alternate File-Naming</label>
<input type="text" name="alt_filename" value="${comic['AlternateFileName']}" size="90">
<a href="#" title="Alternate File Naming"><img src="interfaces/default/images/info32.png" height="16" alt="" /></a>
<small>Alternate file-naming to be used when post-processing / renaming files instead of the actual title.</small>
</div>
<div class="row">
<%
year_options = "Default - Keep the Year as is\nYear Removal - Remove issue publication year from searches (dangerous)\nFuzzy the Year - Increase & Decrease the issue publication year by one"

View File

@ -723,6 +723,11 @@ class PostProcessor(object):
series = comicnzb['ComicName'].encode('ascii', 'ignore').strip()
self._log("Series: " + series)
logger.fdebug(module + ' Series: ' + str(series))
if comicnzb['AlternateFileName']:
seriesfilename = comicnzb['AlternateFileName'].encode('ascii', 'ignore').strip()
logger.fdebug(module + ' Alternate File Naming has been enabled for this series. Will rename series to : ' + seriesfilename)
else:
seriesfilename = series
seriesyear = comicnzb['ComicYear']
self._log("Year: " + seriesyear)
logger.fdebug(module + ' Year: ' + str(seriesyear))
@ -828,7 +833,7 @@ class PostProcessor(object):
#rename file and move to new path
#nfilename = series + " " + issueno + " (" + seriesyear + ")"
file_values = {'$Series': series,
file_values = {'$Series': seriesfilename,
'$Issue': prettycomiss,
'$Year': issueyear,
'$series': series.lower(),
@ -859,19 +864,19 @@ class PostProcessor(object):
except:
logger.error(module + ' unable to set root folder. Forcing it due to some error above most likely.')
odir = self.nzb_folder
logger.fdebug(module + ' odir: ' + str(odir))
logger.fdebug(module + ' ofilename: ' + str(ofilename))
logger.fdebug(module + ' odir: ' + odir)
logger.fdebug(module + ' ofilename: ' + ofilename)
else:
if pcheck == "fail":
otofilename = ml['ComicLocation']
logger.fdebug(module + ' otofilename:' + str(otofilename))
logger.fdebug(module + ' otofilename:' + otofilename)
odir, ofilename = os.path.split(otofilename)
logger.fdebug(module + ' odir: ' + str(odir))
logger.fdebug(module + ' ofilename: ' + str(ofilename))
logger.fdebug(module + ' odir: ' + odir)
logger.fdebug(module + ' ofilename: ' + ofilename)
path, ext = os.path.splitext(ofilename)
logger.fdebug(module + ' path: ' + str(path))
logger.fdebug(module + ' ext:' + str(ext))
logger.fdebug(module + ' path: ' + path)
logger.fdebug(module + ' ext:' + ext)
if ofilename is None:
logger.error(module + ' Aborting PostProcessing - the filename does not exist in the location given. Make sure that ' + str(self.nzb_folder) + ' exists and is the correct location.')
@ -880,8 +885,8 @@ class PostProcessor(object):
return self.queue.put(self.valreturn)
self._log("Original Filename: " + ofilename)
self._log("Original Extension: " + ext)
logger.fdebug(module + ' Original Filname: ' + str(ofilename))
logger.fdebug(module + ' Original Extension: ' + str(ext))
logger.fdebug(module + ' Original Filename: ' + ofilename)
logger.fdebug(module + ' Original Extension: ' + ext)
if mylar.FILE_FORMAT == '' or not mylar.RENAME_FILES:
self._log("Rename Files isn't enabled...keeping original filename.")
@ -911,26 +916,26 @@ class PostProcessor(object):
dst = os.path.join(comlocation, (nfilename + ext.lower()))
self._log("Source:" + src)
self._log("Destination:" + dst)
logger.fdebug(module + ' Source: ' + str(src))
logger.fdebug(module + ' Destination: ' + str(dst))
logger.fdebug(module + ' Source: ' + src)
logger.fdebug(module + ' Destination: ' + dst)
if ml is None:
#downtype = for use with updater on history table to set status to 'Downloaded'
downtype = 'True'
#non-manual run moving/deleting...
logger.fdebug(module + ' self.nzb_folder: ' + self.nzb_folder)
logger.fdebug(module + ' odir: ' + str(odir))
logger.fdebug(module + ' ofilename:' + str(ofilename))
logger.fdebug(module + ' nfilename:' + str(nfilename + ext))
logger.fdebug(module + ' odir: ' + odir)
logger.fdebug(module + ' ofilename:' + ofilename)
logger.fdebug(module + ' nfilename:' + nfilename + ext)
if mylar.RENAME_FILES:
if str(ofilename) != str(nfilename + ext):
logger.fdebug(module + ' Renaming ' + os.path.join(odir, str(ofilename)) + ' ..to.. ' + os.path.join(odir,str(nfilename + ext)))
os.rename(os.path.join(odir, str(ofilename)), os.path.join(odir,str(nfilename + ext)))
logger.fdebug(module + ' Renaming ' + os.path.join(odir, ofilename) + ' ..to.. ' + os.path.join(odir,nfilename + ext))
os.rename(os.path.join(odir, ofilename), os.path.join(odir,nfilename + ext))
else:
logger.fdebug(module + ' Filename is identical as original, not renaming.')
#src = os.path.join(self.nzb_folder, str(nfilename + ext))
src = os.path.join(odir, str(nfilename + ext))
src = os.path.join(odir, nfilename + ext)
try:
shutil.move(src, dst)
except (OSError, IOError):
@ -965,8 +970,8 @@ class PostProcessor(object):
os.rename(os.path.join(odir, str(ofilename)), os.path.join(odir ,str(nfilename + ext)))
else:
logger.fdebug(module + ' Filename is identical as original, not renaming.')
src = os.path.join(odir, str(nfilename + ext))
logger.fdebug(module + ' odir src : ' + os.path.join(odir, str(nfilename + ext)))
src = os.path.join(odir, nfilename + ext)
logger.fdebug(module + ' odir src : ' + os.path.join(odir, nfilename + ext))
logger.fdebug(module + ' Moving ' + src + ' ... to ... ' + dst)
try:
shutil.move(src, dst)

View File

@ -1388,7 +1388,7 @@ def dbcheck():
c_error = 'sqlite3.OperationalError'
c=conn.cursor()
c.execute('CREATE TABLE IF NOT EXISTS comics (ComicID TEXT UNIQUE, ComicName TEXT, ComicSortName TEXT, ComicYear TEXT, DateAdded TEXT, Status TEXT, IncludeExtras INTEGER, Have INTEGER, Total INTEGER, ComicImage TEXT, ComicPublisher TEXT, ComicLocation TEXT, ComicPublished TEXT, LatestIssue TEXT, LatestDate TEXT, Description TEXT, QUALalt_vers TEXT, QUALtype TEXT, QUALscanner TEXT, QUALquality TEXT, LastUpdated TEXT, AlternateSearch TEXT, UseFuzzy TEXT, ComicVersion TEXT, SortOrder INTEGER, DetailURL TEXT, ForceContinuing INTEGER, ComicName_Filesafe TEXT)')
c.execute('CREATE TABLE IF NOT EXISTS comics (ComicID TEXT UNIQUE, ComicName TEXT, ComicSortName TEXT, ComicYear TEXT, DateAdded TEXT, Status TEXT, IncludeExtras INTEGER, Have INTEGER, Total INTEGER, ComicImage TEXT, ComicPublisher TEXT, ComicLocation TEXT, ComicPublished TEXT, LatestIssue TEXT, LatestDate TEXT, Description TEXT, QUALalt_vers TEXT, QUALtype TEXT, QUALscanner TEXT, QUALquality TEXT, LastUpdated TEXT, AlternateSearch TEXT, UseFuzzy TEXT, ComicVersion TEXT, SortOrder INTEGER, DetailURL TEXT, ForceContinuing INTEGER, ComicName_Filesafe TEXT, AlternateFileName TEXT)')
c.execute('CREATE TABLE IF NOT EXISTS issues (IssueID TEXT, ComicName TEXT, IssueName TEXT, Issue_Number TEXT, DateAdded TEXT, Status TEXT, Type TEXT, ComicID TEXT, ArtworkURL Text, ReleaseDate TEXT, Location TEXT, IssueDate TEXT, Int_IssueNumber INT, ComicSize TEXT, AltIssueNumber TEXT, IssueDate_Edit TEXT)')
c.execute('CREATE TABLE IF NOT EXISTS snatched (IssueID TEXT, ComicName TEXT, Issue_Number TEXT, Size INTEGER, DateAdded TEXT, Status TEXT, FolderName TEXT, ComicID TEXT, Provider TEXT)')
c.execute('CREATE TABLE IF NOT EXISTS upcoming (ComicName TEXT, IssueNumber TEXT, ComicID TEXT, IssueID TEXT, IssueDate TEXT, Status TEXT, DisplayComicName TEXT)')
@ -1470,6 +1470,10 @@ def dbcheck():
except sqlite3.OperationalError:
c.execute('ALTER TABLE comics ADD COLUMN ComicName_Filesafe TEXT')
try:
c.execute('SELECT AlternateFileName from comics')
except sqlite3.OperationalError:
c.execute('ALTER TABLE comics ADD COLUMN AlternateFileName TEXT')
# -- Issues Table --

View File

@ -100,7 +100,7 @@ def listFiles(dir,watchcomic,Publisher,AlternateSearch=None,manual=None,sarc=Non
logger.fdebug('[FILECHECKER] filename not a valid cbr/cbz - ignoring: ' + item)
continue
#print item
print item
#subname = os.path.join(basedir, item)
subname = item
@ -154,7 +154,6 @@ def listFiles(dir,watchcomic,Publisher,AlternateSearch=None,manual=None,sarc=Non
volrem = subit
vers4year = "yes"
#check if a year is present in series title (ie. spider-man 2099)
#also check if decimal present in series title (ie. batman beyond 2.0)
#- check if brackets present in series title
@ -374,8 +373,7 @@ def listFiles(dir,watchcomic,Publisher,AlternateSearch=None,manual=None,sarc=Non
# subname = str(subnm[0]).lstrip() + ' (' + str(subnm[1]).strip() + ') '
subname = subnm[0]
if len(subnm):
if len(subnm) == 1:
# if it still has no year (brackets), check setting and either assume no year needed.
subname = subname
logger.fdebug('[FILECHECKER] subname no brackets: ' + str(subname))
@ -391,7 +389,7 @@ def listFiles(dir,watchcomic,Publisher,AlternateSearch=None,manual=None,sarc=Non
if nono in subname:
subcnt = subname.count(nono)
charpos = indices(subname,nono) # will return a list of char positions in subname
logger.fdebug("charpos: " + str(charpos))
logger.fdebug("[" + str(nono) + "] charpos: " + str(charpos))
if nono == '-':
i=0
while (i < len(charpos)):
@ -448,6 +446,13 @@ def listFiles(dir,watchcomic,Publisher,AlternateSearch=None,manual=None,sarc=Non
x = 0
fndit = 0
blspc = 0
if nono == '#':
logger.info('# detected.')
fndit = subname.find(nono)
if subname[fndit+1].isdigit():
logger.info('# detected before digits - assuming issue number.')
subname = re.sub('#','',subname)
continue
while x < subcnt:
fndit = subname.find(nono, fndit)
#print ("space before check: " + str(subname[fndit-1:fndit]))
@ -456,7 +461,7 @@ def listFiles(dir,watchcomic,Publisher,AlternateSearch=None,manual=None,sarc=Non
logger.fdebug('[FILECHECKER] blankspace detected before and after ' + str(nono))
blspc+=1
x+=1
#logger.fdebug('[FILECHECKER] replacing ' + str(nono) + ' with a space')
logger.fdebug('[FILECHECKER] replacing ' + str(nono) + ' with a space')
subname = re.sub(str(nono), '', subname)
nonocount = nonocount + subcnt + blspc
#subname = re.sub('[\_\#\,\/\:\;\.\-\!\$\%\+\'\?\@]',' ', subname)
@ -597,7 +602,7 @@ def listFiles(dir,watchcomic,Publisher,AlternateSearch=None,manual=None,sarc=Non
for i,j in enumerate(charpos):
logger.fdebug('i,j:' + str(i) + ',' + str(j))
logger.fdebug(str(len(subname)) + ' - subname: ' + subname)
logger.fdebug("digitchk: " + str(subname[j:]))
logger.fdebug("digitchk: " + str(subname[j-1:]))
if j >= len(subname):
logger.fdebug('[FILECHECKER] ' + str(j) + ' is >= ' + str(len(subname)) + ' .End reached. ignoring remainder.')
break
@ -617,7 +622,7 @@ def listFiles(dir,watchcomic,Publisher,AlternateSearch=None,manual=None,sarc=Non
elif ('-' in watchcomic or '.' in watchcomic) and j < len(watchcomic):
logger.fdebug('[FILECHECKER] - appears in series title, ignoring.')
else:
digitchk = subname[j:]
digitchk = subname[j-1:]
logger.fdebug('[FILECHECKER] special character appears outside of title - ignoring @ position: ' + str(charpos[i]))
nonocount-=1

View File

@ -345,6 +345,8 @@ def rename_param(comicid, comicname, issue, ofilename, comicyear=None, issueid=N
iss_find = issuenum.find('.')
iss_b4dec = issuenum[:iss_find]
iss_decval = issuenum[iss_find+1:]
if iss_decval.endswith('.'):
iss_decval = iss_decval[:-1]
if int(iss_decval) == 0:
iss = iss_b4dec
issdec = int(iss_decval)
@ -451,6 +453,11 @@ def rename_param(comicid, comicname, issue, ofilename, comicyear=None, issueid=N
logger.fdebug('Publisher: ' + str(publisher))
series = comicnzb['ComicName']
logger.fdebug('Series: ' + str(series))
if comicnzb['AlternateFileName']:
seriesfilename = comicnzb['AlternateFileName']
logger.fdebug('Alternate File Naming has been enabled for this series. Will rename series title to : ' + seriesfilename)
else:
seriesfilename = series
seriesyear = comicnzb['ComicYear']
logger.fdebug('Year: ' + str(seriesyear))
comlocation = comicnzb['ComicLocation']
@ -526,18 +533,18 @@ def rename_param(comicid, comicname, issue, ofilename, comicyear=None, issueid=N
logger.fdebug('Annual detected within series title of ' + series + '. Not auto-correcting issue #')
series = series.encode('ascii', 'ignore').strip()
seriesfilename = seriesfilename.encode('ascii', 'ignore').strip()
filebad = [':',',','/','?','!','\''] #in u_comicname or '/' in u_comicname or ',' in u_comicname or '?' in u_comicname:
for dbd in filebad:
if dbd in series:
if dbd in seriesfilename:
if dbd == '/': repthechar = '-'
else: repthechar = ''
series = series.replace(dbd,repthechar)
logger.fdebug('Altering series name due to filenaming restrictions: ' + series)
seriesfilename = seriesfilename.replace(dbd,repthechar)
logger.fdebug('Altering series name due to filenaming restrictions: ' + seriesfilename)
publisher = re.sub('!','', publisher)
file_values = {'$Series': series,
file_values = {'$Series': seriesfilename,
'$Issue': prettycomiss,
'$Year': issueyear,
'$series': series.lower(),

View File

@ -933,10 +933,11 @@ def NZB_SEARCH(ComicName, IssueNumber, ComicYear, SeriesYear, Publisher, IssueDa
continue
#changed this from '' to ' '
comic_iss_b4 = re.sub('[\-\:\,\?\!]', ' ', str(comic_andiss))
comic_iss_b4 = re.sub('[\-\:\,\?\!]', ' ', comic_andiss)
comic_iss_b4 = re.sub('\'', '', comic_iss_b4)
comic_iss = comic_iss_b4.replace('.',' ')
#if issue_except: comic_iss = re.sub(issue_except.lower(), '', comic_iss)
logger.fdebug("adjusted nzb comic and issue: " + str(comic_iss))
logger.fdebug("adjusted nzb comic and issue: " + comic_iss)
splitit = comic_iss.split(None)
#something happened to dognzb searches or results...added a '.' in place of spaces

View File

@ -425,7 +425,6 @@ class WebInterface(object):
decisval = decis
issaftdec = str(decisval)
try:
# int_issnum = str(issnum)
int_issnum = (int(issb4dec) * 1000) + (int(issaftdec) * 10)
except ValueError:
logger.error(module + ' This has no issue # for me to get - Either a Graphic Novel or one-shot.')
@ -2806,13 +2805,19 @@ class WebInterface(object):
myDB = db.DBConnection()
results = myDB.select("SELECT * FROM importresults WHERE WatchMatch is Null OR WatchMatch LIKE 'C%' group by ComicName COLLATE NOCASE")
#this is to get the count of issues;
res = []
countit = []
for result in results:
countthis = myDB.select("SELECT count(*) FROM importresults WHERE ComicName=?", [result['ComicName']])
countit = countthis[0][0]
ctrlVal = {"ComicName": result['ComicName']}
newVal = {"IssueCount": countit}
res.append(result)
for x in res:
countthis = myDB.select("SELECT count(*) FROM importresults WHERE ComicName=?", [x['ComicName']])
countit.append({"ComicName": x['ComicName'],
"IssueCount": countthis[0][0]})
for ct in countit:
ctrlVal = {"ComicName": ct['ComicName']}
newVal = {"IssueCount": ct['IssueCount']}
myDB.upsert("importresults", newVal, ctrlVal)
#logger.info("counted " + str(countit) + " issues for " + str(result['ComicName']))
#logger.info("counted " + str(countit) + " issues for " + str(result['ComicName']))
#need to reload results now
results = myDB.select("SELECT * FROM importresults WHERE WatchMatch is Null OR WatchMatch LIKE 'C%' group by ComicName COLLATE NOCASE")
watchresults = myDB.select("SELECT * FROM importresults WHERE WatchMatch is not Null AND WatchMatch NOT LIKE 'C%' group by ComicName COLLATE NOCASE")
@ -3298,25 +3303,25 @@ class WebInterface(object):
raise cherrypy.HTTPRedirect("comicDetails?ComicID=%s" % comicid)
manual_annual_add.exposed = True
def comic_config(self, com_location, ComicID, alt_search=None, fuzzy_year=None, comic_version=None, force_continuing=None):
def comic_config(self, com_location, ComicID, alt_search=None, fuzzy_year=None, comic_version=None, force_continuing=None, alt_filename=None):
myDB = db.DBConnection()
#--- this is for multipe search terms............
#--- this is for multiple search terms............
#--- works, just need to redo search.py to accomodate multiple search terms
ffs_alt = []
if '##' in alt_search:
ffs = alt_search.find('##')
ffs_alt.append(alt_search[:ffs])
ffs_alt_st = str(ffs_alt[0])
print ("ffs_alt: " + str(ffs_alt[0]))
logger.fdebug("ffs_alt: " + str(ffs_alt[0]))
ffs_test = alt_search.split('##')
if len(ffs_test) > 0:
print("ffs_test names: " + str(len(ffs_test)))
logger.fdebug("ffs_test names: " + str(len(ffs_test)))
ffs_count = len(ffs_test)
n=1
while (n < ffs_count):
ffs_alt.append(ffs_test[n])
print("adding : " + str(ffs_test[n]))
logger.fdebug("adding : " + str(ffs_test[n]))
#print("ffs_alt : " + str(ffs_alt))
ffs_alt_st = str(ffs_alt_st) + "..." + str(ffs_test[n])
n+=1
@ -3383,6 +3388,11 @@ class WebInterface(object):
else:
newValues['ForceContinuing'] = 1
if alt_filename is None or alt_filename == 'None':
newValues['AlternateFileName'] = "None"
else:
newValues['AlternateFileName'] = str(alt_filename)
#force the check/creation of directory com_location here
if os.path.isdir(str(com_location)):
logger.info(u"Validating Directory (" + str(com_location) + "). Already exists! Continuing...")