Plex Auto-Delete Script

other-dev

#1

Hello,



Thank you for your interest in this script.

I originally designed this script back in 2013.

It's purpose is to automatically delete shows that you've already watch based on it's status (Watched/Unwatched) in PLEX Media Server.
You can see that journey in the next few posts.... But enough of the history on to what's in important where is the script and how do I get it to work???



Before we get to the good stuff - Please review this list of contributors. (Sorry, if I missed anyone)

ngovil21 - New Project Leader and Successor
.... additional list coming soon ...

Anyways - Now that thee suspense is killing you - The wait is finally over.

-----------------------------------------------------------------------------------------------------------------------

ngovil21 has transformed PLEX Auto Delete Script into to ultimate Plex-Cleaner.

The script is available on GitHub @ https://github.com/ngovil21/Plex-Cleaner


PLEASE READ THE READ.ME ON GIT HUB


Otherwise.... maybe these instructions might be help too....

In case you need some more basic instructions on how to get this working...

1. Install Python --- I currently use version (2.7.10) -- but that's probably because of other Python scripts I run, I think the latest is fine though....

---- Python is a program language required for this script to run.

---- Search through the 2nd post for the Words WINDOWS USERS or LINUX USERS (Mac - Search Linux) for some old instructions I wrote up about Python

2. Download the latest version of Plex-Cleaner (Its the PlexCleaner.py file) from https://github.com/ngovil21/Plex-Cleaner/blob/master/PlexCleaner.py

3. Download the "Cleaner.conf.default" @ https://github.com/ngovil21/Plex-Cleaner/blob/master/Cleaner.conf.default and save it as Cleaner.conf (In the Same Folder)

4. Edit the Cleaner.conf file. You will need to at least set the Username and Password in the files for it to do anything.

---- You can later switch over to the token method for authentication -- but this will get you going

5. Open the Plex-Cleaner.py in notepad or whatever text editor you choose. (To reference the comments about the different settings located in the Cleaner.conf)

6. Realize this script (un-configured) will not delete anything and is completely safe.

7. Adjust log file so you can see what it's going to "flag"....

8. Run the script using --- The instructions in the read.me
9. When you are satisfied with the result then change the setting for "default_action" in the Cleaner.conf to "delete"

OR if you want to archive it "cut" or copy it somewhere those options are available.

Just refer to the commented documentation in the script.



Any question - Feel free to ask here and someone will get back to you shortly.


#2

**** INFORMATION IS OLD AND OUT DATED PLEASE REFER TO POST 1


AutoDelete.py - (Auto Delete Watched Shows) Script - 2013 (DOES NOT WORK)



Disclaimer:

 USE AT YOUR OWN RISK I WILL NOT BE HELD RESPONSIBLE FOR ANYTHING BAD THAT HAPPENS ***
Also Note: I'm New To Python. So Please Ignore The Messy Code.
I'll Get Around to Cleaning It Up Later...
What it is it and What Does It Do?
This is a Script I Wrote In Python.
This Script is used to look for TV Shows That have been marked as "WATCHED".
It will then find the "Watched" file and DELETE it to save you some hard drive space and clutter.
- Tested on Ubuntu 12.04 Linux Server using Python 2.7.3
- Tested on Windows 8 Ultimate (64-Bit) using Python 3.3.2
Configuring:
Also Briefly Described in The Top Portion Of The AutoDelete.py
If Plex Was Installed with all the default settings, you do not need to configure ANYTHING.
You may need to adjust the "Section" Variable if you have multiple librarys like TV Shows, Movies, Audio, Etc
You may want to adjust the "Shows" Variable if you have Shows, Movies, Audio, That You Don't Want Delete (Verifies Against Full File Path).
If you want to save the OnDeck Shows from being Deleted, Set "OnDeck" = "1";
Understanding the Configuration:
http : // :/library/sections/
/recenlyViewed
= IP Address or Host name of the Server (You can also use 127.0.0.1 for localhost)
= Port For Plex Web Server (Default is 32400)
= KEY for the Section You Want This Script To Look At
**You can See what Sections are Available by going to: http : // 192.168.X.X:32400/library/sections/
Looking at the TITLE= and the associated KEY=

It Is Using the XML Data Provided By Your Plex Web Server.
The Number "1" might vary for you.
For my new plex server I have only setup tv shows (no movies section yet) so since I created tv shows first it was given the index of 1.
On my old plex server (windows) I setup tv shows second so it was given the index of 2.
Easy way to tell whats what... Go to the URL and see if the data you are looking at is TV shows or whatever content you are wishing to remove.

