Plex Auto-Delete Script

@MovieGhoul Can you try running the script with the flag --debug and look at the log output for those shows? If not can you PM me the debug log and your config. You can remove the tokens, but leave the usernames.

@ngovil21 said:
@MovieGhoul Can you try running the script with the flag --debug and look at the log output for those shows? If not can you PM me the debug log and your config. You can remove the tokens, but leave the usernames.

Ran with --debug and for the shared user it shows ā€œUnauthorized to access url with tokenā€ under each line stating ā€œ[INFO] sharedusera has not seen video ######ā€.

@MovieGhoul said:

@ngovil21 said:
@MovieGhoul Can you try running the script with the flag --debug and look at the log output for those shows? If not can you PM me the debug log and your config. You can remove the tokens, but leave the usernames.

Ran with --debug and for the shared user it shows ā€œUnauthorized to access url with tokenā€ under each line stating ā€œ[INFO] sharedusera has not seen video ######ā€.

Looks like the token you got for the Shared User is not the right one to access the server or the user does not have access to that library.

You can try running a new copy of the config with Shared: True and set Token to the token you are currently using and run that config with the --test parameter. That should hopefully give you the access token. I’ll update the script to do it automatically for users that end in a ā€˜$’

@ngovil21 said:

@MovieGhoul said:

@ngovil21 said:
@MovieGhoul Can you try running the script with the flag --debug and look at the log output for those shows? If not can you PM me the debug log and your config. You can remove the tokens, but leave the usernames.

Ran with --debug and for the shared user it shows ā€œUnauthorized to access url with tokenā€ under each line stating ā€œ[INFO] sharedusera has not seen video ######ā€.

Looks like the token you got for the Shared User is not the right one to access the server or the user does not have access to that library.

You can try running a new copy of the config with Shared: True and set Token to the token you are currently using and run that config with the --test parameter. That should hopefully give you the access token. I’ll update the script to do it automatically for users that end in a ā€˜$’

Ok, great that got me a token and it flagged the sharedusera’s shows that have been watched for deletion on my original config. So is the token they gave me just good for their login? I’m curious how running with the settings you just mentioned retrieved the token stored on my server.

Thanks again for all your help!

@MovieGhoul It depends on how you got the shared user token. Plex has two tokens for shared users. When you authenticate your user login, plex give you a token to access Plex.tv. This token will also authenticate a server that you own. For shared users, you must access https://plex.tv/api/resources?includeHttps=1 using the login token to get a token for shared plex servers. When you specify Shared: True in the script it access the resources to get the proper access token to authenticate with the PMS.

Just pushed an update that will do that automatically if you specify shared users with a a$ at the end (i.e. `shared_user_1$: ā€œ[TOKEN]ā€) and some more processing to make everything more foolproof.

Let me know if it causes any issues.

This is a stupid question, but I’m trying to figure this out. If I want to delete a file 7 days after watching, which variable do I set? I think I set default_watched to true and default_minDays to 7, but I just wanted to verify.

@wiz561 said:
This is a stupid question, but I’m trying to figure this out. If I want to delete a file 7 days after watching, which variable do I set? I think I set default_watched to true and default_minDays to 7, but I just wanted to verify.

Yes that is correct. Just make sure you run the script with --test to make sure it runs the way you want it to.

@ngovil21 said:

@wiz561 said:
This is a stupid question, but I’m trying to figure this out. If I want to delete a file 7 days after watching, which variable do I set? I think I set default_watched to true and default_minDays to 7, but I just wanted to verify.

Yes that is correct. Just make sure you run the script with --test to make sure it runs the way you want it to.

Thanks. I’ve been running it with test and move instead of delete, but I’m excited and impatient to wait the 7 days. Lol…

OK, so it’s been awhile and I seem to hit a snag as it’s not finding all the episodes to delete. For example, I watched Superstore on 4/15/18. When I run plexcleaner, I see this in the log:

Superstore - S03xE019 - Lottery | Viewed: 1 | Days Since Last Viewed: 8 | On Deck: False
[KEEPING] /mnt/videos/TV/Superstore/Season 03/Superstore - S03E19 - Lottery.mkv

I have my default_minDays set to 3 and my default_watched to True. But at the end of the run, it doesn’t talk about flagging this show for removal.

I was wondering if you had any hints about how I can see why it’s saying 8 days since last viewed and my config is set to 3 days, but yet it’s not flagging it for removal.

Thanks!

@ngovil21 said:
@boris9898989 Ok so you are running the script with shared user credentials, but the script is being run on the same machine as PMS correct? If you are using Shared Users then yes you should have Shared: True You should run two scripts if you need to manage different sections differently. If there is one section for your mom and one section for you.

Edit 2: It looks like Windows messed up the formatting of the Config file. Using nano works better. If you use Notepad++ make sure you save as a Unicode encoding and don’t use a Windows format.

Edit 3: The script should look in the script directory for the config file, but this may vary depending on the OS.

Edit 4: max_days is used if you have the option episodes set. Plex_Cleaner will not delete episodes if there is less than episodes of the show in the library, but will if the file has been there longer than max_days. max_days should always be greater than min_days

Hi @ngovil21 i followed your instructions and can’t get it to work…just to clarify again, i’m a friend (account that is a friend to a main administrator accout), administrator and friend accounts are both mine, i want to use plex cleaner on my friend account not on my administrator acount… i’m running plex cleaner on the same machine where is plex… here is my config

  "test": false,
  "Host": "",
  "Port": "",
  "SectionList": [1],
  "IgnoreSections": [],
  "LogFile": "",
  "LogFileMode": "overwrite",
  "trigger_rescan": true,
  "EmailLog": false,
  "EmailServer": "",
  "EmailServerPort": 0,
  "EmailServerUseTLS": false,
  "EmailUsername": "",
  "EmailPassword": "",
  "EmailRecipient": "",
  "Token": "",  
  "Username": "friend_account_name",
  "Password": "friend_password",
  "Shared": true,
  "DeviceName": "",
  "RemoteMount": "",
  "LocalMount": "",
  "plex_delete": false,
  "similar_files": true,
  "cleanup_movie_folders": true,
  "minimum_folder_size": 10,
  "default_episodes": 0,
  "default_minDays": 5,
  "default_maxDays": 60,
  "default_action": "delete",
  "default_watched": true,
  "default_progressAsWatched": 0,
  "default_location": "",
  "default_onDeck": true,
  "default_homeUsers": "",
  "default_ignoreFolders": [],

And i get

[ERROR] Cannot reach server!
[ERROR] Access Token not found or not a shared account

I tried than to put a token in

"Token": "", 

that i got with Ctrl+Shift+I, and again i got the same issue
I tried also different ways you mentioned in forums, and always i get cannot reach server… whats is the proper way to achieve this?

EDIT: After i put my plex server name in

"DeviceName": "",

I managed to recieve Access Token, after that i deleted my username and password and put token, and it seems that it’s working… but i get this message every time i test it… Can i ignore these messages or something else is still needed?

[ERROR] Unable to get access token for token ending with: XqrU
[ERROR] Access Token not found or not a shared account

In error message it says unable to get access token, but i’m running script with access token!?

EDIT 2: after all that, I changed shared from true to false and errors are gone… now it’s error free…
Really strange but it’s working.

Sorry for not reponding, been on vacation for the last two weeks.

@wiz561 Do you have default_episodes set to a certain number, that would prevent episodes from being deleted? You can run the script with --debug to get more information what is not passing the check.

@boris9898989 Sorry, SharedUser should only be used if you are using the username and password to login. If you are able to get the token directly then it should be set to false.

Hey,
I’m attempting to run the Docker image but as long as I run PMS behind encryption, Plex-Clener times out with ā€œCannot reach the serverā€, however, if I change to no encryption, it works, but that is not preferred. I’ve also tried changing host to use https://.

Log file says:
Host: https://192.168.1.2
Port: 32400
Error requesting page: hostname u’192.168.1.2’ doesn’t match ā€˜*.guid.plex.direct’
Section List Mode: User-defined
Operating on user-defined sections:

My config is using everything default besides host, username and password.

Can someone please point me in the right direction?

@Fitur
It’s because the SSL certificate is not accepted on 192.168... Solution could be to ignore SSL certificate verification in Python, or to use the plex-direct address that your Plex clients use.

You could also look into allowing clients to connect without authentication on certain ip address, but not sure if that will apply to SSL connections.

@ngovil21 said:
It’s because the SSL certificate is not accepted on 192.168.

Thanks,
What can I do? Can you point me to a previous reply where this is explained? I’d really appreciate it.
I’ve tried to use the plex.direct guid too, but to no avail.

@Fitur said:

@ngovil21 said:
It’s because the SSL certificate is not accepted on 192.168.

Thanks,
What can I do? Can you point me to a previous reply where this is explained? I’d really appreciate it.
I’ve tried to use the plex.direct guid too, but to no avail.

Sorry accidentally posted before I finished typing the post.

I think try the plex-direct url with port 32443 or 443.

If that doesn’t work you’ll have to modify the code to ignore certificate hostname. Won’t have access to my computer till after the weekend to give you the code to do that.

@ngovil21 said:

@Fitur said:

@ngovil21 said:
It’s because the SSL certificate is not accepted on 192.168.

Thanks,
What can I do? Can you point me to a previous reply where this is explained? I’d really appreciate it.
I’ve tried to use the plex.direct guid too, but to no avail.

Sorry accidentally posted before I finished typing the post.

I think try the plex-direct url with port 32443 or 443.

If that doesn’t work you’ll have to modify the code to ignore certificate hostname. Won’t have access to my computer till after the weekend to give you the code to do that.

Thanks,
Giving the plex direct URL a go. Will try again tomorrow!

Edit: No luck. Please let me know when you have the time to share the modified code.
Have a nice weekend!

Just starting to look at this and it looks great. I’m starting to work my way through the options and testing to see how it works and what it can do.

A question though - is there any hierarchy to the options. In particular, if I process a collection and delete watched shows, but just one of those shows I don’t want to delete - how would I do that? Does the shows section take precedence over the Profiles section, or is there a way to exclude a show from the Profiles section?

Or, if a show is in multiple collections - is there a priority/order? (e.g. if I have a collection called ā€œKids TVā€ that they use to watch their shows, and I have it set to delete watched after 7 days, but then I have another collection called ā€œKids TV - Keepā€ which lists some of those same shows but delete never - which takes priority?).

Thanks!

I’m trying to get plex-cleaner working. It works if I just use my/admin account and token just fine, but I have other users (all homeUsers that I can switch between).

When I try to use these - e.g. ā€œGrey’s Anatomyā€: { ā€œhomeUsersā€: ā€œme,themā€} I get the error:

[ERROR] Do not have the token for them. Please check spelling or token.

I saw somewhere on here how to specify multiple tokens, so set this up like below:

"Token": {
  "me*": "mytoken...",
  "them": "theirtoken..."
}

But this still doesn’t seem to solve the problem - it then says:

Unauthorized to access url with token.

How should I obtain the token for the Home Users to go into the Token section?

Hi
Is it possible to monitor a show and only delete if two users have watched it?

It does not appear I can retrieve shared users access Tokens anymore. I tried the saved extra script I used the first time and it just states ā€œCannot reach serverā€ & ā€œAccess token not foundā€.
Updated PlexCleaner.py and tried with shareduser$ and it did not work either.

Adding the name under ā€œDeviceName:ā€ fixed the issue.