diff --git a/test/fixtures/m3u8/Multiple-rendition-groups.m3u8 b/test/fixtures/m3u8/Multiple-rendition-groups.m3u8 new file mode 100644 index 0000000..cca87af --- /dev/null +++ b/test/fixtures/m3u8/Multiple-rendition-groups.m3u8 @@ -0,0 +1,17 @@ +#EXTM3U +#EXT-X-VERSION:4 +#EXT-X-INDEPENDENT-SEGMENTS +#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac_high",NAME="English",DEFAULT=YES,URI="aac_high_eng.m3u8" +#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac_high",NAME="Japanese",DEFAULT=NO,URI="aac_high_jp.m3u8" +#EXT-X-STREAM-INF:BANDWIDTH=6000000,AUDIO="aac_high" +1080p.m3u8 +#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac_mid",NAME="English",DEFAULT=YES,URI="aac_mid_eng.m3u8" +#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac_mid",NAME="Japanese",DEFAULT=NO,URI="aac_mid_jp.m3u8" +#EXT-X-STREAM-INF:BANDWIDTH=3000000,AUDIO="aac_mid" +720p.m3u8 +#EXT-X-STREAM-INF:BANDWIDTH=1500000,AUDIO="aac_mid" +540p.m3u8 +#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac_low",NAME="English",DEFAULT=YES,URI="aac_low_eng.m3u8" +#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac_low",NAME="Japanese",DEFAULT=NO,URI="aac_low_jp.m3u8" +#EXT-X-STREAM-INF:BANDWIDTH=1000000,AUDIO="aac_low" +360p.m3u8 \ No newline at end of file diff --git a/test/fixtures/objects/Multiple-rendition-groups.js b/test/fixtures/objects/Multiple-rendition-groups.js new file mode 100644 index 0000000..411d778 --- /dev/null +++ b/test/fixtures/objects/Multiple-rendition-groups.js @@ -0,0 +1,28 @@ +const {MasterPlaylist, Variant, Rendition} = require('../../../types'); + +const renditions = [ + new Rendition({type: 'AUDIO', groupId: 'aac_high', name: 'English', isDefault: true, uri: 'aac_high_eng.m3u8'}), + new Rendition({type: 'AUDIO', groupId: 'aac_high', name: 'Japanese', isDefault: false, uri: 'aac_high_jp.m3u8'}), + new Rendition({type: 'AUDIO', groupId: 'aac_mid', name: 'English', isDefault: true, uri: 'aac_mid_eng.m3u8'}), + new Rendition({type: 'AUDIO', groupId: 'aac_mid', name: 'Japanese', isDefault: false, uri: 'aac_mid_jp.m3u8'}), + new Rendition({type: 'AUDIO', groupId: 'aac_low', name: 'English', isDefault: true, uri: 'aac_low_eng.m3u8'}), + new Rendition({type: 'AUDIO', groupId: 'aac_low', name: 'Japanese', isDefault: false, uri: 'aac_low_jp.m3u8'}), +]; +const variants = [ + {uri: '1080p.m3u8', bandwidth: 6000000, audioId: 'aac_high'}, + {uri: '720p.m3u8', bandwidth: 3000000, audioId: 'aac_mid'}, + {uri: '540p.m3u8', bandwidth: 1500000, audioId: 'aac_mid'}, + {uri: '360p.m3u8', bandwidth: 1000000, audioId: 'aac_low'}, +].map( + ({uri, bandwidth, audioId}) => new Variant({ + uri, bandwidth, audio: renditions.filter(({groupId}) => groupId === audioId) + }) +); + +const playlist = new MasterPlaylist({ + version: 4, + independentSegments: true, + variants, +}); + +module.exports = playlist; diff --git a/test/spec/misc/multiple-rendition-groups.js b/test/spec/misc/multiple-rendition-groups.js new file mode 100644 index 0000000..89e4b85 --- /dev/null +++ b/test/spec/misc/multiple-rendition-groups.js @@ -0,0 +1,49 @@ +const test = require("ava"); +const utils = require("../../helpers/utils"); +const HLS = require("../../.."); + +test("Multiple-Rendition-Groups_01", t => { + const shouldRead = ` + #EXTM3U + #EXT-X-VERSION:4 + #EXT-X-INDEPENDENT-SEGMENTS + #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac_high",NAME="English",DEFAULT=YES,URI="aac_high_eng.m3u8" + #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac_high",NAME="Japanese",DEFAULT=NO,URI="aac_high_jp.m3u8" + #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac_mid",NAME="English",DEFAULT=YES,URI="aac_mid_eng.m3u8" + #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac_mid",NAME="Japanese",DEFAULT=NO,URI="aac_mid_jp.m3u8" + #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac_low",NAME="English",DEFAULT=YES,URI="aac_low_eng.m3u8" + #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac_low",NAME="Japanese",DEFAULT=NO,URI="aac_low_jp.m3u8" + #EXT-X-STREAM-INF:BANDWIDTH=6000000,AUDIO="aac_high" + 1080p.m3u8 + #EXT-X-STREAM-INF:BANDWIDTH=3000000,AUDIO="aac_mid" + 720p.m3u8 + #EXT-X-STREAM-INF:BANDWIDTH=1500000,AUDIO="aac_mid" + 540p.m3u8 + #EXT-X-STREAM-INF:BANDWIDTH=1000000,AUDIO="aac_low" + 360p.m3u8 + `; + + const playlist = HLS.parse(shouldRead); + + const shouldWrite = ` + #EXTM3U + #EXT-X-VERSION:4 + #EXT-X-INDEPENDENT-SEGMENTS + #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac_high",NAME="English",DEFAULT=YES,URI="aac_high_eng.m3u8" + #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac_high",NAME="Japanese",DEFAULT=NO,URI="aac_high_jp.m3u8" + #EXT-X-STREAM-INF:BANDWIDTH=6000000,AUDIO="aac_high" + 1080p.m3u8 + #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac_mid",NAME="English",DEFAULT=YES,URI="aac_mid_eng.m3u8" + #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac_mid",NAME="Japanese",DEFAULT=NO,URI="aac_mid_jp.m3u8" + #EXT-X-STREAM-INF:BANDWIDTH=3000000,AUDIO="aac_mid" + 720p.m3u8 + #EXT-X-STREAM-INF:BANDWIDTH=1500000,AUDIO="aac_mid" + 540p.m3u8 + #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac_low",NAME="English",DEFAULT=YES,URI="aac_low_eng.m3u8" + #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac_low",NAME="Japanese",DEFAULT=NO,URI="aac_low_jp.m3u8" + #EXT-X-STREAM-INF:BANDWIDTH=1000000,AUDIO="aac_low" + 360p.m3u8 + `; + + t.is(HLS.stringify(playlist), utils.stripCommentsAndEmptyLines(shouldWrite)); +});