2017-08-13 01:35:13 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
Plex-MarkWatched is a useful to always mark a show as watched. This comes in
|
|
|
|
handy when you have a show you keep downloaded, but do not religiously watch
|
|
|
|
every single episode that is downloaded. By marking everything watched, it
|
|
|
|
will keep the show out of your OnDeck list inside Plex.
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
Intended usage is to add the tak 'markwatched' to any show you want to have
|
|
|
|
this behaviour. Then simply add this script to run on a schedule and you
|
|
|
|
should be all set.
|
2017-08-15 02:55:54 +00:00
|
|
|
|
|
|
|
Example Crontab:
|
|
|
|
*/5 * * * * /home/atodd/plex-markwatched.py >> /home/atodd/plex-markwatched.log 2>&1
|
2017-08-13 01:35:13 +00:00
|
|
|
"""
|
2017-08-15 02:55:54 +00:00
|
|
|
from datetime import datetime
|
2017-08-13 01:35:13 +00:00
|
|
|
from plexapi.server import PlexServer
|
|
|
|
|
|
|
|
|
2019-06-05 13:48:37 +00:00
|
|
|
def _has_markwatched_tag(item):
|
|
|
|
collections = item.show().collections if item.type == 'episode' else item.collections
|
|
|
|
tags = [c.tag.lower() for c in collections]
|
|
|
|
return 'markwatched' in tags
|
|
|
|
|
|
|
|
|
|
|
|
def _get_title(item):
|
|
|
|
if item.type == 'episode':
|
2020-09-28 13:41:18 +00:00
|
|
|
return '{title} {episode}'.format(title=item.grandparentTitle, episode=item.seasonEpisode)
|
2019-06-05 13:48:37 +00:00
|
|
|
return item.title
|
|
|
|
|
|
|
|
|
|
|
|
def _iter_items(search):
|
|
|
|
for item in search:
|
|
|
|
if item.type in ['show']:
|
|
|
|
for episode in item.episodes():
|
|
|
|
yield episode
|
|
|
|
break
|
|
|
|
yield item
|
|
|
|
|
|
|
|
|
2017-08-13 01:35:13 +00:00
|
|
|
if __name__ == '__main__':
|
2019-07-20 20:47:54 +00:00
|
|
|
datestr = lambda: datetime.now().strftime('%Y-%m-%d %H:%M:%S') # noqa
|
2023-08-29 03:29:39 +00:00
|
|
|
print(f'{datestr()} Starting plex-markwatched script..')
|
2017-08-13 01:35:13 +00:00
|
|
|
plex = PlexServer()
|
|
|
|
for section in plex.library.sections():
|
2023-08-29 03:29:39 +00:00
|
|
|
print(f'{datestr()} Checking {section.title} for unwatched items..')
|
2019-06-05 13:48:37 +00:00
|
|
|
for item in _iter_items(section.search(collection='markwatched')):
|
|
|
|
if not item.isWatched:
|
2023-08-29 03:29:39 +00:00
|
|
|
print(f'{datestr()} Marking {_get_title(item)} watched.')
|
2019-06-05 13:48:37 +00:00
|
|
|
item.markWatched()
|
|
|
|
# Check all OnDeck items
|
2023-08-29 03:29:39 +00:00
|
|
|
print(f'{datestr()} Checking OnDeck for unwatched items.')
|
2019-06-05 13:48:37 +00:00
|
|
|
for item in plex.library.onDeck():
|
|
|
|
if not item.isWatched and _has_markwatched_tag(item):
|
2023-08-29 03:29:39 +00:00
|
|
|
print(f'{datestr()} Marking {_get_title(item)} watched.')
|
2019-06-05 13:48:37 +00:00
|
|
|
item.markWatched()
|