Notes:
Delete = ""
Noting will be deleted - Safe for Review and Testing

Delete = "1"
Your files will be deleted... Please Don't Cry

Linux Users (Ubuntu):
sudo apt-get -y install python nano            (typically skip this step it should already be installed)
python -V (CAPITAL V - Check the Version - I use 2.7.3)
touch AutoDelete.py
chmod +x AutoDelete.py
nano AutoDelete.py (OR YOUR FAVORITE TEXT EDITOR)
Copy & Paste Contents
PRESS: (CTRL + X) answer YES to Save and WriteOut the file)
To run it:
./AutoDelete.py
Or Dump It To A Log File:
./AutoDelete.py >> AutoDelete.log
note the period then then slash followed by the file name.
Then you'll need to setup a schedule task using cronjob (google it, if you really need help then ask).
Windows User:
Download and Install Python:
http://www.python.org/download/releases/3.3.2/
Windows x86 MSI Installer (3.3.2) (sig) and Visual Studio debug information files (sig)
or
Windows X86-64 MSI Installer (3.3.2) 1 and Visual Studio debug information files (sig)

Note its installation location:
Mine Was: C:\Python33

CREATE A BAT FIle using Notepad or whatever..

AutoDelete.BAT

SET PythonEXE="C:\Python33\Python.exe"
SET AutoDelete="C:\Python33\AutoDelete.py"
SET LOGFILE=C:\Python33\AutoDelete.log"

%PythonEXE% %AutoDelete%>>%LOGFILE%

Then get your AutoDelete.py script and put in the location and modify the 3 above variables accordingly.
I recommended a bat file as it easiest to use when setting up a scheduled task.

Code for AutoDelete.py:
SECOND POST

**** INFORMATION IS OLD AND OUT DATED PLEASE REFER TO POST 1 ***

AutoDelete.py
 
NOTE:  If Plex Was Installed With The Default Setting
    - No Configuration Are Needed
 
You may want to configure the following though:
  - Section  (What Section 1,2,3 Contains Your TV Shows, Mine is 2) -- ( If You A Few Different Libraries EG. Shows, Movies, Etc...)
  - Shows    (What Shows NOT to do Delete)
  - OnDeck  (Do Not Delete Show If "On Deck")
 
Download or Copy/Paste Below

#!/usr/bin/python

                                  INFORMATION

   Developed by: Steven Johnson

   Last Updated: 11/13/2013 4:00AM PST

   

   Description: Auto-Delete Watched Items In Plex

   Required Configurations:

      - PC       (Blank = AutoDetect  |  W = Windows  |  L = Linux/Unix/MAC )

      - Host     (Hostname or IP  | Blank = 127.0.0.1)

      - Port     (Port  |  Blank = 32400)

      - Section  (Section aka Library 1 2 3 varies on your system  |  Blank = 1)

      - Delete   (1 = Delete  |  Blank = 0 (For Testing or Review))

      - Shows    ( ["Show1","Show2"]; = Kept Shows OR [""]; = DEL ALL SHOWS )

      - OnDeck   ( 1 = Keep If On Deck  |  Blank = Delete Regardless if onDeck  )

PC = "";
Host = "";
Port = "";
Section = "";
Delete = "";
Shows = [""];
OnDeck = "";

                        NO NEED TO EDIT BELOW THIS LINE  

import os
import xml.dom.minidom
import platform
import re

  Checking URL

if Host=="":
  Host="127.0.0.1"
if Port=="":
  Port="32400"
if Section=="":
  Section = "1"
URL = ("http://" + Host + ":" + Port + "/library/sections/" + Section + "/recentlyViewed")
OnDeckURL = ("http://" + Host + ":" + Port + "/library/sections/" + Section + "/onDeck")
print("----------------------------------------------------------------------------")
print("                           Detected Settings")
print("----------------------------------------------------------------------------")
print("Host: " + Host)
print("Port: " + Port)
print("Section: " + Section)
print("URL: " + URL)
print("OnDeck URL: " + OnDeckURL)

  Checking Shows

NoDelete = " | "
ShowCount = len(Shows)
print("Show Count: " + str(ShowCount))

for Show in Shows:
  Show = re.sub('[^A-Za-z0-9 ]+', '', Show).strip()
  if Show=="":
    NoDelete += "(None Listed) | "
    ShowCount -= 1
  else:
    NoDelete += Show + " | "

