forked from blacktwin/JBOPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaired_today_playlist.py
60 lines (49 loc) · 1.91 KB
/
aired_today_playlist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
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 ')
print(r)
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 += [child]
elif child.type == 'show':
child_lst += child.episodes()
else:
pass
# Find what aired with today's month-day
for video in child_lst:
try:
if str(video.originallyAvailableAt.month) == str(today.tm_mon) \
and str(video.originallyAvailableAt.day) == str(today.tm_mday):
aired_lst += [[video] + [str(video.originallyAvailableAt)]]
except Exception as e:
pass
# 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)