Skip to content

Instantly share code, notes, and snippets.

@Hellowlol
Forked from blacktwin/aired_today_playlist.py
Last active March 4, 2017 15:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hellowlol/5d05f2928dbf6a0f1666bf92a056e1e1 to your computer and use it in GitHub Desktop.
Save Hellowlol/5d05f2928dbf6a0f1666bf92a056e1e1 to your computer and use it in GitHub Desktop.
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.
"""
# Untested requires plexapi 3.0.0.
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 = []
today = datetime.now().date()
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:
playlist.delete()
elif playlist.title == TODAY_PLAY_TITLE:
print('{} already exists. No need to make again.'.format(TODAY_PLAY_TITLE))
exit(0)
# 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.append(child)
elif child.type == 'show':
child_lst += child.episodes()
pl = sorted([v for v in child_lst if v.originallyAvailableAt.date() == today], lambda k: k.originallyAvailableAt)
# Create Playlist
plex.createPlaylist(TODAY_PLAY_TITLE, pl)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment