Plex Auto-Delete Script

Anyone else had a problem where the Recently Viewed Episodes doesn't at all reflect the reality.

My Recently Viewed Episodes claims that I have watched 15 episodes the last 263 days... Not quite right...

(I also posted this question on the General discussion forum).

My bad!

Episode files that are deleted after viewing does not appear in Recently Viewed Episodes... Of course...

i see some of you are having problem whit the scrip. The last update that i post it working for me on MAC just fine. 

Yes the original script will probably still work if you are not using Plex Home. My version of the script uses a token from plex.tv that will allow authentication with Plex Home. The script is just future proofed. I think the script should work for the majority of people now.

And good job troubleshooting your own issue Old-T.

Yes the original script will probably still work if you are not using Plex Home. My version of the script uses a token from plex.tv that will allow authentication with Plex Home. The script is just future proofed. I think the script should work for the majority of people now.

And good job troubleshooting your own issue Old-T.

what's the deal whit the Plex home? 

Plex Home is Plex's solution for parental controls. While it was a greatly sought feature, it means that all authentication to use the API must go through plex.tv. There is no local authentication.

If you are not using Plex Home then it won't affect you. In my updates if a token or a username is not provided it will not go through plex.tv then.

I forgot the most important part:

VERY GOOD JOB CREATING THE SCRIPT!!!!!

It solves some manual parts in the Plex envrionment and I'm very much for automation :-)

Well done all of you!

I am having issues with ngovil21's script. 

Although configured the same as the original script, which works, ngovil21's script doesn't show any output.

You can see difference between my working at Ngovil21 here: https://www.diffchecker.com/p29pfe8s

Also I am having issues with both scripts (original and ngovil21) to save output to a log file, the bat file as explained in the original post doesn't save anything. Ngovil21, can you please update your script with save to file functionality so we do not depend on batch file logging?

I am also trying to configure FireDaemon Pro to restart the script every 30 minutes. Seems to work fine so far, as long as launched with pythonw to avoid the annoying Interactive Desktop Message popups in Windows. However, now that there's no console and no file logging at all, I have no clue what the script is deleting. So functionality to log to file is even more important.

I'd also suggest that there's option to have an input() at the end to keep the window open until any button is pressed.

Thanks in advance for the great work.

OK I added logging to a file. It also turns out that getting the token by logging in with username and password wasn't working in python3 so I fixed that as well. The script should handle files with special characters in the name in python 2.7, but I could not get it to work in python3, too many problems with Unicode and byte problems. I only use the script on Linux, so I hadn't properly tested it on Python3 or Windows.

Try the new version, hopefully it works and solves the issues.

https://dl.dropboxusercontent.com/u/9141060/PlexAutoDelete.py

Looked through the comments and didn’t see this question.


I am running the plex server on a Mac and have my drives running on a separate server. It reads the plex file just find, but has the wrong file path to the media.

@

Looked through the comments and didn't see this question.

I am running the plex server on a Mac and have my drives running on a separate server. It reads the plex file just find, but has the wrong file path to the media.

I haven't tested the with remote drives. Would you mind pasting the output of console or log file and let me know the file path should be.

@


I haven't tested the with remote drives. Would you mind pasting the output of console or log file and let me know the file path should be.

Sure can. It might be a day or 2 before I an able too.

Here is the log.

