2 Create a Plex Playlist with what aired on this day in history (month-day), sort by oldest first.
3 If Playlist from yesterday exists delete and create today's.
4 If today's Playlist exists exit.
8 from plexapi.server import PlexServer
12 PLEX_URL = 'http://localhost:32400'
15 LIBRARY_NAMES = ['Movies', 'TV Shows'] # Your library names
17 today = datetime.datetime.now().date()
19 TODAY_PLAY_TITLE = 'Aired Today {}-{}'.format(today.month, today.day)
21 plex = PlexServer(PLEX_URL, PLEX_TOKEN)
24 # Remove old Aired Today Playlists
25 for playlist in plex.playlists():
26 if playlist.title.startswith('Aired Today') and playlist.title != TODAY_PLAY_TITLE:
28 print('Removing old Aired Today Playlists: {}'.format(playlist.title))
29 elif playlist.title == TODAY_PLAY_TITLE:
30 print('{} already exists. No need to make again.'.format(TODAY_PLAY_TITLE))
34 def get_all_content(library_name):
35 # Get all movies or episodes from LIBRARY_NAME
37 for library in library_name:
38 for child in plex.library.section(library).all():
39 if child.type == 'movie':
41 elif child.type == 'show':
42 child_lst += child.episodes()
48 def find_air_dates(content_lst):
49 # Find what aired with today's month-day
51 for video in content_lst:
53 ad_month = str(video.originallyAvailableAt.month)
54 ad_day = str(video.originallyAvailableAt.day)
56 if ad_month == str(today.month) and ad_day == str(today.day):
57 aired_lst += [[video] + [str(video.originallyAvailableAt)]]
58 except Exception as e:
62 # Sort by original air date, oldest first
63 aired_lst = sorted(aired_lst, key=operator.itemgetter(1))
65 # Remove date used for sorting
66 play_lst = [x[0] for x in aired_lst]
71 play_lst = find_air_dates(get_all_content(LIBRARY_NAMES))
74 plex.createPlaylist(TODAY_PLAY_TITLE, play_lst)
76 print('Found nothing aired on this day in history.')