Skip to content

Commit 8410d81

Browse files
authored
Add 'activities' endpoint support (#569)
* Add /activities endpoint support * Fix typos, return a list instead of iterator * Canary test to validate CI behavior * Increase timer of canary test to ensure proper run * Move test to front of run, provide auth and anon versions * Fix typo
1 parent 2490130 commit 8410d81

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

plexapi/server.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ def account(self):
190190
data = self.query(Account.key)
191191
return Account(self, data)
192192

193+
@property
194+
def activities(self):
195+
"""Returns all current PMS activities."""
196+
activities = []
197+
for elem in self.query(Activity.key):
198+
activities.append(Activity(self, elem))
199+
return activities
200+
193201
def agents(self, mediaType=None):
194202
""" Returns the `:class:`~plexapi.media.Agent` objects this server has available. """
195203
key = '/system/agents'
@@ -601,6 +609,20 @@ def _loadData(self, data):
601609
self.subscriptionState = data.attrib.get('subscriptionState')
602610

603611

612+
class Activity(PlexObject):
613+
"""A currently running activity on the PlexServer."""
614+
key = '/activities'
615+
616+
def _loadData(self, data):
617+
self._data = data
618+
self.cancellable = cast(bool, data.attrib.get('cancellable'))
619+
self.progress = cast(int, data.attrib.get('progress'))
620+
self.title = data.attrib.get('title')
621+
self.subtitle = data.attrib.get('subtitle')
622+
self.type = data.attrib.get('type')
623+
self.uuid = data.attrib.get('uuid')
624+
625+
604626
class SystemAccount(PlexObject):
605627
""" Minimal api to list system accounts. """
606628
key = '/accounts'

tests/test__prepare.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# -*- coding: utf-8 -*-
2+
import time
3+
4+
import pytest
5+
6+
MAX_ATTEMPTS = 60
7+
8+
9+
def wait_for_idle_server(server):
10+
"""Wait for PMS activities to complete with a timeout."""
11+
attempts = 0
12+
while server.activities and attempts < MAX_ATTEMPTS:
13+
print(f"Waiting for activities to finish: {server.activities}")
14+
time.sleep(1)
15+
attempts += 1
16+
assert attempts < MAX_ATTEMPTS, f"Server still busy after {MAX_ATTEMPTS}s"
17+
18+
19+
def test_ensure_metadata_scans_completed(plex):
20+
wait_for_idle_server(plex)
21+
22+
23+
@pytest.mark.authenticated
24+
def test_ensure_metadata_scans_completed_authenticated(plex):
25+
wait_for_idle_server(plex)

0 commit comments

Comments
 (0)