Skip to content

Commit 37c8575

Browse files
authored
Merge pull request #505 from pkkid/intro_update
Update Marker class
2 parents f2f6d8b + d7c215b commit 37c8575

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

plexapi/media.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -704,13 +704,15 @@ class Marker(PlexObject):
704704
"""
705705
TAG = 'Marker'
706706

707+
def __repr__(self):
708+
name = self._clean(self.firstAttr('type'))
709+
start = utils.millisecondToHumanstr(self._clean(self.firstAttr('start')))
710+
end = utils.millisecondToHumanstr(self._clean(self.firstAttr('end')))
711+
return '<%s:%s %s - %s>' % (self.__class__.__name__, name, start, end)
712+
707713
def _loadData(self, data):
708714
self._data = data
709-
self.filter = data.attrib.get('filter')
710715
self.type = data.attrib.get('type')
711-
_tag, _id = self.filter.split('=')
712-
self.tag = self.type + _tag.capitalize()
713-
self.id = _id
714716
self.start = cast(int, data.attrib.get('startTimeOffset'))
715717
self.end = cast(int, data.attrib.get('endTimeOffset'))
716718

plexapi/utils.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import re
55
import time
66
import zipfile
7-
from datetime import datetime
7+
from datetime import datetime, timedelta
88
from getpass import getpass
99
from threading import Event, Thread
1010
from urllib.parse import quote
@@ -204,6 +204,19 @@ def toDatetime(value, format=None):
204204
return value
205205

206206

207+
def millisecondToHumanstr(milliseconds):
208+
""" Returns human readable time duration from milliseconds.
209+
HH:MM:SS:MMMM
210+
211+
Parameters:
212+
milliseconds (str,int): time duration in milliseconds.
213+
"""
214+
milliseconds = int(milliseconds)
215+
r = datetime.datetime.utcfromtimestamp(milliseconds / 1000)
216+
f = r.strftime("%H:%M:%S.%f")
217+
return f[:-2]
218+
219+
207220
def toList(value, itemcast=None, delim=','):
208221
""" Returns a list of strings from the specified value.
209222

tests/test_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,9 @@ def test_utils_download(plex, episode):
7676
assert utils.download(
7777
episode.thumbUrl, plex._token, filename=episode.title, mocked=True
7878
)
79+
80+
81+
82+
def test_millisecondToHumanstr():
83+
res = utils.millisecondToHumanstr(1000)
84+
assert res == "00:00:01:0000"

0 commit comments

Comments
 (0)