globocom / m3u8

Python m3u8 Parser for HTTP Live Streaming (HLS) Transmissions
Other
1.98k stars 464 forks source link

Iframe streams are not parsed correctly #351

Closed saeedesmaili closed 1 month ago

saeedesmaili commented 6 months ago

I was trying to use this library to parse a m3u8 file from apple's website: m3u8 file: https://devstreaming-cdn.apple.com/videos/wwdc/2021/102/9/185FF8CB-65B8-468D-9AF3-E6B6444F9AB7/cmaf.m3u8 video: https://developer.apple.com/videos/play/wwdc2021/102/

When I load the URL, it doesn't have any data:

variant_m3u8 = m3u8.loads(url)
print(variant_m3u8.data)
{'media_sequence': 0,
 'is_variant': False,
 'is_endlist': False,
 'is_i_frames_only': False,
 'is_independent_segments': False,
 'is_images_only': False,
 'playlist_type': None,
 'playlists': [],
 'segments': [],
 'iframe_playlists': [],
 'image_playlists': [],
 'tiles': [],
 'media': [],
 'keys': [],
 'rendition_reports': [],
 'skip': {},
 'part_inf': {},
 'session_data': [],
 'session_keys': [],
 'segment_map': []}

There are a bunch of other m3u8 files inside this file, and I wonder what's the best way to parse such a playlist file? I aim to get to the video's subtitle (webvtt) from this playlist file.

davemevans commented 6 months ago

loads loads a playlist from a string. You need to use load if you want to load from a URL, as shown at https://github.com/globocom/m3u8?tab=readme-ov-file#loading-a-playlist.

Once you have that, you can use the bits at https://github.com/globocom/m3u8#variant-playlists-variable-bitrates. Subtitle playlists are described in MEDIA tags with TYPE=SUBTITLES - get the URI for the one you are interested in and load that.

mauricioabreu commented 1 month ago

Thank you @davemevans