v0.2.2 resolve emoji issue in file names
This commit is contained in:
@@ -4,7 +4,7 @@ import zipfile
|
||||
import tempfile
|
||||
import shutil
|
||||
from tqdm import tqdm
|
||||
from .file_utils import fix_missing_files
|
||||
from .file_utils import fix_missing_files, find_file_by_volume_chapter, has_problematic_characters
|
||||
|
||||
def create_volume_cbz(manga_name, volume_num, chapter_infos, output_dir=None, force=False, verbose=False, extra_verbose=False):
|
||||
"""Combine multiple chapter CBZ files into a single volume CBZ."""
|
||||
@@ -88,11 +88,36 @@ def create_volume_cbz(manga_name, volume_num, chapter_infos, output_dir=None, fo
|
||||
if verbose:
|
||||
print(f"Extracting chapter {chapter_info['chapter_str']}")
|
||||
|
||||
# IMPORTANT: Handle file matching right before extraction
|
||||
file_exists = os.path.exists(chapter_info['filename'])
|
||||
|
||||
if not file_exists:
|
||||
# Try to find the file by volume and chapter
|
||||
directory = os.path.dirname(chapter_info['filename'])
|
||||
vol_num = chapter_info['volume']
|
||||
chap_num = chapter_info['chapter_str']
|
||||
|
||||
if extra_verbose:
|
||||
print(f"File not found: {chapter_info['filename']}")
|
||||
print(f"Looking for alternative file with volume {vol_num}, chapter {chap_num}")
|
||||
|
||||
# Find by volume and chapter numbers only
|
||||
actual_file = find_file_by_volume_chapter(directory, vol_num, chap_num, extra_verbose)
|
||||
|
||||
if actual_file and os.path.exists(actual_file):
|
||||
chapter_info['filename'] = actual_file
|
||||
file_exists = True
|
||||
if extra_verbose:
|
||||
print(f"Found alternative file: {actual_file}")
|
||||
|
||||
# Skip if file still doesn't exist
|
||||
if not file_exists:
|
||||
if extra_verbose:
|
||||
print(f"Skipping chapter {chapter_info['chapter_str']} - file not found")
|
||||
continue
|
||||
|
||||
if extra_verbose:
|
||||
print(f"File: {chapter_info['filename']}")
|
||||
if not os.path.exists(chapter_info['filename']):
|
||||
print(f" ERROR: File does not exist!")
|
||||
continue
|
||||
|
||||
try:
|
||||
# Extract the chapter
|
||||
@@ -100,16 +125,13 @@ def create_volume_cbz(manga_name, volume_num, chapter_infos, output_dir=None, fo
|
||||
file_list = sorted(zf.namelist())
|
||||
|
||||
if extra_verbose:
|
||||
print(f" Contains {len(file_list)} files:")
|
||||
print(f" Contains {len(file_list)} files")
|
||||
|
||||
for i, file_name in enumerate(file_list):
|
||||
if file_name.endswith('/'): # Skip directories
|
||||
continue
|
||||
|
||||
if extra_verbose and i < 10: # Show first 10 files only
|
||||
print(f" - {file_name}")
|
||||
|
||||
# Extract with a standardized naming pattern: chapterXXX_pageYYY.ext
|
||||
# Extract with a standardized naming pattern
|
||||
base, ext = os.path.splitext(os.path.basename(file_name))
|
||||
new_name = f"chapter{chapter_info['chapter_str'].zfill(3)}_{i+1:03d}{ext}"
|
||||
|
||||
@@ -120,11 +142,10 @@ def create_volume_cbz(manga_name, volume_num, chapter_infos, output_dir=None, fo
|
||||
except Exception as file_error:
|
||||
if extra_verbose:
|
||||
print(f" ERROR extracting {file_name}: {str(file_error)}")
|
||||
|
||||
if extra_verbose and len(file_list) > 10:
|
||||
print(f" ... and {len(file_list) - 10} more files")
|
||||
except Exception as e:
|
||||
return False, f"Error extracting chapter {chapter_info['chapter_str']}: {str(e)}"
|
||||
if extra_verbose:
|
||||
print(f"Error extracting chapter: {e}")
|
||||
continue # Skip this chapter but continue with others
|
||||
|
||||
# Create the volume CBZ
|
||||
if verbose:
|
||||
|
||||
Reference in New Issue
Block a user