How to use the m3u8.protocol function in m3u8

To help you get started, we’ve selected a few m3u8 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github globocom / m3u8 / m3u8 / parser.py View on Github external
def _parse_extinf(line, data, state, lineno, strict):
    chunks = line.replace(protocol.extinf + ':', '').split(',', 1)
    if len(chunks) == 2:
        duration, title = chunks
    elif len(chunks) == 1:
        if strict:
            raise ParseError(lineno, line)
        else:
            duration = chunks[0]
            title = ''
    if 'segment' not in state:
        state['segment'] = {}
    state['segment']['duration'] = float(duration)
    state['segment']['title'] = title
github globocom / m3u8 / m3u8 / parser.py View on Github external
def _parse_preload_hint(line, data, state):
    attribute_parser = remove_quotes_parser('uri')
    attribute_parser['type'] = str
    attribute_parser['byterange_start'] = int
    attribute_parser['byterange_length'] = int

    data['preload_hint'] = _parse_attribute_list(
        protocol.ext_x_preload_hint, line, attribute_parser
    )
github globocom / m3u8 / m3u8 / parser.py View on Github external
def _parse_session_data(line, data, state):
    quoted = remove_quotes_parser('data_id', 'value', 'uri', 'language')
    session_data = _parse_attribute_list(protocol.ext_x_session_data, line, quoted)
    data['session_data'].append(session_data)
github globocom / m3u8 / m3u8 / parser.py View on Github external
def _parse_part_inf(line, data, state):
    attribute_parser = {
        "part_target": lambda x: float(x)
    }

    data['part_inf'] = _parse_attribute_list(
        protocol.ext_x_part_inf, line, attribute_parser
    )
github epiclabs-io / hls-analyzer / m3u8 / parser.py View on Github external
'playlist_type': None,
        'playlists': [],
        'iframe_playlists': [],
        'segments': [],
        'media': [],
        }

    state = {
        'expect_segment': False,
        'expect_playlist': False,
        }

    for line in string_to_lines(content):
        line = line.strip()

        if line.startswith(protocol.ext_x_byterange):
            _parse_byterange(line, state)
            state['expect_segment'] = True

        elif state['expect_segment']:
            _parse_ts_chunk(line, data, state)
            state['expect_segment'] = False

        elif state['expect_playlist']:
            _parse_variant_playlist(line, data, state)
            state['expect_playlist'] = False

        elif line.startswith(protocol.ext_x_targetduration):
            _parse_simple_parameter(line, data, float)
        elif line.startswith(protocol.ext_x_media_sequence):
            _parse_simple_parameter(line, data, int)
        #elif line.startswith(protocol.ext_x_program_date_time):
github epiclabs-io / hls-analyzer / m3u8 / parser.py View on Github external
elif line.startswith(protocol.ext_x_discontinuity):
            state['discontinuity'] = True
        elif line.startswith(protocol.ext_x_version):
            _parse_simple_parameter(line, data)
        elif line.startswith(protocol.ext_x_allow_cache):
            _parse_simple_parameter(line, data)

        elif line.startswith(protocol.ext_x_key):
            state['current_key'] = _parse_key(line)
            data['key'] = data.get('key', state['current_key'])

        elif line.startswith(protocol.extinf):
            _parse_extinf(line, data, state)
            state['expect_segment'] = True

        elif line.startswith(protocol.ext_x_stream_inf):
            state['expect_playlist'] = True
            _parse_stream_inf(line, data, state)

        elif line.startswith(protocol.ext_x_i_frame_stream_inf):
            _parse_i_frame_stream_inf(line, data)

        elif line.startswith(protocol.ext_x_media):
            _parse_media(line, data, state)

        elif line.startswith(protocol.ext_x_playlist_type):
            _parse_simple_parameter(line, data)

        elif line.startswith(protocol.ext_i_frames_only):
            data['is_i_frames_only'] = True

        elif line.startswith(protocol.ext_x_endlist):
github globocom / m3u8 / m3u8 / parser.py View on Github external
def _cueout_no_duration(line):
    # this needs to be called first since line.split in all other
    # parsers will throw a ValueError if passed just this tag
    if line == protocol.ext_x_cue_out:
        return (None, None)
github globocom / m3u8 / m3u8 / parser.py View on Github external
def _parse_part(line, data, state):
    attribute_parser = remove_quotes_parser('uri')
    attribute_parser['duration'] = lambda x: float(x)
    attribute_parser['independent'] = str
    attribute_parser['gap'] = str
    attribute_parser['byterange'] = str

    part = _parse_attribute_list(protocol.ext_x_part, line, attribute_parser)

    # this should always be true according to spec
    if state.get('current_program_date_time'):
        part['program_date_time'] = state['current_program_date_time']
        state['current_program_date_time'] += datetime.timedelta(seconds=part['duration'])

    part['dateranges'] = state.pop('dateranges', None)
    part['gap_tag'] = state.pop('gap', None)

    if 'segment' not in state:
        state['segment'] = {}
    segment = state['segment']
    if 'parts' not in segment:
        segment['parts'] = []

    segment['parts'].append(part)
github epiclabs-io / hls-analyzer / m3u8 / parser.py View on Github external
def _parse_media(line, data, state):
    quoted = remove_quotes_parser('uri', 'group_id', 'language', 'name', 'characteristics')
    media = _parse_attribute_list(protocol.ext_x_media, line, quoted)
    data['media'].append(media)
github epiclabs-io / hls-analyzer / m3u8 / parser.py View on Github external
def _parse_stream_inf(line, data, state):
    data['is_variant'] = True
    data['media_sequence'] = None
    atribute_parser = remove_quotes_parser('codecs', 'audio', 'video', 'subtitles')
    atribute_parser["program_id"] = int
    atribute_parser["bandwidth"] = int
    state['stream_info'] = _parse_attribute_list(protocol.ext_x_stream_inf, line, atribute_parser)