Skip to content

Instantly share code, notes, and snippets.

@JonnyWong16
Last active November 27, 2023 17:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonnyWong16/69d88256537655b5ff4a27652ca10f70 to your computer and use it in GitHub Desktop.
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.
#!/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))
@gold007eye
Copy link

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:

mark_watched.py:40: DeprecationWarning: Call to deprecated function or method "markWatched", use "markPlayed" instead.
        item.markWatched() 

Line 40 of the code:
item.markWatched()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment