Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Create a Plex Playlist with what was aired on this today's month-day, sort by oldest first, using PlexAPI
Create a Plex Playlist with what was aired on this today's month-day, sort by oldest first.
If Playlist from yesterday exists delete and create today's.
If today's Playlist exists exit.
import operator, time
from plexapi.server import PlexServer
import requests
baseurl = 'http://localhost:32400'
token = 'xxxxxx'
plex = PlexServer(baseurl, token)
library_name = ['Movies', 'TV Shows'] # You library names
child_lst = []
aired_lst = []
today = time.gmtime(time.time())
TODAY_PLAY_TITLE = 'Aired Today {}-{}'.format(today.tm_mon, today.tm_mday)
# Remove old Aired Today Playlists
for playlist in plex.playlists():
if playlist.title == TODAY_PLAY_TITLE.startswith('Aired Today') and not TODAY_PLAY_TITLE:
r = requests.delete('{}/playlists/{}?X-Plex-Token={}'
.format(baseurl, TODAY_PLAY_TITLE, token))
print('Removing old Aired Today Playlists ')
elif playlist.title == TODAY_PLAY_TITLE:
print('{} already exists. No need to make again.'.format(TODAY_PLAY_TITLE))
# Get all movies or episodes from LIBRARY_NAME
for library in library_name:
for child in plex.library.section(library).all():
if child.type == 'movie':
child_lst += [child]
elif child.type == 'show':
child_lst += child.episodes()
# Find what aired with today's month-day
for video in child_lst:
if str(video.originallyAvailableAt.month) == str(today.tm_mon) \
and str( == str(today.tm_mday):
aired_lst += [[video] + [str(video.originallyAvailableAt)]]
except Exception as e:
# Sort by original air date, oldest first
aired_lst = sorted(aired_lst, key=operator.itemgetter(1))
# Remove date used for sorting
play_lst = [x[0] for x in aired_lst]
# Create Playlist
plex.createPlaylist(TODAY_PLAY_TITLE, play_lst)

This comment has been minimized.

Copy link

@adamcarter1 adamcarter1 commented Dec 5, 2018

This is cool! How do i implement it?


This comment has been minimized.

Copy link

@cfurrow cfurrow commented Feb 17, 2019


Be sure that you have python and pip installed, then you can run this:

# This installs the plex api so it can be used in the above script
pip install plexapi

# This downloads the above script. You can copy/paste the above code, or use wget to download the "raw" file from github

Then, you need to edit the

Edit the baseurl to point to your server. Mine looks like this:
baseurl = ''

And since I only wanted to get a list of all TV shows that aired today, I modified the following line
library_name = ['TV Shows'] # You library names

You'll need to get a valid plex token. The easiest way to do this, is open up your plex server via, start playing some video from your library and then open your browser's developer tools, and look in the "network" tab. In there, you'll see a bunch of requests being made to your server that look like this:


Find the plex token in there, by looking up the value for X-Plex-Token. Copy the value and add it into the python file.

token = 'XXXXXXX'

Now you're ready to run the script!


That's it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment