se1exin / Cleanarr

A simple UI to help find and delete duplicate and sample files from your Plex server
https://hub.docker.com/r/selexin/cleanarr
MIT License
218 stars 18 forks source link

PlexApi issue (media.delete() resulting in Bad Request) #85

Closed peter-mcconnell closed 1 year ago

peter-mcconnell commented 1 year ago

Hello,

(note: this is NOT an issue with this codebase)

Upon testing this software I noticed many 400 Bad Requests when attempting to delete duplicates. On inspection I noticed this was due to media.delete():

https://github.com/se1exin/Cleanarr/blob/master/backend/main.py#L75 https://github.com/se1exin/Cleanarr/blob/master/backend/plexwrapper.py#L131

Digging further I realised this is actually an issue on the Plex end:

curl -XDELETE http://10.0.0.41:32400/library/metadata/9393/media/24939
<html><head><title>Bad Request</title></head><body><h1>400 Bad Request</h1></body></html>

My question is: is this a common issue / have solutions to this problem already been identified? My kneejerk is that it either needs fixed on the Plex end, or the .delete() method needs to be avoided and offer a separate means to delete these files from disk (meaning figuring out access between this service and disk). I've validated my server allows deletions, though it's possible I've missed something else.

Thought I'd ask here before thinking about it too much more. I appreciate this isn't an issue with Cleanarr. A quick search around led me to https://github.com/ngovil21/Plex-Cleaner/blob/master/PlexCleaner.py#L498 but not sure there's much worth taking here.

peter-mcconnell commented 1 year ago

Follow-up: I identified the issue on the Plex end. Permissions / ownership issues with some folders. Leaving this comment here incase it helps people searching.

Solution:

# identify the path of a single file that's failing to delete
cd /path/to/file
ls -al  # check permissions
sudo chown $(whoami): .  # change dir ownership if needed
sudo chmod 644 <filepath>  # change file permissions if needed
cd ..
# repeat