Last active
May 7, 2019 20:04
-
-
Save JonnyWong16/7708c5e755c74e169c115490b0749279 to your computer and use it in GitHub Desktop.
Automatically mark a multi-episode file as watched in Plex.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# | |
# Description: Automatically mark a multi-episode file as watched in Plex. | |
# Author: /u/SwiftPanda16 | |
# Requires: plexapi | |
# Tautulli script trigger: | |
# * Notify on watched | |
# Tautulli script conditions: | |
# * Condition {1}: | |
# [ Media Type | is | episode ] | |
# * Condition {2} (optional): | |
# [ Username | is | username ] | |
# Tautulli script arguments: | |
# * Watched: | |
# --rating_key {rating_key} --filename {filename} | |
import argparse | |
import os | |
from plexapi.server import PlexServer | |
PLEX_URL = '' | |
PLEX_TOKEN = '' | |
# Environmental Variables | |
PLEX_URL = os.getenv('PLEX_URL', PLEX_URL) | |
PLEX_USER_TOKEN = os.getenv('PLEX_USER_TOKEN', PLEX_TOKEN) | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--rating_key', required=True, type=int) | |
parser.add_argument('--filename', required=True) | |
opts = parser.parse_args() | |
plex = PlexServer(PLEX_URL, PLEX_USER_TOKEN) | |
for episode in plex.fetchItem(opts.rating_key).season().episodes(): | |
if episode.ratingKey == opts.rating_key: | |
continue | |
if any(opts.filename in part.file for media in episode.media for part in media.parts): | |
print("Marking multi-episode file '{grandparentTitle} - S{parentIndex}E{index}' as watched.".format( | |
grandparentTitle=episode.grandparentTitle.encode('UTF-8'), | |
parentIndex=str(episode.parentIndex).zfill(2), | |
index=str(episode.index).zfill(2))) | |
episode.markWatched() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment