m3u8-parser
m3u8-parser copied to clipboard
EXT-X-KEY tag only applies to the first segment after it
Some HLS media playlists provide only one EXT-X-KEY tag to indicate how to decrypt the segments rather than provide it before every segments. Like below.
https://bitmovin-a.akamaihd.net/content/art-of-motion_drm/m3u8s/11331_video_1080_4800000.m3u8
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-TARGETDURATION:4
#EXT-X-KEY:METHOD=AES-128,URI="../video/1080_4800000/enc_hls/encryption.key",IV=0x613E8B8CE9CE208C4EAD4A0E03636371
#EXTINF:4.0
../video/1080_4800000/enc_hls/segment_0.ts
#EXTINF:4.0
../video/1080_4800000/enc_hls/segment_1.ts
#EXTINF:4.0
../video/1080_4800000/enc_hls/segment_2.ts
#EXTINF:4.0
../video/1080_4800000/enc_hls/segment_3.ts
It seems that all segments are encrypted and can be decrypt by the key. However, If I use MediaPlaylistParser to parse the playlist, only the first segment has SegmentKey object. Other segments have no SegmentKey. Would you set the same SegmentKey object to other segments?
Hi,
Yes, currently you'll have to find the previous non-empty key. It's the same for all media segment attributes. I guess it would be handy if the parser could do that for you. Pull requests are welcome :)