print("Number of Shows Detected For Keeping: " + str(ShowCount))
print ("Shows to Keep:" + NoDelete)

  Checking Delete

if Delete=="1":
  print("Delete: Enabled")
else:
  print("Delete: Disabled - Flagging Only")

if OnDeck=="1":
  print("Delete OnDeck: No")
else:
  print("Delete OnDeck: Yes")

  Checking OS

AD = ""
if PC=="":
  AD = "(Auto Detected)"
  if platform.system()=="Windows":
    PC = "W"
  elif platform.system()=="Linux":
    PC = "L"
  elif platform.system()=="Darwin":
    PC = "L"

  Setting OS Based Variables

if PC=="L":
  print("Operating System: Linux " + AD)
  import urllib2
  doc = xml.dom.minidom.parse(urllib2.urlopen(URL))
  deck = xml.dom.minidom.parse(urllib2.urlopen(OnDeckURL))
elif PC=="W":
  print("Operating System: Windows " + AD)
  import urllib.request
  doc = xml.dom.minidom.parse(urllib.request.urlopen(URL))
  deck = xml.dom.minidom.parse(urllib.request.urlopen(OnDeckURL))
else:
  print("Operating System: ** Not Configured **  (" + platform.system() + ") is not recognized.")
  exit()
print("----------------------------------------------------------------------------")
print("----------------------------------------------------------------------------")
print("")

FileCount = 0
DeleteCount = 0
FlaggedCount = 0
OnDeckCount = 0
ShowsCount = 0

  Check On Deck

def CheckOnDeck( CheckDeckFile ):
  InTheDeck = 0
  for DeckVideoNode in deck.getElementsByTagName("Video"):
    DeckMediaNode = DeckVideoNode.getElementsByTagName("Media")
    for DeckMedia in DeckMediaNode:
      DeckPartNode = DeckMedia.getElementsByTagName("Part")
      for DeckPart in DeckPartNode:
        Deckfile = DeckPart.getAttribute("file")
        if CheckDeckFile==Deckfile:
          InTheDeck += 1
        else:
          InTheDeck += 0
  return InTheDeck
 

  Check Shows And Delete If Configured

def CheckShows( CheckFile ):
  global FileCount
  global DeleteCount
  global FlaggedCount
  global OnDeckCount
  global ShowsCount
  FileCount += 1
  CantDelete = 0
  ShowFound = ""
 

  -- CHECK SHOWS --  

  for Show in Shows:
    Show = re.sub('[^A-Za-z0-9 ]+', '', Show).strip()
    if Show=="":
      CantDelete = 0
    else:
      if (' ' in Show) == True:
        if all(str(Word) in CheckFile for Word in Show.split()):
          CantDelete += 1
          ShowFound = "[" + Show + "]"
          ShowsCount += 1
        else:
          CantDelete += 0
      else:
        if Show in CheckFile:
          CantDelete += 1
          ShowFound = "[" + Show + "]"
          ShowsCount += 1
        else:
          CantDelete += 0

-- Check OnDeck --

  if OnDeck=="1":
    IsOnDeck = CheckOnDeck(CheckFile);
    if IsOnDeck==0:
      CantDelete += 0
    else:
      CantDelete += 1
      ShowFound = "[OnDeck]" + ShowFound
      OnDeckCount += 1

