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.

