Add --delete-mode Argument for Advanced Deletion Control (plex, hard-delete, both)#82
Open
samestrin wants to merge 1 commit intol3uddz:masterfrom
Open
Add --delete-mode Argument for Advanced Deletion Control (plex, hard-delete, both)#82samestrin wants to merge 1 commit intol3uddz:masterfrom
samestrin wants to merge 1 commit intol3uddz:masterfrom
Conversation
1. Advanced Deletion Control & Functionality:
- The delete_item function has been completely overhauled.
- Deletion Modes: Introduces a mode parameter ( 'plex' , 'hard-delete' , 'both' ) to control deletion behavior:
- plex : Deletes only from the Plex server's database.
- hard-delete : Deletes files directly from the filesystem.
- both : Deletes from Plex and the filesystem.
- Command-Line Argument: You can now specify the deletion mode using the --delete-mode argument (e.g., python plex_dupefinder.new.py --delete-mode both ). It can also be configured via DEFAULT_DELETE_MODE in config.py .
- Filesystem Deletion Logic:
- New helper functions ( _get_file_paths_for_media_id , _handle_movie_deletion , _handle_episode_deletion ) manage file removal.
- For movies, it intelligently deletes either the specific file (if in a shared directory) or the entire movie's parent directory.
- For episodes, it deletes the specific media file.
- Plex API Endpoint Usage: Uses more precise Plex API endpoints for deletion (e.g., library/metadata/{media_id} for movies, which is generally more appropriate for removing the entire item).
- Deletion Verification: Includes a verify_item_deleted function to confirm that items are actually removed from Plex after an API delete call.
- Fallback Hard Delete: If Plex API deletion fails when in 'plex' mode, the script will attempt a hard delete from the disk.
Addition Enhancements:
1. Improved Structure and Data Handling:
- The item.type (e.g., 'movie', 'episode') is now stored within the part_info dictionary (as part_info['item_type'] ). This is used by the new delete_item function to determine the correct deletion strategy.
- The process_later dictionary is initialized globally, allowing helper functions to access it for retrieving file paths.
2. New Dependencies (Standard Libraries):
- Imports argparse for handling command-line arguments.
- Imports shutil for more robust directory removal ( shutil.rmtree ).
3. Logging and Error Handling:
- The new deletion logic includes more detailed logging and error handling.
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.
Key Enhancements:
Addition Enhancements:
Use Case:
This feature is especially useful for users running Plex in read-only containers where API deletes are disabled. By running plex_dupefinder from a sidecar container with filesystem write access, users can safely and efficiently clean up duplicates directly.