diff --git a/plexapi/media.py b/plexapi/media.py index 65895c3e3..7a106232e 100644 --- a/plexapi/media.py +++ b/plexapi/media.py @@ -704,13 +704,15 @@ class Marker(PlexObject): """ TAG = 'Marker' + def __repr__(self): + name = self._clean(self.firstAttr('type')) + start = utils.millisecondToHumanstr(self._clean(self.firstAttr('start'))) + end = utils.millisecondToHumanstr(self._clean(self.firstAttr('end'))) + return '<%s:%s %s - %s>' % (self.__class__.__name__, name, start, end) + def _loadData(self, data): self._data = data - self.filter = data.attrib.get('filter') self.type = data.attrib.get('type') - _tag, _id = self.filter.split('=') - self.tag = self.type + _tag.capitalize() - self.id = _id self.start = cast(int, data.attrib.get('startTimeOffset')) self.end = cast(int, data.attrib.get('endTimeOffset')) diff --git a/plexapi/utils.py b/plexapi/utils.py index bf26d044f..01e91830c 100644 --- a/plexapi/utils.py +++ b/plexapi/utils.py @@ -4,7 +4,7 @@ import re import time import zipfile -from datetime import datetime +from datetime import datetime, timedelta from getpass import getpass from threading import Event, Thread from urllib.parse import quote @@ -204,6 +204,19 @@ def toDatetime(value, format=None): return value +def millisecondToHumanstr(milliseconds): + """ Returns human readable time duration from milliseconds. + HH:MM:SS:MMMM + + Parameters: + milliseconds (str,int): time duration in milliseconds. + """ + milliseconds = int(milliseconds) + r = datetime.datetime.utcfromtimestamp(milliseconds / 1000) + f = r.strftime("%H:%M:%S.%f") + return f[:-2] + + def toList(value, itemcast=None, delim=','): """ Returns a list of strings from the specified value. diff --git a/tests/test_utils.py b/tests/test_utils.py index 1b172bc18..8587eca80 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -76,3 +76,9 @@ def test_utils_download(plex, episode): assert utils.download( episode.thumbUrl, plex._token, filename=episode.title, mocked=True ) + + + +def test_millisecondToHumanstr(): + res = utils.millisecondToHumanstr(1000) + assert res == "00:00:01:0000"