Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass timespec all the way down in dumps #345

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions m3u8/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def add_segment(self, segment):
def add_rendition_report(self, report):
self.rendition_reports.append(report)

def dumps(self):
def dumps(self, timespec="milliseconds"):
"""
Returns the current m3u8 as a string.
You could also use unicode(<this obj>) or str(<this obj>)
Expand Down Expand Up @@ -416,7 +416,7 @@ def dumps(self):
for key in self.session_keys:
output.append(str(key))

output.append(str(self.segments))
output.append(self.segments.dumps(timespec))

if self.preload_hint:
output.append(str(self.preload_hint))
Expand Down Expand Up @@ -702,14 +702,17 @@ def base_uri(self, newbase_uri):


class SegmentList(list, GroupedBasePathMixin):
def __str__(self):
def dumps(self, timespec="milliseconds"):
output = []
last_segment = None
for segment in self:
output.append(segment.dumps(last_segment))
output.append(segment.dumps(last_segment, timespec))
last_segment = segment
return "\n".join(output)

def __str__(self):
return self.dumps()

@property
def uri(self):
return [seg.uri for seg in self]
Expand Down
7 changes: 7 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,13 @@ def test_dump_segment_honors_timespec():
assert "EXT-X-PROGRAM-DATE-TIME:2014-08-13T13:36:33.000000+00:00" in segment_text


def test_dump_honors_timespec():
obj = m3u8.M3U8(playlists.SIMPLE_PLAYLIST_WITH_PROGRAM_DATE_TIME)
obj_text = obj.dumps(timespec="microseconds").strip()

assert "EXT-X-PROGRAM-DATE-TIME:2014-08-13T13:36:33.000000+00:00" in obj_text


def test_dump_should_not_ignore_zero_duration():
obj = m3u8.M3U8(playlists.SIMPLE_PLAYLIST_WITH_ZERO_DURATION)

Expand Down
Loading