-- DELETE SHOWS --

  if CantDelete == 0:
    if Delete=="1":
      print("[DELETED] " + CheckFile)
      os.remove(file)
      DeleteCount += 1
    else:
      print("
[FLAGGED] " + CheckFile)
      FlaggedCount += 1
  else:
    print("[KEEPING]" + ShowFound + " " + CheckFile)

  Get Files for Watched Shows

for VideoNode in doc.getElementsByTagName("Video"):
  view = VideoNode.getAttribute("viewCount")
  if view == '':
    view = 0
  view = int(view)
  MediaNode = VideoNode.getElementsByTagName("Media")
  for Media in MediaNode:
    PartNode = Media.getElementsByTagName("Part")
    for Part in PartNode:
      file = Part.getAttribute("file")
      if view > 0:
          if os.path.isfile(file):
            CheckShows(file);
          else:
            print("##[NOT FOUND] " + file)

  Check Shows And Delete If Configured

##############################################################################    

print("")
print("----------------------------------------------------------------------------")
print("----------------------------------------------------------------------------")
print("                Summary -- Script Completed Successfully")
print("----------------------------------------------------------------------------")
print("")
print("  Total File Count  " + str(FileCount))
print("  Kept Show Files   " + str(ShowsCount))
print("  On Deck Files     " + str(OnDeckCount))
print("  Deleted Files     " + str(DeleteCount))
print("  Flagged Files     " + str(FlaggedCount))
print("")
print("----------------------------------------------------------------------------")
print("----------------------------------------------------------------------------")


#3

CHANGE LOG:

11/13/2013  -  Added File Count Summary

11/13/2013  -  Added Mac AutoDetect

11/13/2013  -  Added Keep OnDeck

11/12/2013  -  Added Keep Specific Shows

Planned Features:

 - Auto-Delete ALL Sections (Instead of Just Section 1 (for tv shows))

 - Logging

 - Remove After X amount of Days (Possibly - Kinda Like A Delete Que, So if you marked something as watched and didn't mean to, you can save your files before its going to get deleted.)

          - Possible Email Notifications For The (Remove After X Days Feature)

 - OR Remove After X Amount of Days After Being Marked As Watched

 - Additional Plex CleanUp (If Plex Doesn't Already Do This Automatically)

 - Do NOT Delete (Specific Shows)

 - Auto Set IP/HostName

 - Auto Set Port

 - Windows Support

 - Auto Detect OS Architecture


#4

FAQ (Frequently Asked Questions):

1.) How do I keep it from Deleting A Specific Show or a Couple of Shows?

       - Configure the Shows Variable EG.

       - If your show has a special character in it like Grey's Anatomy, the special character will be stripped. I would highly recommended you change Delete = "" to do a TEST run only.

Shows = ["Dexter","2 Broke Girls","Sons of Anarchy"];

2.) Does It Work on A Mac?

      - Yes, Set the PC = "L"; for Linux. As this script was developed for and on Linux. Mac and Linux are Both UNIX based, so it should work on it without any problems.

3.) When I run the Script it showing me all of my movies instead of my TV Shows?

      - This is where the "Section" Variable Comes into play. For me Movies is Section 1 (The default) My TV Shows are under Section 2, So I configure it to be Section = "2"


#5

Hey, this is awesome! I am definitely going to test this out on my mac. I may wait until you have completed the Do Not Delete (specific shows) as I have a couple of shows I want to keep after watching.

Thanks for putting the time in to make this happen! I know a lot of people have been hoping for something like this. The "remove after X days would definitely be a killer feature" for the reason you mentioned.

edit: I just tested it out on my mac and it worked flawlessly! I put "L" for linux as the operating system of course... nano was already on my machine

:D Thanks again!!!


#6

Awesome to know that it works on a Mac. Glad you knew to use the "L" for Unix/Linux. I'll make a note of that for other MAC user that might not have known this.

I had stopped working on cause it didn't seem like many people were too interest, but yea, I'll definitely get working on it again.

I wonder if you could test something for me. I'm curious as to what it identifies the MAC OS as, so I can add it to the auto detect portion.

Would you mind testing the following script and let me know what it returns:

#!/usr/bin/python
import os
import platform

print("Operating System Detected: " + platform.system())

Thank you again for your reply and assistance.

What feature would you prefer me to work on first. Do Not Delete Show or Remove After X?


#7

This sounds awesome!

I'm looking for a features like:

  1. Delete marked file or folder when free HD space falls below nMB - I'm not sure how you could implement marking of items for deletion, maybe use the tagging feature on Mavericks for folders and files?
  2. Requirement #1 should work for multiple HDs

I hope this gets integrated in the Plex client/server someday. Great work mate!


#8

Everyone:

For those looking for the DO NOT DELETE SHOW Feature, I'm nearly done. Small bugs to work out with it so it can account for spaces in the name of the show.

Nimrud7:

As you had mentioned in your feature, I'm not quite sure what could be used to implement a "marking". At least in the ways that I use Plex, I'm not sure, but I will look into it.

I don't foresee checking for free space on multiple drives and deleting when X amount of capacity is reached, being an issue at all.

Excuse my ignorance, what is Mavericks?

So lets talk more about the marking nimrud7.

So, your not wanting the marking to be based on a "watched" marking? (That this script is already utilizing?)

How do you use Plex? Web only, android devices, roku devices?

What would cause you to want to delete a show after your done watching it? And what causes you to want to keep a show?

Just trying understand your needs and usage to help create something that is geared towards you or anyone who might use it as well.


#9

