Merge branch 'volume' into develop
This commit is contained in:
commit
1c39165fcc
@ -38,6 +38,8 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class FileNameParser:
|
class FileNameParser:
|
||||||
|
volume_regex = r"v(?:|ol|olume)\.?\s?"
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.series = ""
|
self.series = ""
|
||||||
self.volume = ""
|
self.volume = ""
|
||||||
@ -117,6 +119,11 @@ class FileNameParser:
|
|||||||
# we should now have a cleaned up filename version with all the words in
|
# we should now have a cleaned up filename version with all the words in
|
||||||
# the same positions as original filename
|
# the same positions as original filename
|
||||||
|
|
||||||
|
# search for volume number
|
||||||
|
match = re.search(self.volume_regex + r"(\d+)", filename, re.IGNORECASE)
|
||||||
|
if match:
|
||||||
|
self.volume = match.group(1)
|
||||||
|
|
||||||
# make a list of each word and its position
|
# make a list of each word and its position
|
||||||
word_list = []
|
word_list = []
|
||||||
for m in re.finditer(r"\S+", filename):
|
for m in re.finditer(r"\S+", filename):
|
||||||
@ -194,10 +201,12 @@ class FileNameParser:
|
|||||||
series = re.sub(r"\(.*?\)", "", series)
|
series = re.sub(r"\(.*?\)", "", series)
|
||||||
|
|
||||||
# search for volume number
|
# search for volume number
|
||||||
match = re.search(r"(.+)([vV]|[Vv][oO][Ll]\.?\s?)(\d+)\s*$", series)
|
match = re.search(r"(.+)" + self.volume_regex + r"(\d+)", series, re.IGNORECASE)
|
||||||
if match:
|
if match:
|
||||||
series = match.group(1)
|
series = match.group(1)
|
||||||
volume = match.group(3)
|
volume = match.group(2)
|
||||||
|
if self.volume:
|
||||||
|
volume = self.volume
|
||||||
|
|
||||||
# if a volume wasn't found, see if the last word is a year in parentheses
|
# if a volume wasn't found, see if the last word is a year in parentheses
|
||||||
# since that's a common way to designate the volume
|
# since that's a common way to designate the volume
|
||||||
@ -221,6 +230,9 @@ class FileNameParser:
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if volume:
|
||||||
|
series = re.sub(r"\s+v(|ol|olume)$", "", series)
|
||||||
|
|
||||||
return series, volume.strip()
|
return series, volume.strip()
|
||||||
|
|
||||||
def get_year(self, filename: str, issue_end: int) -> str:
|
def get_year(self, filename: str, issue_end: int) -> str:
|
||||||
@ -250,7 +262,7 @@ class FileNameParser:
|
|||||||
|
|
||||||
remainder = self.fix_spaces(remainder, remove_dashes=False)
|
remainder = self.fix_spaces(remainder, remove_dashes=False)
|
||||||
if volume != "":
|
if volume != "":
|
||||||
remainder = remainder.replace("Vol." + volume, "", 1)
|
remainder = re.sub(r"(?i)(.+)((?:v(?:|ol|olume))\.?\s?)" + volume, "", remainder, count=1)
|
||||||
if year != "":
|
if year != "":
|
||||||
remainder = remainder.replace(year, "", 1)
|
remainder = remainder.replace(year, "", 1)
|
||||||
if count != "":
|
if count != "":
|
||||||
@ -282,6 +294,9 @@ class FileNameParser:
|
|||||||
self.issue, issue_start, issue_end = self.get_issue_number(filename)
|
self.issue, issue_start, issue_end = self.get_issue_number(filename)
|
||||||
self.series, self.volume = self.get_series_name(filename, issue_start)
|
self.series, self.volume = self.get_series_name(filename, issue_start)
|
||||||
|
|
||||||
|
if self.issue == "":
|
||||||
|
self.issue = self.volume
|
||||||
|
|
||||||
# provides proper value when the filename doesn't have a issue number
|
# provides proper value when the filename doesn't have a issue number
|
||||||
if issue_end == 0:
|
if issue_end == 0:
|
||||||
issue_end = len(self.series)
|
issue_end = len(self.series)
|
||||||
@ -290,13 +305,11 @@ class FileNameParser:
|
|||||||
self.issue_count = self.get_issue_count(filename, issue_end)
|
self.issue_count = self.get_issue_count(filename, issue_end)
|
||||||
self.remainder = self.get_remainder(filename, self.year, self.issue_count, self.volume, issue_end)
|
self.remainder = self.get_remainder(filename, self.year, self.issue_count, self.volume, issue_end)
|
||||||
|
|
||||||
|
if self.volume != "":
|
||||||
|
self.volume = issuestring.IssueString(self.volume).as_string()
|
||||||
if self.issue != "":
|
if self.issue != "":
|
||||||
# strip off leading zeros
|
self.issue = issuestring.IssueString(self.issue).as_string()
|
||||||
self.issue = self.issue.lstrip("0")
|
print(self.issue, self.volume)
|
||||||
if self.issue == "":
|
|
||||||
self.issue = "0"
|
|
||||||
if self.issue[0] == ".":
|
|
||||||
self.issue = "0" + self.issue
|
|
||||||
|
|
||||||
|
|
||||||
class FilenameInfo(TypedDict, total=False):
|
class FilenameInfo(TypedDict, total=False):
|
||||||
@ -892,12 +905,9 @@ def parse_finish(p: Parser) -> Optional[Callable[[Parser], Optional[Callable]]]:
|
|||||||
if "alternate" in p.filename_info:
|
if "alternate" in p.filename_info:
|
||||||
p.filename_info["issue"] = p.filename_info["alternate"]
|
p.filename_info["issue"] = p.filename_info["alternate"]
|
||||||
p.filename_info["alternate"] = ""
|
p.filename_info["alternate"] = ""
|
||||||
else:
|
|
||||||
# TODO: This never happens
|
if "volume" in p.filename_info:
|
||||||
inp = [x for x in p.input if x not in p.irrelevant and x not in p.used_items and x.typ != eof.typ]
|
p.filename_info["issue"] = p.filename_info["volume"]
|
||||||
if len(inp) == 1 and inp[0].typ == filenamelexer.ItemType.Number:
|
|
||||||
p.filename_info["issue"] = inp[0].val
|
|
||||||
p.used_items.append(inp[0])
|
|
||||||
|
|
||||||
remove_items = []
|
remove_items = []
|
||||||
if p.remove_fcbd:
|
if p.remove_fcbd:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user