JBOPS/utility/refresh_next_episode.py
Landon Abney 2be0e376f8
Massive style cleanup
Adds a basic `setup.cfg` file with configurations for flake8 and pylama, 
fixes some basic issues with essentially every file including:
* Many, many, whitespace line cleanups
* Several unused variables and imports
* Missing coding and shabang lines
* Minor style fixes to more closely align with PEP8
* Turn `print` into function calls for Python 2/3 compat
* A few minor bugs
  * Things like using an undefined `i` in `stream_limiter_ban_email.py`
2019-06-20 23:55:11 -07:00

67 lines
2.0 KiB
Python

#!/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}
"""
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')