Skip to content

Commit

Permalink
Fixed image naming being year if no page number was found (#69)
Browse files Browse the repository at this point in the history
The regex to extract the page number was applied to the complete filepath. If there was a year anywhere in the filepath, it would be extract and seen as the page number. That is fixed now by only looking at the filename instead of the complete filepath.
  • Loading branch information
Casvt committed Jul 23, 2023
1 parent e35c26d commit 57eb4d6
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions backend/naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,16 +411,20 @@ def preview_mass_rename(volume_id: int, issue_id: int=None, filepath_filter: Lis
# If file is image, it's probably a page instead of a whole issue/tpb.
# So put it in it's own folder together with the other images.
if file['filepath'].endswith(image_extensions):
filename: str = basename(file['filepath'])
page_number = None
page_result = page_regex.search(file['filepath'])
if page_result:
page_number = next(r for r in page_result.groups() if r is not None)
if 'cover' in filename.lower():
page_number = 'Cover'
else:
page_result = None
r = page_regex_2.finditer(file['filepath'])
for page_result in r: pass
page_result = page_regex.search(filename)
if page_result:
page_number = page_result.group(1)
page_number = next(r for r in page_result.groups() if r is not None)
else:
page_result = None
r = page_regex_2.finditer(basename(file['filepath']))
for page_result in r: pass
if page_result:
page_number = page_result.group(1)
suggested_name = join(suggested_name, page_number or '1')

# Add number to filename if other file has the same name
Expand Down

0 comments on commit 57eb4d6

Please sign in to comment.