Deleting media files from disk

Hi,

I haven’t seen an option in any of my players to delete media files from disk. So I created a playlist that my server periodically checks to create a list of files (and by interference the directories) to delete. In my set up my FreeBSD PMS does not have write access to the NFS media mounts, so my NAS does the deletion.

Anyway I thought I’d share this SQLite query that creates a list of media files based their presence in a video playlist “TO_DELETE”:

“/usr/local/share/plexmediaserver/Plex Media Server” --sqlite “/usr/local/plexdata/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db” “SELECT mp.file FROM media_parts AS mp LEFT JOIN media_items AS mi ON mi.id = mp.media_item_id LEFT JOIN play_queue_generators AS pqg ON mi.metadata_item_id = pqg.metadata_item_id LEFT JOIN metadata_items AS mti ON mti.id = pqg.playlist_id WHERE mti.metadata_type = ‘15’ AND mti.title = ‘TO_DELETE’”

If you use a different playlist name just update the last criterion.

I use the output to create a list of files that my NAS then picks up to delete the actual directories, then trigger a library update:

curl -s -H 'X-Plex-Token: x' http://plex:32400/library/sections/37/refresh

and then empty the trash (after some sanity checks):

curl -s -H 'X-Plex-Token: x' -X PUT http://plex:32400/library/sections/37/emptyTrash

Hope this helps someone. Or someone can show a different way to delete media files.

Thanks for the great software.

If you are using the Plex user account of the server owner
AND
you have activated “Allow media deletion” in the advanced server settings, it should be possible.

Oh nice. Thanks for that Otto. I had that unticked (since my Plex has no write access to the directory anyway - I do this since I don’t allow external facing servers to make changes to my internal network). My round-about solution might give some insight to others looking for DB queries and a way to automate a few things. I’m looking forward to reading the API info released recently.

A final note. An upside to my approach is that the actual action taken on the media is up to the user (I move my directories out of the movies directory to a temporary location before finally deleting them).
A downside is the lack of feature parity across Plex clients - not all players can add media to a playlist, unfortunately.

Feel free to delete this comment, but the dick OttoKerner drew on his pic to show the “Delete” menu option made me snicker. :laughing:

It’s called pareidolia.