Awesome to know that it works on a Mac. Glad you knew to use the "L" for Unix/Linux. I'll make a note of that for other MAC user that might not have known this.

I had stopped working on cause it didn't seem like many people were too interest, but yea, I'll definitely get working on it again.

I wonder if you could test something for me. I'm curious as to what it identifies the MAC OS as, so I can add it to the auto detect portion.

Would you mind testing the following script and let me know what it returns:

#!/usr/bin/python
import os
import platform

print("Operating System Detected: " + platform.system())

Thank you again for your reply and assistance.

What feature would you prefer me to work on first. Do Not Delete Show or Remove After X?

Awesome work! Here is the response "Operating System Detected: Darwin" on my mac

It sounds like you almost have Do Not Delete Show done which I think is most useful.

Remove after X will be nice because what I have noticed is that when I have all of my watched episodes deleted for a specific show Plex no longer shows those shows as "On Deck" anymore. Having the remove after x would be great because then I can just keep them for a couple weeks thus keeping my on deck status for my currently watching shows...

Cool stuff! Love what you have done. Thanks again!  :D


#10

STEEvo:
Thanks for checking that out.
So "Darwin" - Wasn't what I was expecting at all.
So the script won't universally detect for macs, but as you've already figured out just manually configure the letter "L" for the OS.
 
Everyone:
Do Not Delete Show IS DONE.

******************** NOTE I ONLY TESTED THIS FEATURE UNDER WINDOWS THIS TIME *******************************

But it should work on Linux and mac just fine.

Please let me know if it doesn't..

I started doing all my testing on windows as it seems that's the OS it has the biggest problems with and has the legacy code.


#11

STEEvo:
Thanks for checking that out.
So "Darwin" - Wasn't what I was expecting at all.
So the script won't universally detect for macs, but as you've already figured out just manually configure the letter "L" for the OS.
 
Everyone:
Do Not Delete Show IS DONE.

******************** NOTE I ONLY TESTED THIS FEATURE UNDER WINDOWS THIS TIME *******************************

But it should work on Linux and mac just fine.

Please let me know if it doesn't..

I started doing all my testing on windows as it seems that's the OS it has the biggest problems with and has the legacy code.

Excellent, I will give it a test! I got "Darwin" on two different macs I tried FYI.

I will give Do Not Delete Show a test. 

I was thinking about Delete After X last night... Because having all of the recently watched shows deleted ruins the "On Deck" status for that show, having a Delete All But Most Recent feature would be better than Delete After X in my opinion. It seems it might also be easier? Or... maybe Delete All But Most Recent is a toggle for the Delete After X Feature (leaving one watched show behind at all times.)


#12

Excellent, I will give it a test! I got "Darwin" on two different macs I tried FYI.

I will give Do Not Delete Show a test. 

I was thinking about Delete After X last night... Because having all of the recently watched shows deleted ruins the "On Deck" status for that show, having a Delete All But Most Recent feature would be better than Delete After X in my opinion. It seems it might also be easier? Or... maybe Delete All But Most Recent is a toggle for the Delete After X Feature (leaving one watched show behind at all times.)

Were they both the same OS version on the Macs?

I'll add Darwin in as the "Mac" auto-detect on the next release.

Interesting thought you have presented. I watch to many different show for the "On Deck" feature to even be useful to me, so I've never really used it.

I thought the "On Deck" feature was only use for newly added episodes?

Either way though, I do believe the feature you are suggesting might be easier, as I no longer have to keep track of the data, Plex will do all that for me.

However the "Leaving 1 Watched Show Behind"  might be a bit of work, because I'd have to cross reference it with the all shows, and identify if its the last show... but it could be done.

2 Methods Come To Mind:

Method 1

Create a Variable NoOnDeck

