Skip to content

MilkmanWes/py-plex

 
 

Repository files navigation

I wanted a way to automate housekeeping between Plex and Sickbeard. the idea is this:

  • Scan a Plex server for watched shows
  • Delete the media files (in the future this may move the files to a back up location or tar them)
  • Update SickBeard to mark the deleted episodes as Archived (because we are ocd like that)

I want the ability to do the following by cli or ini set options

  • Specify list of libraries to scan
  • Specify list of libraries to skip (scan all except x)
  • Specify list of show to scan
  • Specify list of shows to skip (scan all except x)
  • Specify the Plex server and Sickbeard server for uses where you may have multiples of either
  • Ability to run as a one off or with preserved settings via ini file

The idea is that I can run this as a cron job monthly or whatever. I decided to build my own features into a fork of py-plex since it had a foundation that let me just start on the features I wanted without having to lay too much groundwork.

#Using the ini Copy plexpurge.ini.sample to plexpurge.ini and edit to match your settings.

Each library on your Plex server should be listed as a section head in the ini. Libraries NOT INCLUDED are not scanned by plexpurge

In each library section list any shows you want to be excluded. This is a safe list so any shows included WILL NOT have watched episodes purged, so if you think you may want to rewatch old episodes of Alf 3 or 4 times you need to list it.

Right now this just prints out some things as it parses libraries and shows.

  • Shows are only scanned in libraries that are specified. Given the show "Breaking Thrones" is in the "My Library"

    The show will be scanned and acted upon with this: -s "Breaking Thrones -l "My Library"

    Nothing will happen with this: -s "Breaking Thrones" -L "My Library" or -s "Breaking Thrones -l "My Other Library"

  • Shows that exist in multiple Libraries. Show scan and safe lists are not library specific. So any show that is in two libraries will be scanned or skipped in both. If you want to act on it in one library and not another then run this two times specifying a different library each time.

using cli

usage: plexpurge.py [-h] [-p] [-d] [-c] [-D] [-l [SCANLIBRARY [SCANLIBRARY ...]]] [-s [SCANSHOW [SCANSHOW ...]]] [-L [SKIPLIBRARY [SKIPLIBRARY ...]]] [-S SKIPSHOW [SKIPSHOW ...]] [-i INI_FILE] [-v] [-pa PLEXADDRESS] [-sb] [-sa SICKADDRESS]

This will scan a Plex server for all watched shows and delete the media files. Once deleted it will update the SickBeard server and mark the episode as archived

optional arguments: -h, --help show this help message and exit -p, --print Print purge candidates -d, --purge Scan and Purge watched shows -c, --confirm Confirm each file deletion -D, --delete_all Purge ALL watched (all libraries, ignore safelists) -l [SCANLIBRARY [SCANLIBRARY ...]], --library [SCANLIBRARY [SCANLIBRARY ...]] Comma delimited list of libraries to scan. -s [SCANSHOW [SCANSHOW ...]], --show [SCANSHOW [SCANSHOW ...]] Scan only this show -L [SKIPLIBRARY [SKIPLIBRARY ...]], --skip_library [SKIPLIBRARY [SKIPLIBRARY ...]] Skip this library -S SKIPSHOW [SKIPSHOW ...], --skip_show SKIPSHOW [SKIPSHOW ...] Skip this show -i INI_FILE, --ini_file INI_FILE Specify ini file (uses plexpurge.ini if omitted) -v, --verbose Be really chatty -pa PLEXADDRESS, --plex_address PLEXADDRESS Address for Plex server (omit http://) in the form address:port. If port is left off the default of 32400 is used -sb, --updateSB Update SickBeard to mark deleted episodes as Archived -sa SICKADDRESS, --sick_address SICKADDRESS Address for SickBeard server (omit http://) in the form address:port. If port is left off the default of 32400 is used

Derived from the py-plex project by rueckstiess @ https://github.com/rueckstiess/py-plex. Their code is included in its entirety and changes noted where made via comment lines

Original README from rueckstiess explaining the py-plex functions py-plex

Python wrapper for the Plex Media Server http/xml API. This is work in progress (in its early stage).

Some examples of what you can currently do:

from server import Server

server = Server(ip_address, 32400)      # insert your Plex server's ip address
client = server.clients[0]              # get first client

section = server.library.shows[0]       # get first TV Shows section
shows = section.getContent('newest')    # sort shows by 'newest'
season4 = shows[0].getSeason(4)         # get season 4 of first show in list
episode = season4.episodes[0]           # get first episode of season 4

print episode.title, episode.summary    # print title and summary

client.playVideo(episode)               # start playing this episode on client
client.runCommand('pause')              # pause client
client.runCommand('skipNext')           # next episode
client.runCommand('stop')               # stop playback

# returns a list of matching movies
results = server.library.findMovies('Die Hard')   

# find TV Show 'Game of Thrones' and play the next unwatched episode
game_of_thrones = server.library.findShows('Game of Thrones')[0]
latest = game_of_thrones.getNextUnwatchedEpisode()
client.playVideo(latest)

About

Purging of watched espisodes out of Plex.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%