From 00c21c63255277d8dca1abd3c536ffd35fe66172 Mon Sep 17 00:00:00 2001 From: tijder Date: Sat, 12 May 2018 21:29:17 +0200 Subject: [PATCH 1/5] Function update timeline for base.py Function to update the timeline for a payable item. With this the item will be showed in the now playing screen. --- plexapi/base.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plexapi/base.py b/plexapi/base.py index f452e3e1..c23c3a19 100644 --- a/plexapi/base.py +++ b/plexapi/base.py @@ -565,6 +565,18 @@ class Playable(object): time, state) self._server.query(key) self.reload() + + def updateTimeline(self, time, state='stopped'): + """ Set the timeline progress for this video. + + Parameters: + time (int): milliseconds watched + state (string): state of the video, default 'stopped' + """ + key = '/:/timeline?ratingKey=%s&key=%s&identifier=com.plexapp.plugins.library&time=%d&state=%s' % (self.ratingKey, self.key, + time, state) + self._server.query(key) + self.reload() @utils.registerPlexObject From ace43732a42d2e405bbd424968a7fde3971af94c Mon Sep 17 00:00:00 2001 From: tijder Date: Sun, 13 May 2018 10:50:19 +0200 Subject: [PATCH 2/5] updateTimeline with option duration Without the option duration the video progres will not be updated. --- plexapi/base.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plexapi/base.py b/plexapi/base.py index c23c3a19..9de084ca 100644 --- a/plexapi/base.py +++ b/plexapi/base.py @@ -566,15 +566,18 @@ class Playable(object): self._server.query(key) self.reload() - def updateTimeline(self, time, state='stopped'): + def updateTimeline(self, time, state='stopped', duration=None): """ Set the timeline progress for this video. Parameters: time (int): milliseconds watched state (string): state of the video, default 'stopped' """ - key = '/:/timeline?ratingKey=%s&key=%s&identifier=com.plexapp.plugins.library&time=%d&state=%s' % (self.ratingKey, self.key, - time, state) + durationStr = '' + if duration != None: + durationStr = '&duration=' + str(duration) + key = '/:/timeline?ratingKey=%s&key=%s&identifier=com.plexapp.plugins.library&time=%d&state=%s%s' % (self.ratingKey, self.key, + time, state, durationStr) self._server.query(key) self.reload() From 16ed7451c9bf97045115d1d51198ce03bf10f822 Mon Sep 17 00:00:00 2001 From: tijder Date: Sun, 13 May 2018 11:40:15 +0200 Subject: [PATCH 3/5] Comment parameters --- plexapi/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plexapi/base.py b/plexapi/base.py index 9de084ca..974fae7a 100644 --- a/plexapi/base.py +++ b/plexapi/base.py @@ -572,6 +572,7 @@ class Playable(object): Parameters: time (int): milliseconds watched state (string): state of the video, default 'stopped' + duration (int): duration of the item """ durationStr = '' if duration != None: From 14c40e5fd8aeae16bdc10b03f92a60bd0904b5af Mon Sep 17 00:00:00 2001 From: tijder Date: Mon, 14 May 2018 20:12:29 +0200 Subject: [PATCH 4/5] Basic test --- tests/test_video.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_video.py b/tests/test_video.py index dea9df6d..75e55170 100644 --- a/tests/test_video.py +++ b/tests/test_video.py @@ -283,7 +283,9 @@ def test_video_Episode_unmatch(episode, patched_http_call): def test_video_Episode_updateProgress(episode, patched_http_call): episode.updateProgress(10 * 60 * 1000) # 10 minutes. - + +def test_video_Episode_updateTimeline(episode, patched_http_call): + episode.updateTimeline(10 * 60 * 1000, state='playing', duration=episode.duration) # 10 minutes. def test_video_Episode_stop(episode, mocker, patched_http_call): mocker.patch.object(episode, 'session', return_value=list(mocker.MagicMock(id='hello'))) From 8d4e062a0ab9d265443a0f0e4a5364048d4b51c8 Mon Sep 17 00:00:00 2001 From: tijder Date: Fri, 18 May 2018 10:58:06 +0200 Subject: [PATCH 5/5] Add own duration when not given as parameter --- plexapi/base.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plexapi/base.py b/plexapi/base.py index 974fae7a..7aeb9859 100644 --- a/plexapi/base.py +++ b/plexapi/base.py @@ -574,9 +574,11 @@ class Playable(object): state (string): state of the video, default 'stopped' duration (int): duration of the item """ - durationStr = '' + durationStr = '&duration=' if duration != None: - durationStr = '&duration=' + str(duration) + durationStr = durationStr + str(duration) + else: + durationStr = durationStr + str(self.duration) key = '/:/timeline?ratingKey=%s&key=%s&identifier=com.plexapp.plugins.library&time=%d&state=%s%s' % (self.ratingKey, self.key, time, state, durationStr) self._server.query(key)