If NoOnDeck = 1 (Meaning Don't Delete On Deck)

It will go through its normal functions of Deleting data, but will crosscurrent each file with the ones in the onDeck Section and NOT delete if it finds it in there.

Method 2

Instead of Delete After X. I Do Delete if Older Than X.

It will then cycle through the RecentlyWatched and Check the updatedAt="1383958310" variable.

I'll just have to decipher what their date/time formatting is. Then Compare it to the current DateAndTime and if its older then number of days you've configure it will delete it.


#13

Decided to implement Method One From the Last Post.

View The Change Log For The New Additons.

Code is now available for download, if you'd prefer to download it rather than copy paste.


#14

Decided to implement Method One From the Last Post.

View The Change Log For The New Additons.

Code is now available for download, if you'd prefer to download it rather than copy paste.

Nice work! Sounds like the best solution. I will load this up and test it out!

Edit:

OK, so it almost works! Here is a test On Deck situation I set up and the result:

Here is the On Deck items in media manager:

JupBuFh.png?1

Ep 3 - Walking Dead (On Deck, Unwatched)

Ep 1 - Top of the Lake (On Deck, In Progress)

Ep 5 - The Wrong Mans (On Deck, Unwatched)

Here is the script results (test mode:)

----------------------------------------------------------------------------
                           Detected Settings
----------------------------------------------------------------------------
Host: 127.0.0.1
Port: 32400
Section: 1
URL: http://127.0.0.1:32400/library/sections/1/recentlyViewed
OnDeck URL: http://127.0.0.1:32400/library/sections/1/onDeck
Show Count: 1
Number of Shows Detected For Keeping: 1
Shows to Keep: | Game of Thrones | 
Delete: Disabled - Flagging Only
Delete OnDeck: No
Operating System: Linux (Auto Detected)
----------------------------------------------------------------------------
----------------------------------------------------------------------------

**[FLAGGED] /Volumes/ext3TB/TV/Brooklyn Nine-Nine/Season 01/Brooklyn Nine-Nine - 1x08 - Old School.mkv
**[FLAGGED] /Volumes/ext3TB/TV/The Walking Dead/Season 04/The Walking Dead - 4x02 - Infected.mkv
**[FLAGGED] /Volumes/ext3TB/TV/The Walking Dead/Season 04/The Walking Dead - 4x01 - 30 Days Without an Accident.mkv
**[FLAGGED] /Volumes/ext3TB/TV/The Wrong Mans/Season 01/The Wrong Mans - 1x04 - Inside Mans.mkv
**[FLAGGED] /Volumes/ext3TB/TV/The Wrong Mans/Season 01/The Wrong Mans - 1x03 - Dead Mans.mkv
**[FLAGGED] /Volumes/ext3TB/TV/The Wrong Mans/Season 01/The Wrong Mans - 1x02 - Bad Mans.mkv
**[FLAGGED] /Volumes/ext3TB/TV/The Wrong Mans/Season 01/The Wrong Mans - 1x01 - The Wrong Mans.mkv
**[FLAGGED] /Volumes/ext3TB/TV/New Girl/Season 03/New Girl - 3x07 - Coach.mkv

----------------------------------------------------------------------------
----------------------------------------------------------------------------
                Summary -- Script Completed Successfully
----------------------------------------------------------------------------

  Total File Count  8
  Kept Show Files   0
  On Deck Files     0
  Deleted Files     0
  Flagged Files     8

----------------------------------------------------------------------------
----------------------------------------------------------------------------

So, here is what I see happening. The script would delete my last watched Brooklyn Nine-Nine show. This is bad because when a new episode shows up of Brooklyn Nine-Nine that new episode will not be "On Deck" anymore (because On deck is determined by "recently watched" episodes in the library and there is no longer a recently watched episode 08 any more.)

The same exact thing will happen to New Girl

Nearly the same thing will happen to The Walking Dead and The Wrong Mans. They have the next episodes in library and unwatched already. However, when the most recent "recently watched" episodes are deleted for those shows the current episode will no longer be "On Deck."

"In Progress" on deck episodes are fine of course but they were untouched with the previous version of the script since they are not marked as watched.

The way I see it, the script needs to check for an episodes On Deck status (as it already does) and then protect that shows previous episode from deletion. (always keeps the most recently watched episode of an "on deck" show around.)

I am loving this by the way! Excellent work!  :D


#15

Were they both the same OS version on the Macs?

I'll add Darwin in as the "Mac" auto-detect on the next release.

FYI, I tested the autodetect on three macs two running the latest OS X Mavericks and one running 10.7 (Lion.) They all worked for autodetect as Linux.


#16

FYI, I tested the autodetect on three macs two running the latest OS X Mavericks and one running 10.7 (Lion.) They all worked for autodetect as Linux.

Cool Good To Know, Thanks.

Nice work! Sounds like the best solution. I will load this up and test it out!

Edit:

OK, so it almost works! Here is a test On Deck situation I set up and the result:

Here is the On Deck items in media manager:

JupBuFh.png?1

Ep 3 - Walking Dead (On Deck, Unwatched)

Ep 1 - Top of the Lake (On Deck, In Progress)

Ep 5 - The Wrong Mans (On Deck, Unwatched)

Here is the script results (test mode:)

----------------------------------------------------------------------------
Detected Settings
----------------------------------------------------------------------------
Host: 127.0.0.1
Port: 32400
Section: 1
URL: http://127.0.0.1:32400/library/sections/1/recentlyViewed
OnDeck URL: http://127.0.0.1:32400/library/sections/1/onDeck
Show Count: 1
Number of Shows Detected For Keeping: 1
Shows to Keep: | Game of Thrones |
Delete: Disabled - Flagging Only
Delete OnDeck: No
Operating System: Linux (Auto Detected)
----------------------------------------------------------------------------
----------------------------------------------------------------------------

**[FLAGGED] /Volumes/ext3TB/TV/Brooklyn Nine-Nine/Season 01/Brooklyn Nine-Nine - 1x08 - Old School.mkv
**[FLAGGED] /Volumes/ext3TB/TV/The Walking Dead/Season 04/The Walking Dead - 4x02 - Infected.mkv
**[FLAGGED] /Volumes/ext3TB/TV/The Walking Dead/Season 04/The Walking Dead - 4x01 - 30 Days Without an Accident.mkv
**[FLAGGED] /Volumes/ext3TB/TV/The Wrong Mans/Season 01/The Wrong Mans - 1x04 - Inside Mans.mkv
**[FLAGGED] /Volumes/ext3TB/TV/The Wrong Mans/Season 01/The Wrong Mans - 1x03 - Dead Mans.mkv
**[FLAGGED] /Volumes/ext3TB/TV/The Wrong Mans/Season 01/The Wrong Mans - 1x02 - Bad Mans.mkv
**[FLAGGED] /Volumes/ext3TB/TV/The Wrong Mans/Season 01/The Wrong Mans - 1x01 - The Wrong Mans.mkv
**[FLAGGED] /Volumes/ext3TB/TV/New Girl/Season 03/New Girl - 3x07 - Coach.mkv

----------------------------------------------------------------------------
----------------------------------------------------------------------------
Summary -- Script Completed Successfully
----------------------------------------------------------------------------

Total File Count 8
Kept Show Files 0
On Deck Files 0
Deleted Files 0
Flagged Files 8

----------------------------------------------------------------------------
----------------------------------------------------------------------------

So, here is what I see happening. The script would delete my last watched Brooklyn Nine-Nine show. This is bad because when a new episode shows up of Brooklyn Nine-Nine that new episode will not be "On Deck" anymore (because On deck is determined by "recently watched" episodes in the library and there is no longer a recently watched episode 08 any more.)

The same exact thing will happen to New Girl

Nearly the same thing will happen to The Walking Dead and The Wrong Mans. They have the next episodes in library and unwatched already. However, when the most recent "recently watched" episodes are deleted for those shows the current episode will no longer be "On Deck."

"In Progress" on deck episodes are fine of course but they were untouched with the previous version of the script since they are not marked as watched.

The way I see it, the script needs to check for an episodes On Deck status (as it already does) and then protect that shows previous episode from deletion. (always keeps the most recently watched episode of an "on deck" show around.)

I am loving this by the way! Excellent work!  :D

That funny we have almost the exact same shows on our list.

Alright... Well that's weird.... I wonder if its because of the file paths containing spaces, as I noticed none of mine contained spaces.

Can you post me 2 CODE boxes with the contents of

1.) Contents of :  http://127.0.0.1:32400/library/sections/1/recentlyViewed