INFO:root:----------------------------------------------------------------------------
INFO:root:                           Detected Settings
INFO:root:----------------------------------------------------------------------------
INFO:root:Host: ***.***.1.105
INFO:root:Port: 32400
INFO:root:Logged in as: wschlotter
INFO:root:Keep Mode: Keeping for 30 days following the date last viewed
INFO:root:Show Count: 0
INFO:root:Number of Shows Detected For Keeping: 0
INFO:root:Shows to Keep: |
INFO:root:Delete: Disabled - Flagging Only
INFO:root:Delete OnDeck: No
INFO:root:Operating System: Linux
INFO:root:Section List Mode: User-defined
INFO:root:Operating on user-defined sections: 2
INFO:root:
INFO:root:--------- Section 2: TV Shows -----------------------------------
INFO:root:
INFO:root:Viewed:1x | Days Since Viewed: 0 | /Volumes/Media/TV_Shows/Shameless (US)/Season 05/Shameless (US) - S05E06 - Crazy Love.mp4
INFO:root:##[NOT FOUND] /Volumes/Media/TV_Shows/Shameless (US)/Season 05/Shameless (US) - S05E06 - Crazy Love.mp4
INFO:root:
INFO:root:Viewed:1x | Days Since Viewed: 0 | /Volumes/Media/TV_Shows/Shameless (US)/Season 05/Shameless (US) - S05E05 - Rite of Passage.mp4
INFO:root:##[NOT FOUND] /Volumes/Media/TV_Shows/Shameless (US)/Season 05/Shameless (US) - S05E05 - Rite of Passage.mp4
INFO:root:
INFO:root:Viewed:1x | Days Since Viewed: 0 | /Volumes/Media/TV_Shows/Shameless (US)/Season 05/Shameless (US) - S05E04 - A Night to Remem▒^▒ Wait, What.mp4
INFO:root:##[NOT FOUND] /Volumes/Media/TV_Shows/Shameless (US)/Season 05/Shameless (US) - S05E04 - A Night to Remem▒^▒ Wait, What.mp4
INFO:root:
INFO:root:Viewed:1x | Days Since Viewed: 0 | /Volumes/Media/TV_Shows/Shameless (US)/Season 05/Shameless (US) - S05E03 - The Two Lisas.mp4
INFO:root:##[NOT FOUND] /Volumes/Media/TV_Shows/Shameless (US)/Season 05/Shameless (US) - S05E03 - The Two Lisas.mp4
INFO:root:
INFO:root:Viewed:1x | Days Since Viewed: 0 | /Volumes/Media/TV_Shows/Shameless (US)/Season 05/Shameless (US) - S05E02 - I'm the Liver.mp4
INFO:root:##[NOT FOUND] /Volumes/Media/TV_Shows/Shameless (US)/Season 05/Shameless (US) - S05E02 - I'm the Liver.mp4
INFO:root:
INFO:root:Viewed:1x | Days Since Viewed: 0 | /Volumes/Media/TV_Shows/Shameless (US)/Season 05/Shameless (US) - S05E01 - Milk of the Gods.mp4
INFO:root:##[NOT FOUND] /Volumes/Media/TV_Shows/Shameless (US)/Season 05/Shameless (US) - S05E01 - Milk of the Gods.mp4
INFO:root:
INFO:root:Viewed:1x | Days Since Viewed: 0 | /Volumes/Media/TV_Shows/The Big Bang Theory/S08E15 - The Comic Book Store Regeneration.mp4
INFO:root:##[NOT FOUND] /Volumes/Media/TV_Shows/The Big Bang Theory/S08E15 - The Comic Book Store Regeneration.mp4
INFO:root:
INFO:root:Viewed:1x | Days Since Viewed: 2 | /Volumes/Media/TV_Shows/Talking Dead/Season 04/Talking Dead - S04E10 - Them.mp4
INFO:root:##[NOT FOUND] /Volumes/Media/TV_Shows/Talking Dead/Season 04/Talking Dead - S04E10 - Them.mp4
INFO:root:
INFO:root:Viewed:1x | Days Since Viewed: 2 | /Volumes/Media/TV_Shows/Talking Dead/Season 4/Talking Dead - S04E11 - The Distance SDTV.mp4
INFO:root:##[NOT FOUND] /Volumes/Media/TV_Shows/Talking Dead/Season 4/Talking Dead - S04E11 - The Distance SDTV.mp4
INFO:root:
INFO:root:Viewed:1x | Days Since Viewed: 4 | /Volumes/Media/TV_Shows/Doctor Who (2005)/Season 08/Doctor Who (2005) - S08E05 - Time Heist.mkv
INFO:root:##[NOT FOUND] /Volumes/Media/TV_Shows/Doctor Who (2005)/Season 08/Doctor Who (2005) - S08E05 - Time Heist.mkv
INFO:root:
INFO:root:Viewed:1x | Days Since Viewed: 4 | /Volumes/Media/TV_Shows/Doctor Who (2005)/Season 08/Doctor Who (2005) - S08E04 - Listen.mp4
INFO:root:##[NOT FOUND] /Volumes/Media/TV_Shows/Doctor Who (2005)/Season 08/Doctor Who (2005) - S08E04 - Listen.mp4
INFO:root:
INFO:root:Viewed:1x | Days Since Viewed: 4 | /Volumes/Media/TV_Shows/Doctor Who (2005)/Season 08/Doctor Who (2005) - S08E03 - Robot of Sherwood.mp4
INFO:root:##[NOT FOUND] /Volumes/Media/TV_Shows/Doctor Who (2005)/Season 08/Doctor Who (2005) - S08E03 - Robot of Sherwood.mp4
INFO:root:
INFO:root:Viewed:1x | Days Since Viewed: 4 | /Volumes/Media/TV_Shows/Doctor Who (2005)/Season 08/Doctor Who (2005) - S08E02 - Into the Dalek.mp4
INFO:root:##[NOT FOUND] /Volumes/Media/TV_Shows/Doctor Who (2005)/Season 08/Doctor Who (2005) - S08E02 - Into the Dalek.mp4
INFO:root:
INFO:root:Viewed:1x | Days Since Viewed: 4 | /Volumes/Media/TV_Shows/Doctor Who (2005)/Season 08/Doctor Who (2005) - S08E01 - Deep Breath.mkv

