-
Notifications
You must be signed in to change notification settings - Fork 1
/
m3u8.spec.ts
113 lines (90 loc) · 3.16 KB
/
m3u8.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
const chai = require('chai');
import {m3u8Parser} from '../src/index';
import {
m3u1,
m3u2,
m3u3,
m3u4,
m3u5,
m3u6,
m3u7,
m3u8,
m3u9
} from './mocks/hls.data';
chai.should();
describe('#m3u8Parser', function () {
let ret;
it('test base parse', () => {
ret = m3u8Parser(m3u1, 'http://a.b.com/index.m3u8')
ret['master']['should']['be'].equal(false)
ret['live']['should']['be'].equal(false)
ret['segments']['length']['should']['be'].equal(3)
ret['endSN']['should']['be'].equal(2)
ret['duration']['should']['be'].equal(21)
});
it('test bad case', () => {
ret = m3u8Parser("123", 'http://a.b.com/index.m3u8');
ret['error']
.should
.be
.equal(1);
ret = m3u8Parser("#123", '');
ret['msg']
.should
.be
.equal('invalid input');
ret = m3u8Parser("#123 \n ##ffff \n 123", 'http://a.b.com/index.m3u8')
ret['msg']
.should
.be
.equal('invalid m3u8');
})
it('test with discontinuity tag', () => {
ret = m3u8Parser(m3u2, 'http://a.b.com/index.m3u8')
ret['duration']['should']['be'].equal(45)
ret['segments']['length']['should']['be'].equal(5)
ret['segments']['1']['cc']['should']['be'].equal(0)
ret['segments']['2']['cc']['should']['be'].equal(1)
ret['segments']['3']['cc']['should']['be'].equal(1)
ret['segments']['4']['cc']['should']['be'].equal(2)
})
it('test live parse', () => {
ret = m3u8Parser(m3u3, 'http://a.b.com/index.m3u8')
ret['live']['should']['be'].equal(true)
ret['startSN']['should']['be'].equal(2680)
ret['segments'][0]['start']['should']['be'].equal(20)
ret['duration']['should']['be'].equal(41)
})
it('test segment with relative url', () => {
ret = m3u8Parser(m3u4, 'http://a.b.com/a/b/c/index.m3u8')
ret['segments'][0]['url']['should']['be'].equal('http://a.b.com/a/b/c/1.ts')
ret['segments'][1]['url']['should']['be'].equal('http://a.b.com/a/b/c/2.ts')
ret['segments'][2]['url']['should']['be'].equal('http://a.b.com/a/b/c/3.ts')
})
it('test m3u8 encryted with aes-128', () => {
ret = m3u8Parser(m3u5, 'http://a.b.com/index.m3u8');
ret['should']['have'].property("key")
ret['key']['length']['should']['be'].equal(2)
ret['key'][0]['url']['should']['be'].equal('http://a.b.com/key.key')
ret['key'][1]['url']['should']['be'].equal('http://a.b.com/key1.key')
ret['segments'][2]['keyIndex']['should']['be'].equal(0)
ret['segments'][3]['keyIndex']['should']['be'].equal(1)
})
it('test m3u8 encryted with sample-aes', () => {
ret = m3u8Parser(m3u6, 'http://a.b.com/index.m3u8')
ret['key']['length']['should']['be'].equal(2)
})
it('test base master m3u8', () => {
ret = m3u8Parser(m3u7, 'http://a.b.com/index.m3u8')
ret['medias']['length']['should']['be'].equal(0)
ret['levels']['length']['should']['be'].equal(4)
})
it('test master m3u8 with alter media track', () => {
ret = m3u8Parser(m3u8, 'http://a.b.com/index.m3u8')
ret['medias']['length']['should']['be'].equal(3)
})
it('test m3u8 with init metadata info', () => {
ret = m3u8Parser(m3u9, 'http://a.b.com/index.m3u8')
ret['should']['have'].property("map")
})
});