def make_segment(segment, discontinuity=False): """Create a playlist response for a segment.""" response = ["#EXT-X-DISCONTINUITY"] if discontinuity else [] response.extend([ "#EXT-X-PROGRAM-DATE-TIME:" + FAKE_TIME.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z", f"#EXTINF:{SEGMENT_DURATION:.3f},", f"./segment/{segment}.m4s", ]) return "\n".join(response)
def make_segment_with_parts(segment, num_parts, independent_period, discontinuity=False): """Create a playlist response for a segment including part segments.""" response = [] for i in range(num_parts): response.append( f'#EXT-X-PART:DURATION={TEST_PART_DURATION:.3f},URI="./segment/{segment}.{i}.m4s"{",INDEPENDENT=YES" if i%independent_period==0 else ""}' ) if discontinuity: response.append("#EXT-X-DISCONTINUITY") response.extend([ "#EXT-X-PROGRAM-DATE-TIME:" + FAKE_TIME.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z", f"#EXTINF:{math.ceil(SEGMENT_DURATION/TEST_PART_DURATION)*TEST_PART_DURATION:.3f},", f"./segment/{segment}.m4s", ]) return "\n".join(response)