Skip to content
Mauricio Antunes edited this page May 13, 2024 · 3 revisions

The most frequently usage for you to use this m3u8 module is perhaps you want to get the playlist URLs, here is the fast way, for example

import m3u8

def get_segments(m3u8_url):
    def load_m3u8(url):
        urls = []
        m = m3u8.load(url)
        for seg in m.segments:
            urls.append(seg.absolute_uri)
        return urls

    try:
        videoUrls = load_m3u8(m3u8_url)
    except Exception as e:
        # print('load_m3u8 {}'.format(e))
        return {'reason': 'load_m3u8 {}'.format(e)} 
    else:
        return {'videoUrls': videoUrls}
Clone this wiki locally