Skip to content

Commit d7c215b

Browse files
committed
Small change to the repr and add test.
1 parent 881a4fc commit d7c215b

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

plexapi/media.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -706,9 +706,9 @@ class Marker(PlexObject):
706706

707707
def __repr__(self):
708708
name = self._clean(self.firstAttr('type'))
709-
start = utils.millisecondToHuman(self._clean(self.firstAttr('start')))
710-
end = utils.millisecondToHuman(self._clean(self.firstAttr('end')))
711-
return '<%s>' % ':'.join([p for p in [self.__class__.__name__, name, start, end] if p])
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)
712712

713713
def _loadData(self, data):
714714
self._data = data

plexapi/utils.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,17 @@ def toDatetime(value, format=None):
204204
return value
205205

206206

207-
def millisecondToHuman(milliseconds):
207+
def millisecondToHumanstr(milliseconds):
208208
""" Returns human readable time duration from milliseconds.
209-
HH:MM:SS
209+
HH:MM:SS:MMMM
210210
211211
Parameters:
212212
milliseconds (str,int): time duration in milliseconds.
213213
"""
214-
_milliseconds = cast(int, milliseconds)
215-
hhmmsssm = timedelta(milliseconds=_milliseconds)
216-
return str(hhmmsssm).split(".")[0]
214+
milliseconds = int(milliseconds)
215+
r = datetime.datetime.utcfromtimestamp(milliseconds / 1000)
216+
f = r.strftime("%H:%M:%S.%f")
217+
return f[:-2]
217218

218219

219220
def toList(value, itemcast=None, delim=','):

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)