Small change to the repr and add test.

This commit is contained in:
Hellowlol 2020-06-14 20:21:46 +02:00
parent 881a4fc659
commit d7c215b119
3 changed files with 15 additions and 8 deletions

View file

@ -706,9 +706,9 @@ class Marker(PlexObject):
def __repr__(self):
name = self._clean(self.firstAttr('type'))
start = utils.millisecondToHuman(self._clean(self.firstAttr('start')))
end = utils.millisecondToHuman(self._clean(self.firstAttr('end')))
return '<%s>' % ':'.join([p for p in [self.__class__.__name__, name, start, end] if p])
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

View file

@ -204,16 +204,17 @@ def toDatetime(value, format=None):
return value
def millisecondToHuman(milliseconds):
def millisecondToHumanstr(milliseconds):
""" Returns human readable time duration from milliseconds.
HH:MM:SS
HH:MM:SS:MMMM
Parameters:
milliseconds (str,int): time duration in milliseconds.
"""
_milliseconds = cast(int, milliseconds)
hhmmsssm = timedelta(milliseconds=_milliseconds)
return str(hhmmsssm).split(".")[0]
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=','):

View file

@ -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"