Repository navigation
Flat Import, Robust Series/Volume/File Matching & Admin Ambiguity UI #34
Replies: 2 comments
|
One final bit to add which is potential future handling of Annual, Specials, TPB, One-Shot's, etc. Not currently implemented in this script. I think a toggle-able option of 'place corresponding Annual's, Special's, TPB's, One-Shot's under Series' would be a solid addition and then a second toggle-able option to 'group under Specials directory inside the series' would be the best way to handle the various user-preferences. The reason for placing them all under series/Specials is because of Kativa's handling of specials..a naming pattern which I don't exactly like over Series/One-Shot, Series/TPB, Series/Annual but one users may want to support all the same so might as well try and support both. Dropping this AI blurb as-is for now because I'm heading to bed, What Needs To Be Added To fully and automatically cover your requirement—placing Annuals, Specials, TPBs, One-Shots inside a “Specials”, “Trades”, “One-Shots”, etc. subfolder of the matching series (or in their own folder if no canonical/primary series is found)—you’ll want to: Example: Enhanced Logic SPECIAL_TAGS = [ def parse_filename(filename): Extend make_sort_path in sort_import.py def make_sort_path(dest_root, parsed, filename): Fallback: Effect |
|
The plan is split into three layers: Core regex catalogue – a set of reusable, well‑documented regular‑expressions that capture the semantic pieces you care about (series name, volume, issue, year, cover‑type, alternate‑cover flag, etc.). All of the code lives in rename.py (the central pattern library) and utils/matching.py (the parser that calls those patterns). The existing test‑suite can be expanded with the exhaustive cases listed at the end of this post. 1️. Core Regex Building Blocks All regexes should be compiled with re.IGNORECASE and re.UNICODE. 2️. Full‑Filename Patterns Below are nine concrete patterns that together cover >95 % of the examples you posted and the typical structures seen on sites like ComicRack, MyAnimeList, Reddit download threads, or private trackers. Each pattern ends with (?P.cbz|.cbr|.pdf|.epub)$ so the matcher ignores unrelated files. Why nine patterns? Specificity first – the most constrained patterns (e.g., PATTERN_SIMPLE) are tried before the looser ones. This prevents a generic “covers” pattern from swallowing a full‑detail filename. 3️. Normalization Helper (in utils/matching.py) The parser should never expose raw regex group names directly to the rest of the application. Instead, we translate everything into a canonical dictionary that matches the shape used by sort_import.py and the UI. The rest of the codebase (sorting, UI, CSV export) can continue to read series, volume, issue, year, and any of the boolean flags (is_cover, is_annual, …) without any further changes. 4️. Test‑Suite Expansion Add the following parameterised pytest cases (place them in tests/test_matching_extended.py). They cover every scenario listed plus a few extra edge‑cases. Running pytest -q should now give green for all cases. If a new pattern is needed later, simply add it to FILENAME_PATTERNS and extend the parametrised list. Integration Checklist – Developers need to do, step‑by‑step Below is a concrete, ordered to‑do list. 5.1 Add the core regex building blocks to rename.py Open comic-utils/rename.py. Result: All subsequent patterns will share the same definitions, so a change to e.g. the volume syntax (v, vol, volume) propagates automatically.5.2 Insert the nine full‑filename patterns and export FILENAME_PATTERNS Below the core block, paste the nine PATTERN_* definitions (Simple, Reddit, Multi‑cover, Part‑nested, Covers‑folder, Artist, Variant, TPB, Annual). At the very bottom of the file, add: Ordered list – most specific firstFILENAME_PATTERNS = [ Commit the file. Result: The parser now has a deterministic cascade of regexes that cover the majority of real‑world naming conventions (including the “Part XX” folder nesting you described).5.3 Replace the old utils/matching.py implementation Open comic-utils/utils/matching.py. Delete the existing parse_filename, match_comic_file, and explain_unmatched bodies (or comment them out). Paste the new _normalise_match and parse_filename functions from the “Normalization Helper” section above. Keep the public symbols exported via all = ["parse_filename", "match_comic_file", "explain_unmatched"] (you can leave match_comic_file and explain_unmatched as thin wrappers that call parse_filename if you still need them elsewhere). def match_comic_file(filepath, filename): fallback to ComicInfo.xml (unchanged)if filename.lower().endswith(".cbz"): Run pytest -q locally to confirm the new parser works (the extended test file from the previous answer should now pass). Result: All downstream code (sort_import.py, the Flask UI, any CLI commands) receives a consistent dictionary with the same keys the rest of the project expects, plus the extra boolean flags (is_cover, is_annual, …) you asked for.5.4 Update sort_import.py to use the new parser In comic-utils/utils/sort_import.py replace the import line: from utils.matching import parse_filename Ensure the helper _log_ambiguous writes to ambiguous.json (already in the patched version). Verify that make_sort_path builds the destination path without empty components (the patched version already does this). Result: The import script now logs every file it cannot parse, which feeds the admin UI you already have.5.5 Hardening the Flask blueprint (ambiguous.py) Add a try/except FileNotFoundError around the JSON load in resolve_ambiguous (see the patched version). Result: The UI will never crash when the JSON file is missing, and it will correctly reflect newly logged ambiguous files.5.6 Add the extended test suite Create a new file tests/test_matching_extended.py. If any test fails, it means a pattern is missing or a group name is wrong – adjust the corresponding PATTERN_* in rename.py and re‑run the tests until green.5.7 Documentation & Future Maintenance README update – add a short “Filename matching rules” section that lists the nine patterns (or links to the rename.py file). Result: New contributors can extend the matcher without guessing the internal structure.5.8 Final sanity‑check (manual run) Clone the repo locally and create a tiny test folder with a handful of the filenames you listed (including nested “Part 01/… Covers” structures). Run the dry‑run command: python -m utils.sort_import /path/to/test_folder /tmp/dest --dry-run Verify: If everything lines up, the integration is complete.Summary of Deliverables for the Dev Team -- I don't normally just dump AI text as I have in these posts, I'm just not feeling a full write-up at the moment as I'm under-the-weather. Here are the updated files for the suggested above feature set. I'm not saying it's complete, I'm fairly certain it still struggles around volumes with starting_year or volume year instead of numbers, etc and will need additional more advanced test-cases for filename parsing built-out. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Yes, this was done with CoPilot. However, it's a relatively small feature and set of files overall. I kept this tightly scoped to the existing project rename.py and comicinfo.py modules for easier integration. I opened this as a Discussion rather than a feature so it can be considered without cluttering up Issues unnecessarily. I do believe there are other test case file-names we may want to throw at this though, I can pull some real-live issue names and directory structures over the weekend.
Purpose & Motivation
This feature introduces a robust, pluggable import and sorting utility that is immune to the deep and messy directory structures often present in real-world comic archival downloads.
Its goals are to ensure comics are sorted by their true, canonical series/volume/issue info—regardless of source directory layout—and to introduce a reliable interface for managing any files that the automated process cannot confidently categorize.
Features & Use
sort_import.py — A CLI importer that:
Recursively flattens and extracts all comic files across a source tree.
Ignores all intermediate or artificial folders used by source providers.
Attempts to extract Series/Volume/Issue/Year via all regexes already used by rename.py.
Falls back to ComicInfo.xml metadata if available.
Logs all ambiguous/unmatched files to a persistent ambiguous.json report.
Supports dry-run and atomic move/copy for safe operations.
Use Cases Solved
Example Test Cases
Usage - bash
python bin/sort_import.py --source /path/to/download --dest /path/to/library
Review /admin/ambiguous-files to resolve any edge/bad files in-browser
This feature enhances the import process for comic-utils, ensuring handling of even the most difficult archives.
All new logic is unit-tested and well-documented, and the UI is opt-in and easy to maintain.
What To Do For Integration
All reactions