Normally, when you're watching a TV-Show — you don't need all its episodes right away; you just need a few for the next hour or so. The following scripts help you with exactly this! plex-autotag.py marks the new shows you add with tag keep1
; plex-autodelete.py removes watched episodes from your drive; sonarr-refresher.py triggers sonarr to download few new episodes, to keep you always having your next fix. All in all — sonarr will download you a new episode after you've watched one.
All this magic works only for "main" user.
The autodelete script was originally taken from plex-api and then it was modified to remove only watched episodes, plus I've added a couple of tags.
It would've been better to make the sonarr script to work directly with Plex API instead of relying on the deleted files, but I'm not there yet.
To get this working you'd need python3 with the packages listed in requirements.txt. Download all the *.py
files in this gist to your local drive, change all the things in triangle braces (like <PLEX URL>
) to the appropriate values, add the scripts to crontab like this:
@hourly python3 -u /<path>/plex-autotag.py > /dev/null 2>&1
*/15 * * * * bash -c 'python -u /<path>/plex-autodelete.py && python -u /<path>/sonarr-refresher.py' > /dev/null 2>&1
Values to change in the script:
<PLEX URL>
— URL to your plex setup, e.g.http://192.168.1.12:32400
<PLEX TOKEN>
— Plex API Token, you can get one using script plex-gettoken.py
The smallest of them all. Just scans your TV-Shows libraries and adds a tag keep1
to all the shows which don't have any tags/collections. You'll find more detailed description of the tags in the following section.
Values to change in the script:
<PLEX URL>
— URL to your plex setup, e.g.http://192.168.1.12:32400
<PLEX TOKEN>
— Plex API Token, you can get one using script plex-gettoken.py
Clean-ups all the shows having a tag keep*
. Tags keep0
, keep1
, keep3
, ... limits how many episodes you always want to keep, and removes the extra watched episodes. E.g. let's assume you have a show Game of Thrones
with episodes S01E01-06. If you assign tag keep1
to the show, that's what would be happening after the run of the script:
- For the very first run when all the episodes are unwatched, nothing would happen
- After you watched the first episode — it would be removed
- ... all the watched episodes until 6th would be removed
- When you'll watch the last episode, it'll stay in your library
I set keep1
for the ongoing shows and keep0
for the finished ones. This way, intro detection
for the ongoing shows would be working just fine, while the finished shows would be deleted from my collection after watching the last episode.
P.S. I have now idea how keepSeason
would work after my changes to the original script, never had to test it.
Values to change in the script:
<SONARR URL>
— URL to your sonarr setup, e.g.http://192.168.1.12:8989
<API KEY>
— the API key for your sonarr
The script scans all your monitored shows and downloads missing episodes, always keeping you with at least REQUIRED_EPISODES_RUNTIME
minutes of binge-time. Also, there's a separate runtime requirement set by REQUIRED_EPISODES_RUNTIME_FOR_PILOTS
for a show with pilot
tag, I set it for the shows I'm not sure in (i.e. collected from trakt anticipated
and trakt trending
lists).
E.g. Sherlock (UK, 2010)
has the runtime of 90 minutes, with default values for REQUIRED_EPISODES_RUNTIME
and REQUIRED_EPISODES_RUNTIME_FOR_PILOTS
you'll have 2 episodes downloaded without pilot
tag and 1 with it; Archer (2009)
has 25 minutes runtime — with default values you'd have 8 and 4 episodes respectively.
I recommend tweaking those variables depending on your connection speed, so you'd always have the next episode when you need one.
In addition to the default runtime requirements, you can set individual requirements for a show, by using tags like download_666_minutes
, where 666
is the runtime of the show you'd like to always have.
Is this still functional? Plex API seems deprecated.