-
Notifications
You must be signed in to change notification settings - Fork 305
/
mark_multiepisode_watched.py
49 lines (42 loc) · 1.63 KB
/
mark_multiepisode_watched.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
#!/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}
from __future__ import print_function
from __future__ import unicode_literals
from builtins import str
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()