Repository navigation
fix(file_manager): whitelist file types by extension so subtitles, .avi, and .nfo files aren't deleted - #215
Merged
Conversation
…vi, and .nfo files aren't deleted ARTIFACT_FILE_TYPE_WHITELIST was missing commas, so adjacent string literals were concatenated and every .avi, .srt, .sub, and .nfo file was deleted. Restoring the commas alone would whitelist text/plain and application/octet-stream (keeping junk like .txt and .DS_Store) while still deleting .mov/.webm/.ts videos. Files are now kept based on a whitelist of video, subtitle, and metadata file extensions (case-insensitive), with any file libmagic detects as video/* kept as a fallback. Also: - fix the malformed logger.debug call in the whitelisted-file branch, which raised a logging TypeError and failed tests on pytest 9.1 - replace the Metadata() default argument in process_artifacts() with None (ruff B008, flagged by the pre-commit hook) Closes #176 Closes #187 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Fixes #176. The entries in
ARTIFACT_FILE_TYPE_WHITELISTwere missing commas, so Python joined adjacent string literals into one entry. As a result, every.avi,.srt,.sub, and.nfofile inside a movie directory was deleted.Restoring the commas alone wasn't enough: it would whitelist
text/plainandapplication/octet-stream(keeping.txt,.DS_Store, and broken downloads, contrary to the README), and.mov,.webm,.ts, etc. would still be deleted. This PR follows the fix suggested in the issue instead:const.py: the MIME type list is replaced with sets of file extensions to keep:.avi,.m2ts,.m4v,.mkv,.mov,.mp4,.mpeg,.mpg,.ts,.webm,.wmv.ass,.idx,.smi,.srt,.ssa,.sub,.vtt.nfofile_manager.py: newis_whitelisted_artifact()method. It checks the file extension (case-insensitive) first, and keeps any file libmagic detects asvideo/*as a fallback, so videos with unusual extensions aren't deleted.Also included:
logger.debugcall breaks logging and fails tests on pytest 9.1.1 #187: the malformedlogger.debugcall in the whitelisted-file branch raised a loggingTypeError. That failedtest_process_artifactsandtest_process_artifacts_dry_rununder the locked pytest 9.1.1, and more files reach that branch now.process_artifacts()now defaultsvideo_metadatatoNoneinstead ofMetadata()(ruff B008, flagged by the pre-commit hook). There's no behavior change.Tests
test_file_manager.py:video/*fallback works..txt,.jpg,.DS_Store,.part,.url,movie.srt.txt, and an extension-less.srtdotfile are not kept..avi,.srt,.idx,.sub,.nfo, and a video named.partall surviveprocess_artifacts()and are renamed, while.txtand.jpgfiles are deleted.test_const.py: every whitelist entry must be a single, lowercase extension with a leading period, which catches the kind of mistake behind fix(const): missing commas in file-type whitelist cause .avi/.srt/.sub/.nfo files to be deleted #176. It also checks that the whitelist is the union of the three sets and contains the previously deleted types.uv run pytest: 109 passed. Previously 2 tests failed because of #187. ruff and the pre-commit hooks pass.On the same movie directory,
maindeletedmovie.srtandmovie.nfo. This branch keeps and renames them, and still deletesjunk.txtand.DS_Store.Docs
README:
.nfofiles are renamed too. It also no longer claims sample files are deleted: they're videos, so they're kept.Known limitation
Subtitles used to be deleted, so they never collided. Now several files with the same extension in one directory (e.g.
.en.srtand.es.srt, or a sample video) are all renamed to the same name, and only one survives. That's still strictly better than losing all of them. A README note documents this, and the real fix is tracked in #177.Closes #176
Closes #187
🤖 Generated with Claude Code