I found the below script in a post a year back to empty the trash. I would like to run it as a Task via Task Scheduler. I have the server IP and token. A) Is this script still relevant, B) How do I find the ‘key’ for each library?
@echo off
setlocal enabledelayedexpansion
rem ------ Configuration options -----
rem URL to the Plex server and Plex token
set plex=http://127.0.0.1:32400
set token=xxxxxxxxxxxxxxxxxxxxxxxxx
rem Keys for each of the libraries you want to empty, separated by a space
set libraries=2 3 5 6 9
rem ----- Nothing to change below here -----
(for %%l in (%libraries%) do (
echo Emptying trash for ID %%l
curl -X PUT "%plex%/library/sections/%%l/emptyTrash?X-Plex-Token=%token%"
))
echo Finished.
I haven’t tried it, but that looks ok. To get the key, use Plex Web an navigate to your library. Look at the end of the URL, it will say “source=x”. That’s the key.
I ran into a problem with that auto empty function enabled. In short, for some reason, Plex re-added my entire library. Based on comments in a different post, determined it was this auto function. So, since the only other option is to manually empty the trash, I went in search of a script.
Did you delete everything in the library and then try emptying the trash? That won’t work even if done manually. Plex intentionally will not empty the trash if the path it looks for is empty or unreachable. i.e. Your library points to “D:\My Movies”. If that folder is empty or can’t be found, Plex will not empty the trash. You have to have at least 1 file in that folder, any file as long as the folder does not appear to be empty.
Not sure what to tell ya, other than that’s the only explanation we could come up with for why Plex did this. It didn’t cause any real issues, other than it changed the Date Added date. I restored the DB files from 2 days prior to this incident and the correct dates were brought back. Maybe it was something related to the fact I run a script to save the Guest Plex VM prior to backing it up with ATI. It could have simply been a coincidence. I plan on leaving things alone for a few weeks, just to see if this happens again w/o that function enabled and w/o running the script.