2.) Contents of:   http://127.0.0.1:32400/library/sections/1/onDeck
 

I might have to do a more intense check and grab the actual name of the show plus season and episode and compare it that way, then decide what to delete.

Cause if hits the right property you should get something like:

[KEEPING][OnDeck] /Media/TV/ShowName/ShowSeason/ShowEpisode.mkv

I'm really wondering if the spaces in the path is the issue...

Cause the code is simply cycling through the xml of the recentlyViewed page and yanking out the full file path.

Then Checking it for any NoDeleteShows, then checking if that file path matches the xml yanked files from the onDeck.


#17

1:

This XML file does not appear to have any style information associated with it. The document tree is shown below.











2:

This XML file does not appear to have any style information associated with it. The document tree is shown below.






#18

So, yours keeps the most recently watched episode around even though it is marked as watched?

Edit:

Doesn't the CheckOnDeck portion of the script need to do some kind of OnDeckEpisode# - 1 Episode = ProtectedEpisode# math to mark the previous to OnDeck episode as protected?

example:

OnDeckEpisode = The Walking Dead - S04E03

ProtectedEpisode = The Walking Dead - S04E02

 

Yeah, I don't code so I am just trying to interpret... haha

Edit 2:

I just realized that there is a hole in the above solution. In the scenario where all of the previous episodes have been watched and the upcoming show has not aired yet, the show would not currently have an OnDeck episode and would therefore delete the MostRecentlyWatchedEpisode because there is no OnDeckEpisode yet (hasn't aired yet.) This would cause the future episode to not be "On Deck" when it airs (shows up.)

Edit 3: 

What we really need is something like this:

if show is in [RecentlyViewed] then protect [LargestValueEpisode#OfViewedEpisodes] from deletion and allow deletion of the rest...

This would effectively keep 1 watched episode of any recently watched shows and this would allow On Deck to function properly!


#19

So, yours keeps the most recently watched episode around even though it is marked as watched?

Edit:

Doesn't the CheckOnDeck portion of the script need to do some kind of OnDeckEpisode# - 1 Episode = ProtectedEpisode# math to mark the previous to OnDeck episode as protected?

example:

OnDeckEpisode = The Walking Dead - S04E03

ProtectedEpisode = The Walking Dead - S04E02

 

Yeah, I don't code so I am just trying to interpret... haha

Edit 2:

I just realized that there is a hole in the above solution. In the scenario where all of the previous episodes have been watched and the upcoming show has not aired yet, the show would not currently have an OnDeck episode and would therefore delete the MostRecentlyWatchedEpisode because there is no OnDeckEpisode yet (hasn't aired yet.) This would cause the future episode to not be "On Deck" when it airs (shows up.)

Edit 3: 

What we really need is something like this:

if show is in [RecentlyViewed] then protect [LargestValueEpisode#OfViewedEpisodes] from deletion and allow deletion of the rest...

This would effectively keep 1 watched episode of any recently watched shows and this would allow On Deck to function properly!

No Mine Is Setup To Delete Any Show That Has Been Marked As Watched.

recentlyViewed is a collection of shows that have been watched.

From there I pull a view-count parameter and make sure its greater than 1. (This means you've actually marked the shows as watched).

Once Its met those 2 qualifiers, rather than grab the Show Name, Season, and Episode Name I just grabbed the file name as it is a pretty unique value in itself.

And by file name I'm mean full path + file name.

So when I'm cycling through all of the files in the recentlyViewed shows. I take that file name that I extracted and compare it to the ones in the onDeck.

So its almost the exact same cycle, its calling the onDeck, I'm ignoring the viewcount at this point cause its irrelevant as I'm just trying to see IF the file in my recentlyViewed is in onDeck at all.

So Yes, That is what the CheckOnDeck function is essentialist doing with the file names. It suppose to compare the recentlyShows against the onDeck and Protect it from getting deleted. If OnDeck is set to 1.

Again, I haven't full checked this out on a unix box, since I started working with windows more as it seems to be the pickiest of all the OS's.

So yes, I could go through and grab and compare episode showname etc, but I would think the Filename is a more unique value and would trump that of other values combined.

However, if I can't figure out why its not correctly comparing the filepaths, then I might have to go that route, its just more work and I wasn't seeing the need for it.

I'm not to sure how the OnDeck works, since i again, I don't use it.

I kinda understand what it does, but I'm not quite sure when and how it decides to populate itself. So that where my issue lies.

If when a show has been marked watched, it cycles through and determines if it should be listed in the onDeck.

Or if its on a timed cycle like when it checks your folders for new files.... That I don't really know.

Once I can figure how that function of plex actually operates I might be able to make this work a little better.

I do have another idea though, however, I'm not quite sure of the determining factor.

in the recentlyViewed, it assigns every episode a Title. However, I did notice some episodes are assigned a second title of Title2=OnDeck

What I don't know is if Title2 is always defined even if its blank and/or if OnDeck is only populated in the Title2 parameter.

So it looks like I have some work and research to do.. LOL


#20

Ah ha! I see why it's not working then. The script is trying to match RecentlyViewed episodes with OnDeck episodes. That will never happen. The episodes in OnDeck are always either UnWatched (or InProgress) so they will never match up to any episodes in RecentlyViewed (all always watched status.)

Here is how OnDeck works (in my understanding:)

If there is a TV episode marked as recently viewed then On Deck will show the next unwatched episode in that series as On Deck.

That Title2 parameter is very interesting. I wonder...