Plex Auto-Delete Script

Downloaded the latest version from Git, but I get this error:

  File "PlexCleaner.py", line 498
    elif os.path.isfile("Cleaner.cfg")

Ok sorry, I'm still getting used to git, that error should be fixed now. As far as onDeck, I don't know why it wasn't working for you, it's working for me. Try the newest version.

Pulling the latest from Git solved the problem... well all problems actually.

It still reports that there are 4 episodes On Deck, but it deleted/moved the episodes i watched yesterday.

Good work!!

Thanks!

I'll look into what's going on with onDeck, but thanks for being patient and testing it out. I'm glad it's working right now atleast.

What are your thoughts on the config file if you use it?

I can confirm the OnDeck problem. I watched two shows last night and neither have been moved to my preset prune directory. I know the move works as I tested it yesterday and it moved like 10 files out that were watched. I went into the Plex panel and the two episodes I watched last night are "not" OnDeck. I checked each one and each one is set to "Watched". But in the log it just shows [Keeping]. So I don't know, I would figure it's the ondeck thing as well.

I personally use the config file instead of config inside the script. I like the config file personally. Good job :)

Glad to hear the config file works for you. I pushed an update to check onDeck for all files and to log it with the other info, hopefully this will fix the issue or help track the miscounts.

Updated and ran a test.

Still works for me, remove the episode just watched.

Btw, didn't the old version signal to Plex that the file was deleted and told Plex to update the library?

Hey, great job on the github stuff!

I am experiencing a new error with the latest ver off of git:

This World - S2014xE002 - The Coffee Trail with Simon Reeve | Viewed: 0 | Days Since Last Viewed: 0 | On Deck: False

[Keeping] /home/plex/series/This World/Season 2014/This.World.S2014E02.SD.TV-SiCKBEARD.mkv

 

Traceback (most recent call last):

  File "./PlexCleaner.py", line 684, in

    changed += checkShow(getURLX("http://" + Host + ":" + Port + show_key))

  File "./PlexCleaner.py", line 445, in checkShow

    season = getURLX("http://" + Host + ":" + Port + season_key)

  File "./PlexCleaner.py", line 205, in getURLX

    return xml.dom.minidom.parse(urllib2.urlopen(req))

  File "/usr/lib/python2.7/urllib2.py", line 126, in urlopen

    return _opener.open(url, data, timeout)

  File "/usr/lib/python2.7/urllib2.py", line 406, in open

    response = meth(req, response)

  File "/usr/lib/python2.7/urllib2.py", line 519, in http_response

    'http', request, response, code, msg, hdrs)

  File "/usr/lib/python2.7/urllib2.py", line 444, in error

    return self._call_chain(*args)

  File "/usr/lib/python2.7/urllib2.py", line 378, in _call_chain

    result = func(*args)

  File "/usr/lib/python2.7/urllib2.py", line 527, in http_error_default

    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)

urllib2.HTTPError: HTTP Error 500: Internal Server Error

 

Next show in folder is 'Those\ Who\ Kill\ \(US\)', if that helps. Thanks for all the hard work!

Ran into another error when I enabled delete

The Zero Theorem | Viewed: 0 | Days Since Viewed: 0 | On Deck: False

[Keeping] /home/plex/movies/Z/The Zero Theorem (2013)/The.Zero.Theorem.2013.720p.BluRay.DD5.1.x264-HiFi.mkv

 

Cleaning up orphaned folders less than 30MB in Section 1

**[DELETED] /home/plex/movies/0

Traceback (most recent call last):

  File "./PlexCleaner.py", line 686, in

    getURLX("http://" + Host + ":" + Port + "/library/sections/" + Section + "/refresh")

  File "./PlexCleaner.py", line 205, in getURLX

    return xml.dom.minidom.parse(urllib2.urlopen(req))

  File "/usr/lib/python2.7/xml/dom/minidom.py", line 1920, in parse

    return expatbuilder.parse(file)

  File "/usr/lib/python2.7/xml/dom/expatbuilder.py", line 928, in parse

    result = builder.parseFile(file)

  File "/usr/lib/python2.7/xml/dom/expatbuilder.py", line 211, in parseFile

    parser.Parse("", True)

xml.parsers.expat.ExpatError: no element found: line 1, column 0

Ok I added try and except to the url open method. It will retry 3 times and if it fails the rest of the script should just skip over whatever was failing. I also fixed the issue with trigger_rescan.

@Wheezer I don't think cleanup_movie_folders is a good option for you because you store your movie files in alphabetical subdirectories. It looks like the script deleted your 0 folder in your movie directory because it was probably empty. This could be a problem for you. The script also will only look at folders in the movie root and doesn't recursively check subdirectories.

Right now cleanup_movie_folders just searches the movie root directory specified by plex for folders that are smaller than the minimum size. It doesn't intelligently look to see if it matches any movie file that was deleted.

Added a couple of updates.

So now cleanup_movie_folders will not delete directories that are one character long, but will instead search through those directories for folders less than the minimum size. Hopefully this helps the people who store their movies in alphabetical folders.

Also added a new settings section specifically for Movies libraries. Run the script and it will update the config file, or you can edit the script directly.

I tested it a bit, but let me know how it works.

The format for each single show in the config file is a little bit unstructured. With what program should i open this on Windows?

Added a couple of updates.

So now cleanup_movie_folders will not delete directories that are one character long, but will instead search through those directories for folders less than the minimum size. Hopefully this helps the people who store their movies in alphabetical folders.

Also added a new settings section specifically for Movies libraries. Run the script and it will update the config file, or you can edit the script directly.

I tested it a bit, but let me know how it works.

Cheers, works a treat!

The format for each single show in the config file is a little bit unstructured. With what program should i open this on Windows?

I know the config file is difficult to read, but it is the best default method in python that I have found. For windows I would recommend getting a text editor that is not Notepad. Personally I use SublimeText, which is free, but has a nag screen. Another editor I have used in the past are Notepad++ or Atom. If the text editor you have has syntax highlighting, enable it for JSON.

If you have trouble editing the file directly, you can make a copy of the script after you checkout from GitHub, and input settings into the copied file. Then run that script with the --dump [file] option and it will make a config file for you. This way you won't modify the original file and will still be able to pull new updates. I will try to keep the script able to automatically update the config file if any new options are added.

I put the script in task scheduler...but nothing I don't know what try..

I put the script in task scheduler...but nothing I don't know what try..

Are you in Windows or Linux or Mac? What command did you place in the scheduler? Also, have you tried the script from the command line without the scheduler to see it's output?

@jfreak he is using a Synology NAS device @MarcoBishero, did you install Python2 from the Synocommunity repo? That is required. http://synocommunity.com

Ah! Then yeah, I have no clue haha. Glad you were paying attention as I wasn't ;)

Yes! I've installed it :S

I've no idea what's wrong. Late I'll go another test..from the command line goes all smoothly.

Good script btw..Bravo!! ;) ;)

What is the exact command you have in task manager? What is the output of this command via ssh: “which python”