Last active
April 12, 2025 23:50
-
-
Save khaosx/ebd588a80c12dea11512e6ca9873effa to your computer and use it in GitHub Desktop.
Creates a playlist in Plex with the first unwatched episode of your current shows.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script creates a playlist that contains the next unwatched episode of any | |
# shows you define in a collection. | |
# | |
# Requires python 3 | |
# | |
# Usage: | |
# | |
# In Plex, create a collection named "Current Shows". It should contain all the shows | |
# that you want considered for the new playlist. | |
# | |
# Update the variables to match your environment. Search Google for details on how to find | |
# your X-Plex-Token value. | |
# | |
# Then you can run this to create or recreate your playlist: | |
# python current_shows_playlist.py | |
# Update these: | |
PLEX_URL = 'http://my.plex.server:32400' | |
PLEX_TOKEN = 'my_plex_token' | |
# Leave all this alone! | |
import os, operator, time, sys, datetime, re | |
import requests | |
from plexapi.server import PlexServer | |
baseurl = PLEX_URL | |
token = PLEX_TOKEN | |
plex = PlexServer(baseurl, token) | |
MY_PLAYLIST = 'Current Shows' | |
for playlist in plex.playlists(): | |
if playlist.title == MY_PLAYLIST: | |
print('{} already exists. Deleting and rebuilding.'.format(MY_PLAYLIST)) | |
playlist.delete() | |
tv_shows_section = plex.library.section('TV') | |
episode_list = [] | |
for collection in tv_shows_section.collection(): | |
regexp = re.compile(r'Current Shows') | |
if not regexp.search(collection.title): | |
break | |
print(collection) | |
for tv_show in collection.children: | |
print(tv_show) | |
for episode in tv_show.episodes(): | |
if not episode.isWatched: | |
print(episode.title) | |
episode_list += episode | |
break | |
print('Adding {} shows to playlist.'.format(len(episode_list))) | |
plex.createPlaylist(MY_PLAYLIST, episode_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How would one edit this to base the playlist off a label rather than a collection?