OK I just tried this on a mac with a samba mounted volume and it was able to find the files. Are you sure that the path was mounted when you ran the script? I had that problem during my testing.

Otherwise I don't see anything that would be causing a problem.

Hello @ngovil21, can you please add an option to your script to force delete folders of movies removed from the library, since currently only media files are removed and garbage directories remain.

Perhaps most generic would be to define set of sections that have force remove folder. 

Is there any way to make it remove files through Plex? Perhaps from all active servers within your plex account? Right now it just tells me it can't delete the files since the files don't exist locally.

It would be great if this script (or something like it) would be on Github so we can add some extra features.

Hello @ngovil21, can you please add an option to your script to force delete folders of movies removed from the library, since currently only media files are removed and garbage directories remain.

Perhaps most generic would be to define set of sections that have force remove folder. 

Well the script is more suited to deleting TV Shows than Movies. It would be possible to delete the folder for movies, but I am concerned it might delete the entire movie folder if there is a stray movie file that is not in its own folder. A separate script that searches for orphaned folders in the movies folder might be better.

Is there any way to make it remove files through Plex? Perhaps from all active servers within your plex account? Right now it just tells me it can't delete the files since the files don't exist locally.

It would be great if this script (or something like it) would be on Github so we can add some extra features.

I guess you are running the script in a different location than the Plex Media Server. Any reason you can't run the script on the server itself? I can add that functionality, but the script is starting to get fragmented and I don't want to have too many configurable options.

As far as Github, I won't be able to actively update the script, if someone would like to create one to maintain, I have no problem with it.

I would upload It to the hub tomorow. So fsr my code is working fine. Since they modify It to delete especial characters anime apisodes.

I guess you are running the script in a different location than the Plex Media Server. Any reason you can't run the script on the server itself? I can add that functionality, but the script is starting to get fragmented and I don't want to have too many configurable options.

The reason is that I have multiple Plex Media Servers, some local, some remote. And I like to clean them all at once when I'm cleaning anyway. Right now I can do it with mounts and a search/replace in the file path, but it's a tad tedious.

@wolph, how about running multiple copies of the script, each for separate server? You can run them in order via the bat file. And I use FireDaemon to keep them restarting every 30 min to delete as fast as I watch the next episode or movie.



Sent from my iPad using Tapatalk

@apoapostolov the issue was that he was running the Script on a different computer than the plex media server, which was giving the paths on the plex media server to the file, not the path to the file on the computer the script was running on.

I added an option to delete the file using the Plex API, so you can run the script from a remote computer. It will not delete any similar files because Plex doesn't do that.

Hopefully this works for you wolph and wschlotter. You would need to run a separate script for each server to get a valid Token.

Newest version: https://www.dropbox.com/s/zlvt9gyp4vlkm43/PlexAutoDelete.py?dl=0

First, thank you all for keeping up with all this. It is ridiculously helpful!

Do you have any suggestions on what to try if the script returns with a 0 total file count? If it matters, I'm using the script ngovil21 just wrote, on a windows computer, but the host is remote running linux. I'm not getting any errors, just nothing is being found. I went through and read each post but didn't find anything similar. Thanks in advance!

----------------------------------------------------------------------------
                           Detected Settings
----------------------------------------------------------------------------
Host: xxx.xx.xxx.xx
Port: xxxx
Using Token for login
Keep Mode: DISABLED
Show Count: 1
Number of Shows Detected For Keeping: 0
Shows to Keep: | (None Listed) | 
Delete: Disabled - Flagging Only
Delete OnDeck: No
Operating System: Linux 
Section List Mode: User-defined
Operating on user-defined sections: 1,2
 
--------- Section 1: Movies -----------------------------------
 
--------- Section 2: TV Shows -----------------------------------
 
----------------------------------------------------------------------------
----------------------------------------------------------------------------
                Summary -- Script Completed Successfully
----------------------------------------------------------------------------
 
  Total File Count      0
  Kept Show Files       0
  On Deck Files         0
  Deleted Files         0
  Moved Files           0
  Copied Files          0
  Flagged Files         0
  Rescanned Sections    
 
----------------------------------------------------------------------------
----------------------------------------------------------------------------