Welcome to our forums! Please take a few moments to read through our Community Guidelines (also conveniently linked in the header at the top of each page). There, you'll find guidelines on conduct, tips on getting the help you may be searching for, and more!

Plex Auto-Delete Script

Steven4x4Steven4x4 Members, Plex Pass Posts: 42 Plex Pass
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.
«13456722

Comments

  • Steven4x4Steven4x4 Members, Plex Pass Posts: 42 Plex Pass
    edited March 17
    **** 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 : // <IP>:<PORT>/library/sections/<SECTION>/recenlyViewed
    <IP> = IP Address or Host name of the Server (You can also use 127.0.0.1 for localhost)
    <PORT> = Port For Plex Web Server (Default is 32400)
    <SECTION> = 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] (sig) 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("
    
    ")
    
  • Steven4x4Steven4x4 Members, Plex Pass Posts: 42 Plex Pass
    edited November 2013

    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

  • Steven4x4Steven4x4 Members, Plex Pass Posts: 42 Plex Pass
    edited November 2013

    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"

  • maxrogersmaxrogers Members, Plex Pass Posts: 58 Plex Pass
    edited November 2013

    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!!!

  • Steven4x4Steven4x4 Members, Plex Pass Posts: 42 Plex Pass
    edited November 2013

    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?

  • Nemesis7Nemesis7 Members Posts: 42 ✭✭

    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!

  • Steven4x4Steven4x4 Members, Plex Pass Posts: 42 Plex Pass
    edited November 2013

    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.

  • maxrogersmaxrogers Members, Plex Pass Posts: 58 Plex Pass
    Steven4x4 wrote on November 6 2013, 11:23 PM: »

    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

  • Steven4x4Steven4x4 Members, Plex Pass Posts: 42 Plex Pass
    edited November 2013

    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.

  • maxrogersmaxrogers Members, Plex Pass Posts: 58 Plex Pass
    edited November 2013
    Steven4x4 wrote on November 11 2013, 11:00 PM: »

    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.)

  • Steven4x4Steven4x4 Members, Plex Pass Posts: 42 Plex Pass
    edited November 2013
    STEEVo wrote on November 12 2013, 5:12 PM: »

    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.

  • Steven4x4Steven4x4 Members, Plex Pass Posts: 42 Plex Pass

    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.

  • maxrogersmaxrogers Members, Plex Pass Posts: 58 Plex Pass
    edited November 2013
    Steven4x4 wrote on November 13 2013, 12:12 PM: »

    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

  • maxrogersmaxrogers Members, Plex Pass Posts: 58 Plex Pass
    Steven4x4 wrote on November 12 2013, 6:07 PM: »

    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.

  • Steven4x4Steven4x4 Members, Plex Pass Posts: 42 Plex Pass
    edited November 2013
    STEEVo wrote on November 13 2013, 4:43 PM: »

    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.

    STEEVo wrote on November 13 2013, 4:35 PM: »

    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.

  • maxrogersmaxrogers Members, Plex Pass Posts: 58 Plex Pass

    1:

    This XML file does not appear to have any style information associated with it. The document tree is shown below.
    <MediaContainer size="9" allowSync="1" art="/:/resources/show-fanart.jpg" identifier="com.plexapp.plugins.library" librarySectionID="1" librarySectionUUID="46d08448-09b8-4218-ab0e-ba9a9b6a8960" mediaTagPrefix="/system/bundle/media/flags/" mediaTagVersion="1378415400" mixedParents="1" nocache="1" thumb="/:/resources/show.png" title1="TV Shows" title2="Recently Viewed Episodes" viewGroup="episode" viewMode="65592">
    <Video ratingKey="3600" key="/library/metadata/3600" parentRatingKey="3599" grandparentRatingKey="3598" type="episode" title="Old School" grandparentKey="/library/metadata/3598" parentKey="/library/metadata/3599" grandparentTitle="Brooklyn Nine-Nine" contentRating="TV-14" summary="Jake gets to spend the day with his hero, a former crime reporter; Terry and Charles work with Rosa on how she comes across on the witness stand. " index="8" parentIndex="1" rating="7" viewCount="1" year="2013" thumb="/library/metadata/3600/thumb/1384313967" art="/library/metadata/3598/art/1384313969" grandparentThumb="/library/metadata/3598/thumb/1384313969" duration="1294419" originallyAvailableAt="2013-11-12" addedAt="1384313652" updatedAt="1384313967">
    <Media videoResolution="720" id="3698" duration="1294419" bitrate="4378" width="1280" height="720" aspectRatio="1.78" audioChannels="6" audioCodec="ac3" videoCodec="h264" container="mkv" videoFrameRate="24p">
    <Part id="3727" key="/library/parts/3727/file.mkv" duration="1294419" file="/Volumes/ext3TB/TV/Brooklyn Nine-Nine/Season 01/Brooklyn Nine-Nine - 1x08 - Old School.mkv" size="708391254" container="mkv"/>
    </Media>
    </Video>
    <Video ratingKey="2699" key="/library/metadata/2699" parentRatingKey="2697" grandparentRatingKey="2696" type="episode" title="Infected" grandparentKey="/library/metadata/2696" parentKey="/library/metadata/2697" grandparentTitle="The Walking Dead" contentRating="TV-14" summary="As the group faces a brand new enemy, Rick and the others must fight to protect the livelihood they worked so hard to create at the prison." index="2" parentIndex="4" rating="7.9" viewCount="1" year="2013" thumb="/library/metadata/2699/thumb/1382975292" art="/library/metadata/2696/art/1384172534" grandparentThumb="/library/metadata/2696/thumb/1384172534" grandparentTheme="/library/metadata/2696/theme/1384172534" duration="2583876" originallyAvailableAt="2013-10-20" addedAt="1382975206" updatedAt="1382975292">
    <Media videoResolution="720" id="2393" duration="2583876" bitrate="4247" width="1280" height="718" aspectRatio="1.78" audioChannels="2" audioCodec="aac" videoCodec="h264" container="mkv" videoFrameRate="24p">
    <Part id="2416" key="/library/parts/2416/file.mkv" duration="2583876" file="/Volumes/ext3TB/TV/The Walking Dead/Season 04/The Walking Dead - 4x02 - Infected.mkv" size="1371559538" container="mkv"/>
    </Media>
    <Writer tag="Angela Kang"/>
    <Director tag="Guy Ferland"/>
    </Video>
    <Video ratingKey="2698" key="/library/metadata/2698" parentRatingKey="2697" grandparentRatingKey="2696" type="episode" title="30 Days Without an Accident" grandparentKey="/library/metadata/2696" parentKey="/library/metadata/2697" grandparentTitle="The Walking Dead" contentRating="TV-14" summary="Old and new members of the group seem to have made themselves at home in the prison, when a scouting expedition for provisions goes terribly wrong. Rick has to deal with a lost soul outside the gates." index="1" parentIndex="4" rating="7.8" viewCount="1" year="2013" thumb="/library/metadata/2698/thumb/1382975291" art="/library/metadata/2696/art/1384172534" grandparentThumb="/library/metadata/2696/thumb/1384172534" grandparentTheme="/library/metadata/2696/theme/1384172534" duration="2583808" originallyAvailableAt="2013-10-13" addedAt="1382975206" updatedAt="1382975291">
    <Media videoResolution="720" id="2392" duration="2583808" bitrate="4497" width="1280" height="718" aspectRatio="1.78" audioChannels="6" audioCodec="ac3" videoCodec="h264" container="mkv" videoFrameRate="24p">
    <Part id="2415" key="/library/parts/2415/file.mkv" duration="2583808" file="/Volumes/ext3TB/TV/The Walking Dead/Season 04/The Walking Dead - 4x01 - 30 Days Without an Accident.mkv" size="1452542118" container="mkv"/>
    </Media>
    <Writer tag="Scott M. Gimple"/>
    <Director tag="Greg Nicotero"/>
    </Video>
    <Video ratingKey="1146" key="/library/metadata/1146" parentRatingKey="1145" grandparentRatingKey="1144" type="episode" title="Episode 1" grandparentKey="/library/metadata/1144" parentKey="/library/metadata/1145" grandparentTitle="Top of the Lake" contentRating="TV-14" summary="In a breathtaking but remote mountain town in South Island, New Zealand, a twelve year-old girl named Tui is discovered to be pregnant. Local police enlist help from Detective Robin Griffin, a child protection specialist who has recently returned to the area to care for her mother. Tui refuses to disclose any clues about her perpetrator, but the town’s knot of long-buried secrets begins to unravel. Trapped where happiness and honest work are just out of reach, the entire community is under a smoldering cloud of suspicion. Chief suspect is the girl’s father, a menacing local figure with a violent past who is also embroiled in a land dispute with a new age women’s encampment. Robin’s investigation heightens tensions in the town and hints at a personal history she had hoped to keep buried." index="1" parentIndex="1" rating="7.4" viewOffset="189497" year="2013" thumb="/library/metadata/1146/thumb/1380934536" art="/library/metadata/1144/art/1380934536" grandparentThumb="/library/metadata/1144/thumb/1380934536" duration="2972202" originallyAvailableAt="2013-03-18" addedAt="1380933238" updatedAt="1380934536">
    <Media videoResolution="720" id="975" duration="2972202" bitrate="4187" width="960" height="720" aspectRatio="1.78" audioChannels="2" audioCodec="aac" videoCodec="h264" container="mkv" videoFrameRate="PAL">
    <Part id="975" key="/library/parts/975/file.mkv" duration="2972202" file="/Volumes/ext3TB/TV/Top of the Lake/Season 01/Top of the Lake - 1x01 - Episode 1.mkv" size="1555499314" container="mkv"/>
    </Media>
    <Writer tag="Jane Campion"/>
    <Writer tag="Gerard Lee"/>
    <Director tag="Jane Campion"/>
    </Video>
    <Video ratingKey="3596" key="/library/metadata/3596" parentRatingKey="3589" grandparentRatingKey="3588" type="episode" title="Inside Mans" grandparentKey="/library/metadata/3588" parentKey="/library/metadata/3589" grandparentTitle="The Wrong Mans" summary="The devious Scarlett sends Sam and Phil on a mission to retrieve a music box, which has fallen into the hands of eccentric Russian exile Marat Milankovic. Armed only with the ransom money they found in the back of Walker's car, the duo set off to buy it back. But with the vengeful Lau still seeking payback, Sam and Phil find themselves arriving empty-handed at a drug-fuelled house party. Inadvertently stumbling into the middle of a poisonous assassination plot, the boys are plunged deeper into a world of betrayal, bullets and blood." index="4" parentIndex="1" rating="7" viewCount="1" year="2013" thumb="/library/metadata/3596/thumb/1384230530" art="/library/metadata/3588/art/1384219008" grandparentThumb="/library/metadata/3588/thumb/1384219008" duration="1741960" originallyAvailableAt="2013-10-15" addedAt="1384230519" updatedAt="1384230530">
    <Media videoResolution="720" id="3668" duration="1741960" bitrate="7164" width="1280" height="720" aspectRatio="1.78" audioChannels="2" audioCodec="dca" videoCodec="h264" container="mkv" videoFrameRate="PAL">
    <Part id="3697" key="/library/parts/3697/file.mkv" duration="1741960" file="/Volumes/ext3TB/TV/The Wrong Mans/Season 01/The Wrong Mans - 1x04 - Inside Mans.mkv" size="1559967900" container="mkv"/>
    </Media>
    <Writer tag="James Corden"/>
    <Writer tag="Matthew Baynton"/>
    <Director tag="Jim Field Smith"/>
    </Video>
    <Video ratingKey="3595" key="/library/metadata/3595" parentRatingKey="3589" grandparentRatingKey="3588" type="episode" title="Dead Mans" grandparentKey="/library/metadata/3588" parentKey="/library/metadata/3589" grandparentTitle="The Wrong Mans" summary="When Lau shows up at the council offices, Sam successfully negotiates the safe handover of Scarlett in exchange for Lau's nephew Jason. But Phil has his own ideas and nearly scuppers the plan. Narrowly escaping, they pay a visit to Phil's mum Linda before taking Scarlett back to her husband. But it's not the happy reunion they imagined, and Sam and Phil must go on the run from both cops and criminals, until finding temporary safety in the hands of enigmatic MI5 agent Walker." index="3" parentIndex="1" rating="8" viewCount="1" year="2013" thumb="/library/metadata/3595/thumb/1384230530" art="/library/metadata/3588/art/1384219008" grandparentThumb="/library/metadata/3588/thumb/1384219008" duration="1731960" originallyAvailableAt="2013-10-08" addedAt="1384230519" updatedAt="1384230530">
    <Media videoResolution="720" id="3667" duration="1731960" bitrate="7205" width="1280" height="720" aspectRatio="1.78" audioChannels="2" audioCodec="dca" videoCodec="h264" container="mkv" videoFrameRate="PAL">
    <Part id="3696" key="/library/parts/3696/file.mkv" duration="1731960" file="/Volumes/ext3TB/TV/The Wrong Mans/Season 01/The Wrong Mans - 1x03 - Dead Mans.mkv" size="1559762225" container="mkv"/>
    </Media>
    <Writer tag="Tom Basden"/>
    <Writer tag="Matthew Baynton"/>
    <Director tag="Jim Field Smith"/>
    </Video>
    <Video ratingKey="3594" key="/library/metadata/3594" parentRatingKey="3589" grandparentRatingKey="3588" type="episode" title="Bad Mans" grandparentKey="/library/metadata/3588" parentKey="/library/metadata/3589" grandparentTitle="The Wrong Mans" summary="Nick Stevens is heavily in debt to Mr Lau, a local underground casino boss who has now kidnapped his wife Scarlett. With no money, no skills and no idea, Phil and Sam are sent to rescue her by the cowardly Stevens. Sure enough, it doesn't go very well, and in the melee our heroes end up accidentally taking an angry hostage of their own." index="2" parentIndex="1" rating="8" viewCount="1" year="2013" thumb="/library/metadata/3594/thumb/1384229193" art="/library/metadata/3588/art/1384219008" grandparentThumb="/library/metadata/3588/thumb/1384219008" duration="1735960" originallyAvailableAt="2013-10-01" addedAt="1384229173" updatedAt="1384229193">
    <Media videoResolution="720" id="3662" duration="1735960" bitrate="7189" width="1280" height="720" aspectRatio="1.78" audioChannels="2" audioCodec="dca" videoCodec="h264" container="mkv" videoFrameRate="PAL">
    <Part id="3691" key="/library/parts/3691/file.mkv" duration="1735960" file="/Volumes/ext3TB/TV/The Wrong Mans/Season 01/The Wrong Mans - 1x02 - Bad Mans.mkv" size="1559877746" container="mkv"/>
    </Media>
    <Writer tag="James Corden"/>
    <Writer tag="Matthew Baynton"/>
    <Director tag="Jim Field Smith"/>
    </Video>
    <Video ratingKey="3590" key="/library/metadata/3590" parentRatingKey="3589" grandparentRatingKey="3588" type="episode" title="The Wrong Mans" titleSort="Wrong Mans" grandparentKey="/library/metadata/3588" parentKey="/library/metadata/3589" grandparentTitle="The Wrong Mans" summary="Lowly council employee Sam Pinkett is the sole witness to a shocking car accident. Answering a ringing mobile phone which he finds at the crash site, he suddenly finds himself mixed up in a deadly kidnap plot. Shocked and hungover, Sam also has problems mounting up at work, where his boss and ex-girlfriend Lizzie feels like he isn't pulling his weight. But his excitable colleague Phil convinces him they need to step up and save the day - and after a trip to the hospital this day goes from bad to worse." index="1" parentIndex="1" rating="8" viewCount="1" year="2013" thumb="/library/metadata/3590/thumb/1384219008" art="/library/metadata/3588/art/1384219008" grandparentThumb="/library/metadata/3588/thumb/1384219008" duration="1744960" originallyAvailableAt="2013-09-24" addedAt="1384218978" updatedAt="1384219008">
    <Media videoResolution="720" id="3650" duration="1744960" bitrate="7152" width="1280" height="720" aspectRatio="1.78" audioChannels="2" audioCodec="dca" videoCodec="h264" container="mkv" videoFrameRate="PAL">
    <Part id="3679" key="/library/parts/3679/file.mkv" duration="1744960" file="/Volumes/ext3TB/TV/The Wrong Mans/Season 01/The Wrong Mans - 1x01 - The Wrong Mans.mkv" size="1560100889" container="mkv"/>
    </Media>
    <Writer tag="James Corden"/>
    <Writer tag="Matthew Baynton"/>
    <Director tag="Jim Field Smith"/>
    </Video>
    <Video ratingKey="3560" key="/library/metadata/3560" parentRatingKey="3559" grandparentRatingKey="3558" type="episode" title="Coach" grandparentKey="/library/metadata/3558" parentKey="/library/metadata/3559" grandparentTitle="New Girl" contentRating="TV-14" summary="A newly single Coach returns to the loft, and wants to pick up exactly where he left off when he moved out. Meanwhile Jess and Cece have a girls' night out, during which they meet a handsome stranger." index="7" parentIndex="3" rating="9" viewCount="1" year="2013" thumb="/library/metadata/3560/thumb/1383753353" art="/library/metadata/3558/art/1383753353" grandparentThumb="/library/metadata/3558/thumb/1383753353" grandparentTheme="/library/metadata/3558/theme/1383753353" duration="1303637" originallyAvailableAt="2013-11-05" addedAt="1383753288" updatedAt="1383753353">
    <Media videoResolution="720" id="3436" duration="1303637" bitrate="4482" width="1280" height="718" aspectRatio="1.78" audioChannels="6" audioCodec="ac3" videoCodec="h264" container="mkv" videoFrameRate="24p">
    <Part id="3460" key="/library/parts/3460/file.mkv" duration="1303637" file="/Volumes/ext3TB/TV/New Girl/Season 03/New Girl - 3x07 - Coach.mkv" size="730435931" container="mkv"/>
    </Media>
    <Writer tag="David Feeney"/>
    <Director tag="Russ Alsobrook"/>
    </Video>
    </MediaContainer>
    

    2:

    This XML file does not appear to have any style information associated with it. The document tree is shown below.
    <MediaContainer size="3" allowSync="1" art="/:/resources/show-fanart.jpg" identifier="com.plexapp.plugins.library" librarySectionID="1" librarySectionUUID="46d08448-09b8-4218-ab0e-ba9a9b6a8960" mediaTagPrefix="/system/bundle/media/flags/" mediaTagVersion="1378415400" mixedParents="1" nocache="1" thumb="/:/resources/show.png" title1="TV Shows" title2="On Deck" viewGroup="episode" viewMode="65592">
    <Video ratingKey="2878" key="/library/metadata/2878" parentRatingKey="2697" grandparentRatingKey="2696" type="episode" title="Isolation" grandparentKey="/library/metadata/2696" parentKey="/library/metadata/2697" grandparentTitle="The Walking Dead" contentRating="TV-14" summary="A group leaves the prison to search for supplies. The remaining members of the group deal with recent losses." index="3" parentIndex="4" rating="7.9" year="2013" thumb="/library/metadata/2878/thumb/1383559761" art="/library/metadata/2696/art/1384172534" parentThumb="/library/metadata/2697/thumb/1382975292" grandparentThumb="/library/metadata/2696/thumb/1384172534" grandparentTheme="/library/metadata/2696/theme/1384172534" duration="2576704" originallyAvailableAt="2013-10-27" addedAt="1382984389" updatedAt="1383559761">
    <Media videoResolution="720" id="2550" duration="2576704" bitrate="4122" width="1280" height="718" aspectRatio="1.78" audioChannels="2" audioCodec="aac" videoCodec="h264" container="mkv" videoFrameRate="24p">
    <Part id="2573" key="/library/parts/2573/file.mkv" duration="2576704" file="/Volumes/ext3TB/TV/The Walking Dead/Season 04/The Walking Dead - 4x03 - Isolation.mkv" size="1327547122" container="mkv"/>
    </Media>
    <Writer tag="Robert Kirkman"/>
    <Director tag="Dan Sackheim"/>
    </Video>
    <Video ratingKey="1146" key="/library/metadata/1146" parentRatingKey="1145" grandparentRatingKey="1144" type="episode" title="Episode 1" grandparentKey="/library/metadata/1144" parentKey="/library/metadata/1145" grandparentTitle="Top of the Lake" contentRating="TV-14" summary="In a breathtaking but remote mountain town in South Island, New Zealand, a twelve year-old girl named Tui is discovered to be pregnant. Local police enlist help from Detective Robin Griffin, a child protection specialist who has recently returned to the area to care for her mother. Tui refuses to disclose any clues about her perpetrator, but the town’s knot of long-buried secrets begins to unravel. Trapped where happiness and honest work are just out of reach, the entire community is under a smoldering cloud of suspicion. Chief suspect is the girl’s father, a menacing local figure with a violent past who is also embroiled in a land dispute with a new age women’s encampment. Robin’s investigation heightens tensions in the town and hints at a personal history she had hoped to keep buried." index="1" parentIndex="1" rating="7.4" viewOffset="189497" year="2013" thumb="/library/metadata/1146/thumb/1380934536" art="/library/metadata/1144/art/1380934536" grandparentThumb="/library/metadata/1144/thumb/1380934536" duration="2972202" originallyAvailableAt="2013-03-18" addedAt="1380933238" updatedAt="1380934536">
    <Media videoResolution="720" id="975" duration="2972202" bitrate="4187" width="960" height="720" aspectRatio="1.78" audioChannels="2" audioCodec="aac" videoCodec="h264" container="mkv" videoFrameRate="PAL">
    <Part id="975" key="/library/parts/975/file.mkv" duration="2972202" file="/Volumes/ext3TB/TV/Top of the Lake/Season 01/Top of the Lake - 1x01 - Episode 1.mkv" size="1555499314" container="mkv"/>
    </Media>
    <Writer tag="Jane Campion"/>
    <Writer tag="Gerard Lee"/>
    <Director tag="Jane Campion"/>
    </Video>
    <Video ratingKey="3591" key="/library/metadata/3591" parentRatingKey="3589" grandparentRatingKey="3588" type="episode" title="Wanted Mans" grandparentKey="/library/metadata/3588" parentKey="/library/metadata/3589" grandparentTitle="The Wrong Mans" summary="Having agreed to take care of the hunted and wounded Marat, Sam and Phil return back to Phil's house where his mum Linda proves surprisingly resourceful. With spies shadowing their every move, our heroes inadvertently bring the dangerous plot right to their doorsteps and ultimately, to the council offices. By arranging to hand over Marat to the care of MI5, they think they can wash their hands of their troubles. Yet the duplicitous Agent Smoke has other plans and just as our two unlikely heroes start to figure out what is afoot, they become high-value fugitives." index="5" parentIndex="1" rating="7" year="2013" thumb="/library/metadata/3591/thumb/1384220335" art="/library/metadata/3588/art/1384219008" grandparentThumb="/library/metadata/3588/thumb/1384219008" duration="1741960" originallyAvailableAt="2013-10-22" addedAt="1384220325" updatedAt="1384220335">
    <Media videoResolution="720" id="3653" duration="1741960" bitrate="7164" width="1280" height="720" aspectRatio="1.78" audioChannels="2" audioCodec="dca" videoCodec="h264" container="mkv" videoFrameRate="PAL">
    <Part id="3682" key="/library/parts/3682/file.mkv" duration="1741960" file="/Volumes/ext3TB/TV/The Wrong Mans/Season 01/The Wrong Mans - 1x05 - Wanted Mans.mkv" size="1559879239" container="mkv"/>
    </Media>
    <Writer tag="Tom Basden"/>
    <Writer tag="Matthew Baynton"/>
    <Director tag="Jim Field Smith"/>
    </Video>
    </MediaContainer>
    
  • maxrogersmaxrogers Members, Plex Pass Posts: 58 Plex Pass
    edited November 2013

    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!

  • Steven4x4Steven4x4 Members, Plex Pass Posts: 42 Plex Pass
    edited November 2013
    STEEVo wrote on November 13 2013, 6:28 PM: »

    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

  • maxrogersmaxrogers Members, Plex Pass Posts: 58 Plex Pass
    edited November 2013

    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... 

  • Steven4x4Steven4x4 Members, Plex Pass Posts: 42 Plex Pass
    STEEVo wrote on November 14 2013, 5:59 AM: »

    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... 

    Hmm, now I'm a little confused.

    Given what you just said that OnDeck is either Un-watched or In-progress. Then the original script, should have touched it at all. Unless the view-count isn't correct. But I thought I originally tested that watching shows half way through and watching shows fully threw even marking it as watched and then re-marking it as unwatched and it either changed that count or set it to 0. BUT Speaking that out loud now I think I just found a small coding flaw. As view-count isn't resetting to zero so it might keep the value of the file it previously checked.. Which is why it might deleting some shows that it shouldn't be..

    So yea, like I said it should only be deleting shows that were marked as watched, if its unwatched or in progress, it shouldn't be deleted. That was the idea at least LOL.

    But yea, I think I need to add a fix for resetting that view-count so that it doesn't accidentally take the previous files incase the next file doesn't have it.

    Plex is wierd (and its probably for performance reasons) but a show will only have a view-count paremeter if its been viewed. Otherwise it will not have a view-count of 0. UNLESS you have marked it as watched and then re-marked it as watched.

    OK, enough blabbing gotta head to work.

    I'll take a look at that view-count thing sometime in the next 24 hours if I can and I'll post it when its done.

    Thanks for you interest, help and feedback on this project. I appreciate it.

«13456722
Sign In or Register to comment.