Last active
November 27, 2023 17:12
-
-
Save JonnyWong16/69d88256537655b5ff4a27652ca10f70 to your computer and use it in GitHub Desktop.
Automatically mark a video (movie, show, season, or episode) as played in Plex for a specific users.
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 video (movie, show, season, or episode) | |
# as played in Plex for specific users. | |
# Author: /u/SwiftPanda16 | |
# Requires: plexapi | |
# | |
# Tautulli script trigger: | |
# * Notify on watched | |
# Tautulli script conditions: | |
# * Condition {1}: | |
# [ Username | is | <from username> ] | |
# * Condition {2} (optional): | |
# [ Library Name | is | DVR ] | |
# Tautulli script arguments: | |
# * Watched: | |
# --rating_key {rating_key} --users "<to username2>" "<to username3>" | |
import argparse | |
import os | |
from plexapi.server import PlexServer | |
from plexapi.video import Video | |
PLEX_URL = '' | |
PLEX_TOKEN = '' | |
# Environmental Variables | |
PLEX_URL = os.getenv('PLEX_URL', PLEX_URL) | |
PLEX_TOKEN = os.getenv('PLEX_TOKEN', PLEX_TOKEN) | |
def mark_watched(plex, rating_key, users): | |
admin = plex.myPlexAccount().username.lower() | |
for user in users: | |
server = plex if user.lower() == admin else plex.switchUser(user) | |
item = server.fetchItem(rating_key) | |
if isinstance(item, Video): | |
print(f'Marking {item.title} as watched for {user}.') | |
item.markWatched() | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--rating_key', required=True, type=int) | |
parser.add_argument('--users', required=True, nargs='+') | |
opts = parser.parse_args() | |
plex = PlexServer(PLEX_URL, PLEX_TOKEN) | |
mark_watched(plex, **vars(opts)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wanted to say thanks for this script and let you know that it looks like it may need to be updated slightly as I noticed this in the logs while testing it out today. Looks like the markWatched functions is going to be depreciated. I did test with changing the code on line 40 from Watched to Played and it worked without error after that.
Log Warning:
Line 40 of the code:
item.markWatched()