2012-09-13 15:27:34 +00:00
|
|
|
#/usr/bin/env python
|
|
|
|
# This file is part of Mylar.
|
|
|
|
#
|
|
|
|
# Mylar is free software: you can redistribute it and/or modify
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# Mylar is distributed in the hope that it will be useful,
|
|
|
|
# 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
|
|
|
|
# along with Mylar. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import os
|
|
|
|
import os.path
|
|
|
|
import pprint
|
|
|
|
import subprocess
|
2012-12-31 16:52:16 +00:00
|
|
|
import re
|
2013-01-05 03:00:13 +00:00
|
|
|
import logger
|
2013-04-22 03:43:57 +00:00
|
|
|
import mylar
|
2013-04-22 17:12:29 +00:00
|
|
|
import sys
|
2012-09-13 15:27:34 +00:00
|
|
|
|
|
|
|
def file2comicmatch(watchmatch):
|
|
|
|
#print ("match: " + str(watchmatch))
|
|
|
|
pass
|
|
|
|
|
2013-01-07 20:35:17 +00:00
|
|
|
def listFiles(dir,watchcomic,AlternateSearch=None):
|
|
|
|
# use AlternateSearch to check for filenames that follow that naming pattern
|
|
|
|
# ie. Star Trek TNG Doctor Who Assimilation won't get hits as the
|
|
|
|
# checker looks for Star Trek TNG Doctor Who Assimilation2 (according to CV)
|
2013-03-08 01:36:36 +00:00
|
|
|
|
|
|
|
# we need to convert to ascii, as watchcomic is utf-8 and special chars f'it up
|
|
|
|
u_watchcomic = watchcomic.encode('ascii', 'ignore').strip()
|
2013-01-05 03:00:13 +00:00
|
|
|
logger.fdebug("comic: " + watchcomic)
|
2012-09-13 15:27:34 +00:00
|
|
|
basedir = dir
|
2013-01-05 03:00:13 +00:00
|
|
|
logger.fdebug("Looking in: " + dir)
|
2012-09-13 15:27:34 +00:00
|
|
|
watchmatch = {}
|
|
|
|
comiclist = []
|
|
|
|
comiccnt = 0
|
|
|
|
for item in os.listdir(basedir):
|
|
|
|
#print item
|
2012-12-31 16:52:16 +00:00
|
|
|
#subname = os.path.join(basedir, item)
|
|
|
|
subname = item
|
2013-02-20 19:34:55 +00:00
|
|
|
#versioning - remove it
|
|
|
|
subsplit = subname.split()
|
FIX:(#304) Index out of range on recheck, FIX:(#303) Comicvine link updated on details page, FIX:(#302) Query rate (Search Delay) Added as a configuration option, FIX:(#300) Version number error on searching when no version number, FIX:(#297) Manual Rename of Files working, FIX:(#294) 'AU' issue problems should be resolved now, FIX:(#290) V#(year) and Vol#(year) added to filechecking, IMP: ComicVine data use only now as a hidden option (cv_only = 1 in config.ini), IMP: added as options for file naming, IMP: Rough drafting of Annuals (annuals_on = 1 in config.ini), Other fixes..
2013-04-06 09:43:18 +00:00
|
|
|
volrem = None
|
2013-02-20 19:34:55 +00:00
|
|
|
for subit in subsplit:
|
FIX:(#304) Index out of range on recheck, FIX:(#303) Comicvine link updated on details page, FIX:(#302) Query rate (Search Delay) Added as a configuration option, FIX:(#300) Version number error on searching when no version number, FIX:(#297) Manual Rename of Files working, FIX:(#294) 'AU' issue problems should be resolved now, FIX:(#290) V#(year) and Vol#(year) added to filechecking, IMP: ComicVine data use only now as a hidden option (cv_only = 1 in config.ini), IMP: added as options for file naming, IMP: Rough drafting of Annuals (annuals_on = 1 in config.ini), Other fixes..
2013-04-06 09:43:18 +00:00
|
|
|
#print ("subit:" + str(subit))
|
|
|
|
if 'v' in str(subit).lower():
|
2013-02-20 19:34:55 +00:00
|
|
|
#print ("possible versioning detected.")
|
|
|
|
if subit[1:].isdigit():
|
FIX:(#304) Index out of range on recheck, FIX:(#303) Comicvine link updated on details page, FIX:(#302) Query rate (Search Delay) Added as a configuration option, FIX:(#300) Version number error on searching when no version number, FIX:(#297) Manual Rename of Files working, FIX:(#294) 'AU' issue problems should be resolved now, FIX:(#290) V#(year) and Vol#(year) added to filechecking, IMP: ComicVine data use only now as a hidden option (cv_only = 1 in config.ini), IMP: added as options for file naming, IMP: Rough drafting of Annuals (annuals_on = 1 in config.ini), Other fixes..
2013-04-06 09:43:18 +00:00
|
|
|
#if in format v1, v2009 etc...
|
2013-02-20 19:34:55 +00:00
|
|
|
#print (subit + " - assuming versioning. Removing from initial search pattern.")
|
|
|
|
subname = re.sub(str(subit), '', subname)
|
FIX:(#304) Index out of range on recheck, FIX:(#303) Comicvine link updated on details page, FIX:(#302) Query rate (Search Delay) Added as a configuration option, FIX:(#300) Version number error on searching when no version number, FIX:(#297) Manual Rename of Files working, FIX:(#294) 'AU' issue problems should be resolved now, FIX:(#290) V#(year) and Vol#(year) added to filechecking, IMP: ComicVine data use only now as a hidden option (cv_only = 1 in config.ini), IMP: added as options for file naming, IMP: Rough drafting of Annuals (annuals_on = 1 in config.ini), Other fixes..
2013-04-06 09:43:18 +00:00
|
|
|
volrem = subit
|
|
|
|
if subit.lower()[:3] == 'vol':
|
|
|
|
#if in format vol.2013 etc
|
|
|
|
#because the '.' in Vol. gets removed, let's loop thru again after the Vol hit to remove it entirely
|
|
|
|
#print ("volume detected as version #:" + str(subit))
|
|
|
|
subname = re.sub(subit, '', subname)
|
|
|
|
volrem = subit
|
|
|
|
|
2013-04-22 03:11:12 +00:00
|
|
|
subname = re.sub('[\_\#\,\/\:\;\.\-\!\$\%\+\'\?\@]',' ', str(subname))
|
|
|
|
modwatchcomic = re.sub('[\_\#\,\/\:\;\.\-\!\$\%\+\'\?\@]', ' ', u_watchcomic)
|
|
|
|
modwatchcomic = re.sub('\&', ' and ', modwatchcomic)
|
FIX:(#304) Index out of range on recheck, FIX:(#303) Comicvine link updated on details page, FIX:(#302) Query rate (Search Delay) Added as a configuration option, FIX:(#300) Version number error on searching when no version number, FIX:(#297) Manual Rename of Files working, FIX:(#294) 'AU' issue problems should be resolved now, FIX:(#290) V#(year) and Vol#(year) added to filechecking, IMP: ComicVine data use only now as a hidden option (cv_only = 1 in config.ini), IMP: added as options for file naming, IMP: Rough drafting of Annuals (annuals_on = 1 in config.ini), Other fixes..
2013-04-06 09:43:18 +00:00
|
|
|
modwatchcomic = re.sub('\s+', ' ', str(modwatchcomic)).strip()
|
2013-04-22 03:11:12 +00:00
|
|
|
subname = re.sub('&', ' and ', subname)
|
2013-01-05 03:00:13 +00:00
|
|
|
subname = re.sub('\s+', ' ', str(subname)).strip()
|
2013-01-07 20:35:17 +00:00
|
|
|
if AlternateSearch is not None:
|
2013-03-08 01:36:36 +00:00
|
|
|
#same = encode.
|
|
|
|
u_altsearchcomic = AlternateSearch.encode('ascii', 'ignore').strip()
|
2013-04-22 03:11:12 +00:00
|
|
|
altsearchcomic = re.sub('[\_\#\,\/\:\;\.\-\!\$\%\+\'\?\@]', ' ', u_altsearchcomic)
|
|
|
|
altseachcomic = re.sub('&', ' and ', altsearchcomic)
|
2013-01-07 20:35:17 +00:00
|
|
|
altsearchcomic = re.sub('\s+', ' ', str(altsearchcomic)).strip()
|
|
|
|
else:
|
|
|
|
#create random characters so it will never match.
|
|
|
|
altsearchcomic = "127372873872871091383 abdkhjhskjhkjdhakajhf"
|
2012-12-31 16:52:16 +00:00
|
|
|
#if '_' in subname:
|
|
|
|
# subname = subname.replace('_', ' ')
|
2013-01-05 03:00:13 +00:00
|
|
|
logger.fdebug("watchcomic:" + str(modwatchcomic) + " ..comparing to found file: " + str(subname))
|
2013-01-07 20:35:17 +00:00
|
|
|
if modwatchcomic.lower() in subname.lower() or altsearchcomic.lower() in subname.lower():
|
2012-09-13 15:27:34 +00:00
|
|
|
if 'annual' in subname.lower():
|
2012-09-24 05:17:29 +00:00
|
|
|
#print ("it's an annual - unsure how to proceed")
|
2012-10-30 10:43:01 +00:00
|
|
|
continue
|
2012-09-13 15:27:34 +00:00
|
|
|
comicpath = os.path.join(basedir, item)
|
2013-01-05 03:00:13 +00:00
|
|
|
logger.fdebug( modwatchcomic + " - watchlist match on : " + comicpath)
|
2012-09-13 15:27:34 +00:00
|
|
|
comicsize = os.path.getsize(comicpath)
|
|
|
|
#print ("Comicsize:" + str(comicsize))
|
|
|
|
comiccnt+=1
|
2013-02-09 03:34:02 +00:00
|
|
|
if modwatchcomic.lower() in subname.lower():
|
FIX:(#304) Index out of range on recheck, FIX:(#303) Comicvine link updated on details page, FIX:(#302) Query rate (Search Delay) Added as a configuration option, FIX:(#300) Version number error on searching when no version number, FIX:(#297) Manual Rename of Files working, FIX:(#294) 'AU' issue problems should be resolved now, FIX:(#290) V#(year) and Vol#(year) added to filechecking, IMP: ComicVine data use only now as a hidden option (cv_only = 1 in config.ini), IMP: added as options for file naming, IMP: Rough drafting of Annuals (annuals_on = 1 in config.ini), Other fixes..
2013-04-06 09:43:18 +00:00
|
|
|
#remove versioning here
|
|
|
|
if volrem != None:
|
|
|
|
jtd_len = len(modwatchcomic) + len(volrem) + 1 #1 is to account for space btwn comic and vol #
|
|
|
|
else:
|
|
|
|
jtd_len = len(modwatchcomic)
|
2013-02-09 03:34:02 +00:00
|
|
|
justthedigits = item[jtd_len:]
|
|
|
|
elif altsearchcomic.lower() in subname.lower():
|
FIX:(#304) Index out of range on recheck, FIX:(#303) Comicvine link updated on details page, FIX:(#302) Query rate (Search Delay) Added as a configuration option, FIX:(#300) Version number error on searching when no version number, FIX:(#297) Manual Rename of Files working, FIX:(#294) 'AU' issue problems should be resolved now, FIX:(#290) V#(year) and Vol#(year) added to filechecking, IMP: ComicVine data use only now as a hidden option (cv_only = 1 in config.ini), IMP: added as options for file naming, IMP: Rough drafting of Annuals (annuals_on = 1 in config.ini), Other fixes..
2013-04-06 09:43:18 +00:00
|
|
|
#remove versioning here
|
|
|
|
if volrem != None:
|
|
|
|
jtd_len = len(altsearchcomic) + len(volrem) + 1
|
|
|
|
else:
|
|
|
|
jtd_len = len(altsearchcomic)
|
2013-02-09 03:34:02 +00:00
|
|
|
justthedigits = item[jtd_len:]
|
2012-09-13 15:27:34 +00:00
|
|
|
comiclist.append({
|
|
|
|
'ComicFilename': item,
|
|
|
|
'ComicLocation': comicpath,
|
2013-02-09 03:34:02 +00:00
|
|
|
'ComicSize': comicsize,
|
|
|
|
'JusttheDigits': justthedigits
|
2012-09-13 15:27:34 +00:00
|
|
|
})
|
|
|
|
watchmatch['comiclist'] = comiclist
|
|
|
|
else:
|
|
|
|
pass
|
|
|
|
#print ("directory found - ignoring")
|
2013-03-08 01:36:36 +00:00
|
|
|
logger.fdebug("you have a total of " + str(comiccnt) + " " + watchcomic + " comics")
|
2012-09-13 15:27:34 +00:00
|
|
|
watchmatch['comiccount'] = comiccnt
|
|
|
|
return watchmatch
|
2013-04-22 03:43:57 +00:00
|
|
|
|
|
|
|
def validateAndCreateDirectory(dir, create=False):
|
|
|
|
if os.path.exists(dir):
|
|
|
|
logger.info("Found comic directory: " + dir)
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
logger.warn("Could not find comic directory: " + dir)
|
|
|
|
if create:
|
|
|
|
if dir.strip():
|
|
|
|
logger.info("Creating comic directory ("+str(mylar.CHMOD_DIR)+") : " + dir)
|
|
|
|
try:
|
2013-04-22 17:12:29 +00:00
|
|
|
permission = int(mylar.CHMOD_DIR, 8)
|
|
|
|
os.umask(0) # this is probably redudant, but it doesn't hurt to clear the umask here.
|
|
|
|
os.makedirs(str(dir), permission )
|
2013-04-22 03:43:57 +00:00
|
|
|
except OSError:
|
|
|
|
raise SystemExit('Could not create data directory: ' + mylar.DATA_DIR + '. Exiting....')
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
logger.warn("Provided directory is blank, aborting")
|
|
|
|
return False
|
|
|
|
return False
|