Created
November 14, 2019 00:32
-
-
Save bbakermmc/c5b26251c59fe53d5e320dfe3d6c4c53 to your computer and use it in GitHub Desktop.
Plex Create Playlist By Network
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
""" | |
Update the values 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 | |
""" | |
import os, operator, time, sys, datetime, re | |
from typing import Union | |
import requests | |
from plexapi.library import ShowSection, MusicSection, MovieSection, PhotoSection | |
from plexapi.server import PlexServer | |
baseurl = "http://192.068.0.1:32400" | |
token = "CHANGEME" | |
plex = PlexServer(baseurl, token) | |
NETWORKS = ["Disney+", "Apple TV+", "Netflix"] | |
for networkName in NETWORKS: | |
print(networkName) | |
for playlist in plex.playlists(): | |
if playlist.title == networkName: | |
r = requests.delete('{}/playlists/{}?X-Plex-Token={}'.format(baseurl, networkName, token)) | |
print('{} already exists. Deleting it and will rebuild.'.format(networkName)) | |
tv_shows_section: Union[ShowSection, PhotoSection, MovieSection, MusicSection] = plex.library.section('TV Shows') | |
shows_list = [] | |
print("-----------------------") | |
class ShowsToProcess: | |
def __init__(self, tvshow, studio): | |
self.tvshow = tvshow | |
self.studio = studio | |
for show in tv_shows_section.all(): | |
for networkName in NETWORKS: | |
if networkName == show.studio: | |
shows_list.append(ShowsToProcess(show, show.studio)) | |
for networkName in NETWORKS: | |
playlist = [] | |
for rec in shows_list: | |
if networkName == rec.studio: | |
playlist.append(rec.tvshow) | |
if len(playlist) != 0: | |
print("Creating Playlist for " + networkName) | |
plex.createPlaylist(networkName, playlist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment