Fix filename extension detection for parenthesized format strings - #31
Open
croakingtoad wants to merge 1 commit into
Open
Fix filename extension detection for parenthesized format strings#31croakingtoad wants to merge 1 commit into
croakingtoad wants to merge 1 commit into
Conversation
When Anna's Archive metadata includes the file format in parentheses (e.g. "Book Title (v5.0) (mobi)"), Python's Path.suffix incorrectly parses the extension as ".0) (mobi)" instead of ".mobi". This causes files to be saved without a proper extension. This fix scans the filename for known format strings in parentheses when the detected extension is not in LEGAL_FILES, strips the parenthesized format, and appends the correct extension. Examples: "Book (v5.0) (mobi)" -> "Book (v5.0).mobi" "Book (epub)" -> "Book.epub" "Book (pdf)" -> "Book.pdf" Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Author
|
Hope you find this helpful. Was running into this problem when using stacks to download to booklore's bookdrop folder. |
|
Hey @zelestcarlyone any plans on merging this in? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
(mobi),(epub),(pdf))Path.suffixmisparses filenames likeBook (v5.0) (mobi)as having extension.0) (mobi)instead of.mobi, causing downstream tools to not recognize the file typeProblem
When the "Filepath" metadata from Anna's Archive contains the format in parentheses rather than as a dotted extension, the existing extension validation in
direct.pyfails:Path("Book (v5.0) (mobi)").suffixreturns.0) (mobi)LEGAL_FILES, so it logs a warning but doesn't fix the filenameBook (v5.0) (mobi)with no usable extensionFix
When
Path.suffixreturns an extension not inLEGAL_FILES, the code now scans the filename for known format strings in parentheses (e.g.(mobi),(epub),(pdf)). If found, it strips the parenthesized format from the end and appends the correct dotted extension.Examples:
Homer - The Iliad (v5.0) (mobi)Homer - The Iliad (v5.0).mobiSome Book Title (epub)Some Book Title.epubBook With (v2.1) (pdf)Book With (v2.1).pdfNormal Book.epubNormal Book.epub(unchanged)No Extension At AllNo Extension At All.epub(existing fallback)Test plan
.epub) still works(v5.0)are preserved🤖 Generated with Claude Code