Skip to content

Commit 9ce0d17

Browse files
committed
Merge master
2 parents 1c37f60 + 42ab22b commit 9ce0d17

File tree

4 files changed

+43
-11
lines changed

4 files changed

+43
-11
lines changed

docs/configuration.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ are optional. An example config.ini file may look like the following with all po
2121
client_baseurl = http://127.0.0.1:32433
2222
client_token = BDFSLCNSNL789FH7
2323
24-
[headers]
24+
[header]
2525
identifier = 0x485b314307f3L
2626
platorm = Linux
2727
platform_version = 4.4.0-62-generic

plexapi/myplex.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ class MyPlexUser(PlexObject):
516516
thumb (str): Link to the users avatar.
517517
title (str): Seems to be an aliad for username.
518518
username (str): User's username.
519+
servers: Servers shared between user and friend
519520
"""
520521
TAG = 'User'
521522
key = 'https://plex.tv/api/users/'

plexapi/server.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,12 @@ def account(self):
182182
""" Returns the :class:`~plexapi.server.Account` object this server belongs to. """
183183
data = self.query(Account.key)
184184
return Account(self, data)
185-
185+
186+
def createToken(self, type='delegation', scope='all'):
187+
"""Create a temp access token for the server."""
188+
q = self.query('/security/token?type=%s&scope=%s' % (type, scope))
189+
return q.attrib.get('token')
190+
186191
def systemAccounts(self):
187192
""" Returns the :class:`~plexapi.server.SystemAccounts` objects this server contains. """
188193
accounts = []
@@ -325,7 +330,7 @@ def history(self, maxresults=9999999, mindate=None):
325330
326331
Parameters:
327332
maxresults (int): Only return the specified number of results (optional).
328-
mindate (datetime): Min datetime to return results from. This really helps speed
333+
mindate (datetime): Min datetime to return results from. This really helps speed
329334
up the result listing. For example: datetime.now() - timedelta(days=7)
330335
"""
331336
results, subresults = [], '_init'

tools/plex-markwatched.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,40 @@
1818
from plexapi.server import PlexServer
1919

2020

21+
def _has_markwatched_tag(item):
22+
collections = item.show().collections if item.type == 'episode' else item.collections
23+
tags = [c.tag.lower() for c in collections]
24+
return 'markwatched' in tags
25+
26+
27+
def _get_title(item):
28+
if item.type == 'episode':
29+
return f'{item.grandparentTitle} {item.seasonEpisode}'
30+
return item.title
31+
32+
33+
def _iter_items(search):
34+
for item in search:
35+
if item.type in ['show']:
36+
for episode in item.episodes():
37+
yield episode
38+
break
39+
yield item
40+
41+
2142
if __name__ == '__main__':
22-
datestr = lambda: datetime.now().strftime('%Y-%m-%d %H:%M:%S')
23-
print('%s Starting plex-markwatched script..' % datestr())
43+
datestr = lambda: datetime.now().strftime('%Y-%m-%d %H:%M:%S') # noqa
44+
print(f'{datestr()} Starting plex-markwatched script..')
2445
plex = PlexServer()
2546
for section in plex.library.sections():
26-
if section.type in ('show',): # ('movie', 'artist', 'show'):
27-
for item in section.search(collection='markwatched'):
28-
for episode in item.episodes():
29-
if not episode.isWatched:
30-
print('%s Marking %s watched.' % (datestr(), episode.title))
31-
episode.markWatched()
47+
print(f'{datestr()} Checking {section.title} for unwatched items..')
48+
for item in _iter_items(section.search(collection='markwatched')):
49+
if not item.isWatched:
50+
print(f'{datestr()} Marking {_get_title(item)} watched.')
51+
item.markWatched()
52+
# Check all OnDeck items
53+
print(f'{datestr()} Checking OnDeck for unwatched items..')
54+
for item in plex.library.onDeck():
55+
if not item.isWatched and _has_markwatched_tag(item):
56+
print(f'{datestr()} Marking {_get_title(item)} watched.')
57+
item.markWatched()

0 commit comments

Comments
 (0)