-
-
Save cfurrow/13a062359bd83ac17a38f8c4fcd3bab2 to your computer and use it in GitHub Desktop.
Create a "Saturday Morning Cartoons" Plex playlist
This file contains 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
PLEX_URL="http://192.168.1.5:32400" | |
PLEX_TOKEN=abc123 |
This file contains 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
""" | |
Create a "Saturday Morning Cartoons" playlist from your Plex TV Show collections | |
named "80s Cartoons" and "90s Cartoons". | |
Update the values in .env to match your server. Google details on how to find | |
your X-Plex-Token value and put that in the .env file for PLEX_TOKEN | |
Then you can run this to create or recreate your playlist: | |
python cartoon_playlist.py | |
""" | |
import os, operator, time, sys, datetime, re | |
import requests | |
from dotenv import load_dotenv | |
from plexapi.server import PlexServer | |
load_dotenv(verbose=True) | |
baseurl = os.environ['PLEX_URL'] | |
token = os.environ['PLEX_TOKEN'] | |
plex = PlexServer(baseurl, token) | |
CARTOON_PLAYLIST_TITLE = 'Saturday Morning Cartoons' | |
for playlist in plex.playlists(): | |
if playlist.title == CARTOON_PLAYLIST_TITLE: | |
r = requests.delete('{}/playlists/{}?X-Plex-Token={}'.format(baseurl, CARTOON_PLAYLIST_TITLE, token)) | |
print('{} already exists. Deleting it and will rebuild.'.format(CARTOON_PLAYLIST_TITLE)) | |
tv_shows_section = plex.library.section('TV Shows') | |
episode_list = [] | |
for collection in tv_shows_section.collection(): | |
regexp = re.compile(r'(80s|90s) Cartoons') | |
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 {} cartoons to playlist.'.format(len(episode_list))) | |
plex.createPlaylist(CARTOON_PLAYLIST_TITLE, episode_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've not used this script in a few years, but, it seems like it did not find anything to add.
Verify you have a Collection in your Plex library called "80s Cartoons" or "90s Cartoons". Otherwise the script won't know where to find cartoons to add toy our playlist.
It also seems like the underlying PlexAPI library has changed its syntax. Notice this error:
Try changing this line:
to this: