From 0078f76e8c69215bd45ff18c03f22ca22311ef2d Mon Sep 17 00:00:00 2001 From: "beville@gmail.com" Date: Thu, 31 Jan 2013 01:05:16 +0000 Subject: [PATCH] Use an RE to look for #issue before anything else git-svn-id: http://comictagger.googlecode.com/svn/trunk@379 6c5673fe-1810-88d6-992b-cd32ca31540c --- filenameparser.py | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/filenameparser.py b/filenameparser.py index eba0bc8..77da309 100644 --- a/filenameparser.py +++ b/filenameparser.py @@ -107,18 +107,29 @@ class FileNameParser: word_list[i+2] ="XXX" + # first look for the last "#" followed by a digit in the filename. this is almost certainly the issue number + #issnum = re.search('#\d+', filename) + matchlist = re.findall("#\d+", filename) + if len(matchlist) > 0: + #get the last item + issue = matchlist[ len(matchlist) - 1] + issue = issue[1:] + found = True + + # assume the last number in the filename that is under 4 digits is the issue number - for word in reversed(word_list): - if len(word) > 0 and word[0] == "#": - word = word[1:] - if ( - (word.isdigit() and len(word) < 4) or - (self.isPointIssue(word)) - ): - issue = word - found = True - #print 'Assuming issue number is ' + str(issue) + ' based on the position.' - break + if not found: + for word in reversed(word_list): + if len(word) > 0 and word[0] == "#": + word = word[1:] + if ( + (word.isdigit() and len(word) < 4) or + (self.isPointIssue(word)) + ): + issue = word + found = True + #print 'Assuming issue number is ' + str(issue) + ' based on the position.' + break if not found: # try a regex