Skip to content

fix(file_manager): whitelist file types by extension so subtitles, .avi, and .nfo files aren't deleted - #215

Merged
magneticstain merged 1 commit into
mainfrom
fix/file_manager/file-type-whitelist
Oct 29, 2026
Merged

magneticstain merged 1 commit into
mainfrom
fix/file_manager/file-type-whitelist

Conversation

@magneticstain

Copy link
Copy Markdown
Owner

Summary

Fixes #176. The entries in ARTIFACT_FILE_TYPE_WHITELIST were missing commas, so Python joined adjacent string literals into one entry. As a result, every .avi, .srt, .sub, and .nfo file inside a movie directory was deleted.

Restoring the commas alone wasn't enough: it would whitelist text/plain and application/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:
    • Video: .avi, .m2ts, .m4v, .mkv, .mov, .mp4, .mpeg, .mpg, .ts, .webm, .wmv
    • Subtitles: .ass, .idx, .smi, .srt, .ssa, .sub, .vtt
    • Metadata: .nfo
  • file_manager.py: new is_whitelisted_artifact() method. It checks the file extension (case-insensitive) first, and keeps any file libmagic detects as video/* as a fallback, so videos with unusual extensions aren't deleted.

Also included:

Tests

  • test_file_manager.py:
    • Every whitelisted extension is kept regardless of MIME type, uppercase extensions match, and the video/* fallback works.
    • .txt, .jpg, .DS_Store, .part, .url, movie.srt.txt, and an extension-less .srt dotfile are not kept.
    • New end-to-end test: a movie directory with .avi, .srt, .idx, .sub, .nfo, and a video named .part all survive process_artifacts() and are renamed, while .txt and .jpg files are deleted.
  • New 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, main deleted movie.srt and movie.nfo. This branch keeps and renames them, and still deletes junk.txt and .DS_Store.

Docs

README:

  • "Supported File Types" now lists the extensions and the video fallback.
  • "How It Works" now says subtitle and .nfo files are renamed too. It also no longer claims sample files are deleted: they're videos, so they're kept.
  • The libmagic install section now says what libmagic is used for.

Known limitation

Subtitles used to be deleted, so they never collided. Now several files with the same extension in one directory (e.g. .en.srt and .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

…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>
@magneticstain magneticstain added the bug Something isn't working label Oct 29, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in Plexer Oct 29, 2026
@magneticstain magneticstain self-assigned this Oct 29, 2026
@magneticstain magneticstain added this to the v1.1.0 milestone Oct 29, 2026
@magneticstain
magneticstain merged commit 74df092 into main Oct 29, 2026
8 checks passed
@magneticstain
magneticstain deleted the fix/file_manager/file-type-whitelist branch October 29, 2026 01:50
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Plexer Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Done

1 participant