forked from blacktwin/JBOPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
refresh_next_episode.py
68 lines (54 loc) · 2.06 KB
/
refresh_next_episode.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
61
62
63
64
65
66
67
68
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Refresh the next episode of show once current episode is watched.
Check Tautulli's Watched Percent in Tautulli > Settings > General
1. Tautulli > Settings > Notification Agents > Scripts > Bell icon:
[X] Notify on watched
2. Tautulli > Settings > Notification Agents > Scripts > Gear icon:
Enter the "Script folder" where you save the script.
Watched: refresh_next_episode.py
Save
3. Tautulli > Settings > Notifications > Script > Script Arguments:
{show_name} {episode_num00} {season_num00}
"""
from __future__ import print_function
from __future__ import unicode_literals
import requests
import sys
from plexapi.server import PlexServer, CONFIG
# pip install plexapi
PLEX_URL = ''
PLEX_TOKEN = ''
PLEX_URL = CONFIG.data['auth'].get('server_baseurl', PLEX_URL)
PLEX_TOKEN = CONFIG.data['auth'].get('server_token', PLEX_TOKEN)
sess = requests.Session()
# Ignore verifying the SSL certificate
sess.verify = False # '/path/to/certfile'
# If verify is set to a path to a directory,
# the directory must have been processed using the c_rehash utility supplied
# with OpenSSL.
if sess.verify is False:
# Disable the warning that the request is insecure, we know that...
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
plex = PlexServer(PLEX_URL, PLEX_TOKEN, session=sess)
show_name = sys.argv[1]
next_ep_num = int(sys.argv[2])
season_num = int(sys.argv[3])
TV_LIBRARY = 'My TV Shows' # Name of your TV Shows library
current_season = season_num - 1
# Get all seasons from Show
all_seasons = plex.library.section(TV_LIBRARY).get(show_name).seasons()
try:
# Get all episodes from current season of Show
all_eps = all_seasons[current_season].episodes()
# Refresh the next episode
all_eps[next_ep_num].refresh()
except IndexError:
try:
# End of season go to next season
all_eps = all_seasons[season_num].episodes()
# Refresh the next season's first episode
all_eps[0].refresh()
except IndexError:
print('End of series')