support 2nd ch vol format
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
# File: /home/code/projects/manga-organizer-1/cbz-volume-combiner/cbz_volume_combiner/core.py
|
# File: /home/code/projects/manga-organizer-1/cbz-volume-combiner/cbz_volume_combiner/core.py
|
||||||
import os
|
import os, re
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from .parsing import parse_manga_filename
|
from .parsing import parse_manga_filename
|
||||||
from .file_utils import has_problematic_characters, find_file_by_volume_chapter
|
from .file_utils import has_problematic_characters, find_file_by_volume_chapter
|
||||||
@@ -19,58 +19,103 @@ def organize_by_volume(cbz_files, extra_verbose=False):
|
|||||||
if problematic_files and extra_verbose:
|
if problematic_files and extra_verbose:
|
||||||
print(f"\nWARNING: Found {len(problematic_files)} problematic filenames that might need special handling.")
|
print(f"\nWARNING: Found {len(problematic_files)} problematic filenames that might need special handling.")
|
||||||
|
|
||||||
|
# Extract manga name from the first file's directory name
|
||||||
|
if cbz_files:
|
||||||
|
default_manga_name = os.path.basename(os.path.dirname(cbz_files[0]))
|
||||||
|
if extra_verbose:
|
||||||
|
print(f"Using directory name as manga title: {default_manga_name}")
|
||||||
|
else:
|
||||||
|
default_manga_name = "Unknown Manga"
|
||||||
|
|
||||||
for cbz_file in cbz_files:
|
for cbz_file in cbz_files:
|
||||||
info = parse_manga_filename(cbz_file)
|
info = parse_manga_filename(cbz_file)
|
||||||
if info:
|
if info:
|
||||||
manga_key = info['manga_name'].lower()
|
manga_key = info['manga_name'].lower()
|
||||||
volumes[manga_key][info['volume']].append(info)
|
volumes[manga_key][info['volume']].append(info)
|
||||||
else:
|
else:
|
||||||
unparsed_files.append(cbz_file)
|
# Try alternative parsing for ALL unparsed files
|
||||||
|
base_filename = os.path.basename(cbz_file)
|
||||||
|
|
||||||
# For unparsed files that have problematic characters,
|
# Pattern for "Vol XX - YYY - Title.cbz"
|
||||||
# try to get volume and chapter from filename pattern directly
|
alt_pattern = re.search(r'Vol\s+(\d+)\s+-\s+(\d+(?:\.\d+)?)', base_filename, re.IGNORECASE)
|
||||||
has_problem, _ = has_problematic_characters(cbz_file)
|
|
||||||
if has_problem:
|
if alt_pattern:
|
||||||
if extra_verbose:
|
if extra_verbose:
|
||||||
print(f"Attempting alternative parsing for problematic file: {os.path.basename(cbz_file)}")
|
print(f"Using alternative parsing for: {base_filename}")
|
||||||
|
|
||||||
# Extract basic info using more lenient pattern
|
vol_num = int(alt_pattern.group(1))
|
||||||
base_filename = os.path.basename(cbz_file)
|
chap_str = alt_pattern.group(2)
|
||||||
# Look for v## and c### patterns
|
|
||||||
vol_match = re.search(r'v(\d+)', base_filename)
|
|
||||||
chap_match = re.search(r'c(\d+(?:\.\d+)?)', base_filename)
|
|
||||||
|
|
||||||
if vol_match and chap_match:
|
try:
|
||||||
# Extract manga name (everything before v##)
|
chap_num = float(chap_str)
|
||||||
vol_pos = base_filename.find(f"v{vol_match.group(1)}")
|
except ValueError:
|
||||||
manga_name = base_filename[:vol_pos].strip()
|
chap_num = 0
|
||||||
|
|
||||||
# Create a basic info dict
|
# Create a title from everything after the chapter number
|
||||||
vol_num = int(vol_match.group(1))
|
title_match = re.search(r'Vol\s+\d+\s+-\s+\d+(?:\.\d+)?\s+-\s+(.*?)\.cbz', base_filename, re.IGNORECASE)
|
||||||
chap_str = chap_match.group(1)
|
title = title_match.group(1) if title_match else ""
|
||||||
|
|
||||||
try:
|
if extra_verbose:
|
||||||
chap_num = float(chap_str)
|
print(f" Extracted: manga={default_manga_name}, vol={vol_num}, chap={chap_str}, title={title}")
|
||||||
except ValueError:
|
|
||||||
chap_num = 0
|
info = {
|
||||||
|
'manga_name': default_manga_name,
|
||||||
|
'volume': vol_num,
|
||||||
|
'chapter': chap_num,
|
||||||
|
'chapter_str': chap_str,
|
||||||
|
'title': title,
|
||||||
|
'group': '',
|
||||||
|
'filename': cbz_file
|
||||||
|
}
|
||||||
|
|
||||||
|
manga_key = default_manga_name.lower()
|
||||||
|
volumes[manga_key][vol_num].append(info)
|
||||||
|
else:
|
||||||
|
# Fallback to the existing problematic file handling logic
|
||||||
|
has_problem, _ = has_problematic_characters(cbz_file)
|
||||||
|
if has_problem:
|
||||||
if extra_verbose:
|
if extra_verbose:
|
||||||
print(f" Extracted: manga={manga_name}, vol={vol_num}, chap={chap_str}")
|
print(f"Attempting alternative parsing for problematic file: {os.path.basename(cbz_file)}")
|
||||||
|
|
||||||
info = {
|
# Extract basic info using more lenient pattern
|
||||||
'manga_name': manga_name,
|
base_filename = os.path.basename(cbz_file)
|
||||||
'volume': vol_num,
|
# Look for v## and c### patterns
|
||||||
'chapter': chap_num,
|
vol_match = re.search(r'v(\d+)', base_filename)
|
||||||
'chapter_str': chap_str,
|
chap_match = re.search(r'c(\d+(?:\.\d+)?)', base_filename)
|
||||||
'title': '',
|
|
||||||
'group': '',
|
|
||||||
'filename': cbz_file
|
|
||||||
}
|
|
||||||
|
|
||||||
manga_key = manga_name.lower()
|
if vol_match and chap_match:
|
||||||
volumes[manga_key][vol_num].append(info)
|
# Extract manga name (everything before v##)
|
||||||
# Remove from unparsed files since we handled it
|
vol_pos = base_filename.find(f"v{vol_match.group(1)}")
|
||||||
unparsed_files.remove(cbz_file)
|
manga_name = base_filename[:vol_pos].strip()
|
||||||
|
|
||||||
|
# Create a basic info dict
|
||||||
|
vol_num = int(vol_match.group(1))
|
||||||
|
chap_str = chap_match.group(1)
|
||||||
|
|
||||||
|
try:
|
||||||
|
chap_num = float(chap_str)
|
||||||
|
except ValueError:
|
||||||
|
chap_num = 0
|
||||||
|
|
||||||
|
if extra_verbose:
|
||||||
|
print(f" Extracted: manga={manga_name}, vol={vol_num}, chap={chap_str}")
|
||||||
|
|
||||||
|
info = {
|
||||||
|
'manga_name': manga_name,
|
||||||
|
'volume': vol_num,
|
||||||
|
'chapter': chap_num,
|
||||||
|
'chapter_str': chap_str,
|
||||||
|
'title': '',
|
||||||
|
'group': '',
|
||||||
|
'filename': cbz_file
|
||||||
|
}
|
||||||
|
|
||||||
|
manga_key = manga_name.lower()
|
||||||
|
volumes[manga_key][vol_num].append(info)
|
||||||
|
else:
|
||||||
|
unparsed_files.append(cbz_file)
|
||||||
|
else:
|
||||||
|
unparsed_files.append(cbz_file)
|
||||||
|
|
||||||
# Sort chapters within each volume
|
# Sort chapters within each volume
|
||||||
for manga in volumes:
|
for manga in volumes:
|
||||||
|
|||||||
Reference in New Issue
Block a user