m3u8 0.8.2 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +23 -0
- data/.gitignore +1 -1
- data/.rubocop.yml +31 -0
- data/CHANGELOG.md +107 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +1 -1
- data/README.md +524 -40
- data/Rakefile +1 -0
- data/bin/m3u8 +6 -0
- data/lib/m3u8/attribute_formatter.rb +47 -0
- data/lib/m3u8/bitrate_item.rb +31 -0
- data/lib/m3u8/builder.rb +48 -0
- data/lib/m3u8/byte_range.rb +10 -0
- data/lib/m3u8/cli/inspect_command.rb +97 -0
- data/lib/m3u8/cli/validate_command.rb +24 -0
- data/lib/m3u8/cli.rb +116 -0
- data/lib/m3u8/codecs.rb +89 -0
- data/lib/m3u8/content_steering_item.rb +45 -0
- data/lib/m3u8/date_range_item.rb +135 -64
- data/lib/m3u8/define_item.rb +54 -0
- data/lib/m3u8/discontinuity_item.rb +3 -0
- data/lib/m3u8/encryptable.rb +27 -30
- data/lib/m3u8/error.rb +1 -0
- data/lib/m3u8/gap_item.rb +14 -0
- data/lib/m3u8/key_item.rb +7 -0
- data/lib/m3u8/map_item.rb +16 -5
- data/lib/m3u8/media_item.rb +48 -76
- data/lib/m3u8/part_inf_item.rb +35 -0
- data/lib/m3u8/part_item.rb +67 -0
- data/lib/m3u8/playback_start.rb +19 -12
- data/lib/m3u8/playlist.rb +221 -13
- data/lib/m3u8/playlist_item.rb +128 -124
- data/lib/m3u8/preload_hint_item.rb +54 -0
- data/lib/m3u8/reader.rb +86 -28
- data/lib/m3u8/rendition_report_item.rb +48 -0
- data/lib/m3u8/scte35.rb +130 -0
- data/lib/m3u8/scte35_bit_reader.rb +51 -0
- data/lib/m3u8/scte35_segmentation_descriptor.rb +54 -0
- data/lib/m3u8/scte35_splice_insert.rb +62 -0
- data/lib/m3u8/scte35_splice_null.rb +8 -0
- data/lib/m3u8/scte35_time_signal.rb +19 -0
- data/lib/m3u8/segment_item.rb +37 -3
- data/lib/m3u8/server_control_item.rb +69 -0
- data/lib/m3u8/session_data_item.rb +17 -28
- data/lib/m3u8/session_key_item.rb +8 -1
- data/lib/m3u8/skip_item.rb +48 -0
- data/lib/m3u8/time_item.rb +10 -0
- data/lib/m3u8/version.rb +1 -1
- data/lib/m3u8/writer.rb +24 -1
- data/lib/m3u8.rb +30 -6
- data/m3u8.gemspec +12 -12
- data/spec/fixtures/content_steering.m3u8 +10 -0
- data/spec/fixtures/daterange_playlist.m3u8 +14 -0
- data/spec/fixtures/encrypted_discontinuity.m3u8 +17 -0
- data/spec/fixtures/event_playlist.m3u8 +18 -0
- data/spec/fixtures/gap_playlist.m3u8 +14 -0
- data/spec/fixtures/ll_hls_advanced.m3u8 +18 -0
- data/spec/fixtures/ll_hls_playlist.m3u8 +20 -0
- data/spec/fixtures/master_full.m3u8 +14 -0
- data/spec/fixtures/master_v13.m3u8 +8 -0
- data/spec/lib/m3u8/bitrate_item_spec.rb +26 -0
- data/spec/lib/m3u8/builder_spec.rb +352 -0
- data/spec/lib/m3u8/byte_range_spec.rb +1 -0
- data/spec/lib/m3u8/cli/inspect_command_spec.rb +102 -0
- data/spec/lib/m3u8/cli/validate_command_spec.rb +39 -0
- data/spec/lib/m3u8/cli_spec.rb +104 -0
- data/spec/lib/m3u8/content_steering_item_spec.rb +56 -0
- data/spec/lib/m3u8/date_range_item_spec.rb +159 -31
- data/spec/lib/m3u8/define_item_spec.rb +59 -0
- data/spec/lib/m3u8/discontinuity_item_spec.rb +1 -0
- data/spec/lib/m3u8/gap_item_spec.rb +12 -0
- data/spec/lib/m3u8/key_item_spec.rb +1 -0
- data/spec/lib/m3u8/map_item_spec.rb +1 -0
- data/spec/lib/m3u8/media_item_spec.rb +34 -0
- data/spec/lib/m3u8/part_inf_item_spec.rb +27 -0
- data/spec/lib/m3u8/part_item_spec.rb +67 -0
- data/spec/lib/m3u8/playback_start_spec.rb +4 -5
- data/spec/lib/m3u8/playlist_item_spec.rb +130 -17
- data/spec/lib/m3u8/playlist_spec.rb +545 -13
- data/spec/lib/m3u8/preload_hint_item_spec.rb +57 -0
- data/spec/lib/m3u8/reader_spec.rb +376 -29
- data/spec/lib/m3u8/rendition_report_item_spec.rb +56 -0
- data/spec/lib/m3u8/round_trip_spec.rb +152 -0
- data/spec/lib/m3u8/scte35_bit_reader_spec.rb +106 -0
- data/spec/lib/m3u8/scte35_segmentation_descriptor_spec.rb +143 -0
- data/spec/lib/m3u8/scte35_spec.rb +94 -0
- data/spec/lib/m3u8/scte35_splice_insert_spec.rb +185 -0
- data/spec/lib/m3u8/scte35_splice_null_spec.rb +12 -0
- data/spec/lib/m3u8/scte35_time_signal_spec.rb +50 -0
- data/spec/lib/m3u8/segment_item_spec.rb +47 -0
- data/spec/lib/m3u8/server_control_item_spec.rb +64 -0
- data/spec/lib/m3u8/session_data_item_spec.rb +1 -0
- data/spec/lib/m3u8/session_key_item_spec.rb +1 -0
- data/spec/lib/m3u8/skip_item_spec.rb +48 -0
- data/spec/lib/m3u8/time_item_spec.rb +1 -0
- data/spec/lib/m3u8/writer_spec.rb +69 -30
- data/spec/lib/m3u8_spec.rb +1 -0
- data/spec/spec_helper.rb +4 -87
- metadata +70 -129
- data/.hound.yml +0 -3
- data/.travis.yml +0 -8
- data/Guardfile +0 -6
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe M3u8::Scte35TimeSignal do
|
|
6
|
+
def build_time_signal_hex(command_bytes, command_length: nil)
|
|
7
|
+
cmd_len = command_length || command_bytes.length
|
|
8
|
+
section_length = 11 + cmd_len + 6
|
|
9
|
+
header = splice_info_header(section_length, cmd_len)
|
|
10
|
+
command_hex = command_bytes.map { |b| format('%02X', b) }.join
|
|
11
|
+
"0x#{header}06#{command_hex}0000DEADBEEF"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def splice_info_header(section_length, cmd_length)
|
|
15
|
+
table_id = 'FC'
|
|
16
|
+
section_header = format('%04X', 0x3000 | section_length)
|
|
17
|
+
proto_and_pts = '000000000000'
|
|
18
|
+
cw_index = '00'
|
|
19
|
+
tier_cmd = format('%06X', (0xFFF << 12) | cmd_length)
|
|
20
|
+
"#{table_id}#{section_header}#{proto_and_pts}#{cw_index}#{tier_cmd}"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe '.parse_from' do
|
|
24
|
+
it 'should parse time_signal with PTS time' do
|
|
25
|
+
# splice_time: time_specified(1)=1, reserved(6)=111111, pts(33)=90000
|
|
26
|
+
# 90000 = 0x15F90
|
|
27
|
+
# 1_111111_0_00000000_00000001_01011111_10010000
|
|
28
|
+
# = FE 00 01 5F 90
|
|
29
|
+
command_bytes = [0xFE, 0x00, 0x01, 0x5F, 0x90]
|
|
30
|
+
hex = build_time_signal_hex(command_bytes)
|
|
31
|
+
result = M3u8::Scte35.parse(hex)
|
|
32
|
+
cmd = result.splice_command
|
|
33
|
+
|
|
34
|
+
expect(cmd).to be_a(described_class)
|
|
35
|
+
expect(cmd.pts_time).to eq(90_000)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'should parse time_signal without time_specified' do
|
|
39
|
+
# time_specified(1)=0, reserved(7)=1111111
|
|
40
|
+
# = 0x7F (1 byte)
|
|
41
|
+
command_bytes = [0x7F]
|
|
42
|
+
hex = build_time_signal_hex(command_bytes)
|
|
43
|
+
result = M3u8::Scte35.parse(hex)
|
|
44
|
+
cmd = result.splice_command
|
|
45
|
+
|
|
46
|
+
expect(cmd).to be_a(described_class)
|
|
47
|
+
expect(cmd.pts_time).to be_nil
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
require 'spec_helper'
|
|
3
4
|
|
|
4
5
|
describe M3u8::SegmentItem do
|
|
@@ -21,6 +22,29 @@ describe M3u8::SegmentItem do
|
|
|
21
22
|
expect(item.comment).to eq 'anything'
|
|
22
23
|
end
|
|
23
24
|
|
|
25
|
+
describe '.parse' do
|
|
26
|
+
it 'parses tag with duration and comment' do
|
|
27
|
+
tag = '#EXTINF:10.991,anything'
|
|
28
|
+
item = described_class.parse(tag)
|
|
29
|
+
expect(item.duration).to eq(10.991)
|
|
30
|
+
expect(item.comment).to eq('anything')
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'parses tag with duration only' do
|
|
34
|
+
tag = '#EXTINF:10.991,'
|
|
35
|
+
item = described_class.parse(tag)
|
|
36
|
+
expect(item.duration).to eq(10.991)
|
|
37
|
+
expect(item.comment).to be_nil
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'parses tag without trailing comma' do
|
|
41
|
+
tag = '#EXTINF:10.991'
|
|
42
|
+
item = described_class.parse(tag)
|
|
43
|
+
expect(item.duration).to eq(10.991)
|
|
44
|
+
expect(item.comment).to be_nil
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
24
48
|
it 'should provide m3u8 format representation' do
|
|
25
49
|
time_hash = { time: '2010-02-19T14:54:23.031' }
|
|
26
50
|
time_item = M3u8::TimeItem.new(time_hash)
|
|
@@ -53,4 +77,27 @@ describe M3u8::SegmentItem do
|
|
|
53
77
|
expected = "#EXTINF:10.991,anything\n#EXT-X-BYTERANGE:4500\ntest.ts"
|
|
54
78
|
expect(output).to eq expected
|
|
55
79
|
end
|
|
80
|
+
|
|
81
|
+
it 'wraps raw Time in program_date_time as TimeItem' do
|
|
82
|
+
time = Time.iso8601('2020-11-25T20:27:00Z')
|
|
83
|
+
hash = { duration: 10, segment: 'segment.aac',
|
|
84
|
+
program_date_time: time }
|
|
85
|
+
item = M3u8::SegmentItem.new(hash)
|
|
86
|
+
output = item.to_s
|
|
87
|
+
expected = "#EXTINF:10,\n" \
|
|
88
|
+
"#EXT-X-PROGRAM-DATE-TIME:2020-11-25T20:27:00Z\n" \
|
|
89
|
+
'segment.aac'
|
|
90
|
+
expect(output).to eq expected
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it 'converts very small durations to floating point' do
|
|
94
|
+
time = Time.iso8601('2020-11-25T20:27:00Z')
|
|
95
|
+
hash = { duration: 0.000001, segment: 'test.ts', program_date_time: time }
|
|
96
|
+
item = M3u8::SegmentItem.new(hash)
|
|
97
|
+
output = item.to_s
|
|
98
|
+
expected = "#EXTINF:0.000001,\n" \
|
|
99
|
+
"#EXT-X-PROGRAM-DATE-TIME:2020-11-25T20:27:00Z\n" \
|
|
100
|
+
'test.ts'
|
|
101
|
+
expect(output).to eq expected
|
|
102
|
+
end
|
|
56
103
|
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe M3u8::ServerControlItem do
|
|
6
|
+
describe '.new' do
|
|
7
|
+
it 'assigns attributes from options' do
|
|
8
|
+
options = { can_skip_until: 36.0, can_skip_dateranges: true,
|
|
9
|
+
hold_back: 15.0, part_hold_back: 3.0,
|
|
10
|
+
can_block_reload: true }
|
|
11
|
+
item = described_class.new(options)
|
|
12
|
+
expect(item.can_skip_until).to eq(36.0)
|
|
13
|
+
expect(item.can_skip_dateranges).to be true
|
|
14
|
+
expect(item.hold_back).to eq(15.0)
|
|
15
|
+
expect(item.part_hold_back).to eq(3.0)
|
|
16
|
+
expect(item.can_block_reload).to be true
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe '.parse' do
|
|
21
|
+
it 'parses tag with all attributes' do
|
|
22
|
+
tag = '#EXT-X-SERVER-CONTROL:CAN-SKIP-UNTIL=36.0,' \
|
|
23
|
+
'CAN-SKIP-DATERANGES=YES,HOLD-BACK=15.0,' \
|
|
24
|
+
'PART-HOLD-BACK=3.0,CAN-BLOCK-RELOAD=YES'
|
|
25
|
+
item = described_class.parse(tag)
|
|
26
|
+
expect(item.can_skip_until).to eq(36.0)
|
|
27
|
+
expect(item.can_skip_dateranges).to be true
|
|
28
|
+
expect(item.hold_back).to eq(15.0)
|
|
29
|
+
expect(item.part_hold_back).to eq(3.0)
|
|
30
|
+
expect(item.can_block_reload).to be true
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'parses tag without optional attributes' do
|
|
34
|
+
tag = '#EXT-X-SERVER-CONTROL:PART-HOLD-BACK=1.0,' \
|
|
35
|
+
'CAN-BLOCK-RELOAD=YES'
|
|
36
|
+
item = described_class.parse(tag)
|
|
37
|
+
expect(item.can_skip_until).to be_nil
|
|
38
|
+
expect(item.can_skip_dateranges).to be false
|
|
39
|
+
expect(item.part_hold_back).to eq(1.0)
|
|
40
|
+
expect(item.can_block_reload).to be true
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe '#to_s' do
|
|
45
|
+
it 'returns tag with all attributes' do
|
|
46
|
+
options = { can_skip_until: 36.0, can_skip_dateranges: true,
|
|
47
|
+
hold_back: 15.0, part_hold_back: 3.0,
|
|
48
|
+
can_block_reload: true }
|
|
49
|
+
item = described_class.new(options)
|
|
50
|
+
expected = '#EXT-X-SERVER-CONTROL:CAN-SKIP-UNTIL=36.0,' \
|
|
51
|
+
'CAN-SKIP-DATERANGES=YES,HOLD-BACK=15.0,' \
|
|
52
|
+
'PART-HOLD-BACK=3.0,CAN-BLOCK-RELOAD=YES'
|
|
53
|
+
expect(item.to_s).to eq(expected)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'returns tag with only required attributes' do
|
|
57
|
+
options = { part_hold_back: 1.0, can_block_reload: true }
|
|
58
|
+
item = described_class.new(options)
|
|
59
|
+
expected = '#EXT-X-SERVER-CONTROL:PART-HOLD-BACK=1.0,' \
|
|
60
|
+
'CAN-BLOCK-RELOAD=YES'
|
|
61
|
+
expect(item.to_s).to eq(expected)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe M3u8::SkipItem do
|
|
6
|
+
describe '.new' do
|
|
7
|
+
it 'assigns attributes from options' do
|
|
8
|
+
options = { skipped_segments: 10,
|
|
9
|
+
recently_removed_dateranges: 'dr1\tdr2' }
|
|
10
|
+
item = described_class.new(options)
|
|
11
|
+
expect(item.skipped_segments).to eq(10)
|
|
12
|
+
expect(item.recently_removed_dateranges).to eq('dr1\tdr2')
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe '.parse' do
|
|
17
|
+
it 'parses tag with all attributes' do
|
|
18
|
+
tag = '#EXT-X-SKIP:SKIPPED-SEGMENTS=10,' \
|
|
19
|
+
'RECENTLY-REMOVED-DATERANGES="dr1\tdr2"'
|
|
20
|
+
item = described_class.parse(tag)
|
|
21
|
+
expect(item.skipped_segments).to eq(10)
|
|
22
|
+
expect(item.recently_removed_dateranges).to eq('dr1\tdr2')
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'parses tag without optional attributes' do
|
|
26
|
+
tag = '#EXT-X-SKIP:SKIPPED-SEGMENTS=5'
|
|
27
|
+
item = described_class.parse(tag)
|
|
28
|
+
expect(item.skipped_segments).to eq(5)
|
|
29
|
+
expect(item.recently_removed_dateranges).to be_nil
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe '#to_s' do
|
|
34
|
+
it 'returns tag with all attributes' do
|
|
35
|
+
options = { skipped_segments: 10,
|
|
36
|
+
recently_removed_dateranges: 'dr1\tdr2' }
|
|
37
|
+
item = described_class.new(options)
|
|
38
|
+
expected = '#EXT-X-SKIP:SKIPPED-SEGMENTS=10,' \
|
|
39
|
+
'RECENTLY-REMOVED-DATERANGES="dr1\tdr2"'
|
|
40
|
+
expect(item.to_s).to eq(expected)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'returns tag with only required attributes' do
|
|
44
|
+
item = described_class.new(skipped_segments: 5)
|
|
45
|
+
expect(item.to_s).to eq('#EXT-X-SKIP:SKIPPED-SEGMENTS=5')
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
require 'spec_helper'
|
|
3
4
|
|
|
4
5
|
describe M3u8::Writer do
|
|
@@ -16,7 +17,7 @@ describe M3u8::Writer do
|
|
|
16
17
|
item = M3u8::PlaylistItem.new(options)
|
|
17
18
|
playlist.items << item
|
|
18
19
|
options = { data_id: 'com.test.movie.title', value: 'Test',
|
|
19
|
-
|
|
20
|
+
language: 'en' }
|
|
20
21
|
item = M3u8::SessionDataItem.new(options)
|
|
21
22
|
playlist.items << item
|
|
22
23
|
|
|
@@ -27,7 +28,7 @@ describe M3u8::Writer do
|
|
|
27
28
|
%(RESOLUTION=1920x1080,CODECS="avc1.640029,mp4a.40.2") +
|
|
28
29
|
",BANDWIDTH=50000\nplaylist_url\n" +
|
|
29
30
|
%(#EXT-X-SESSION-DATA:DATA-ID="com.test.movie.title",) +
|
|
30
|
-
%(VALUE="Test",
|
|
31
|
+
%(VALUE="Test",LANGUAGE="en"\n)
|
|
31
32
|
|
|
32
33
|
io = StringIO.open
|
|
33
34
|
writer = described_class.new(io)
|
|
@@ -44,9 +45,7 @@ describe M3u8::Writer do
|
|
|
44
45
|
playlist = M3u8::Playlist.new
|
|
45
46
|
playlist.items << item
|
|
46
47
|
|
|
47
|
-
expected = "#EXTM3U\n"
|
|
48
|
-
%(#EXT-X-STREAM-INF:PROGRAM-ID=1,CODECS="mp4a.40.34") +
|
|
49
|
-
",BANDWIDTH=6400\nplaylist_url\n"
|
|
48
|
+
expected = "#EXTM3U\n#EXT-X-STREAM-INF:PROGRAM-ID=1,CODECS=\"mp4a.40.34\",BANDWIDTH=6400\nplaylist_url\n"
|
|
50
49
|
|
|
51
50
|
io = StringIO.open
|
|
52
51
|
writer = described_class.new(io)
|
|
@@ -93,16 +92,16 @@ describe M3u8::Writer do
|
|
|
93
92
|
writer.write(M3u8::Playlist.new)
|
|
94
93
|
|
|
95
94
|
expected = "#EXTM3U\n" \
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
"#EXT-X-MEDIA-SEQUENCE:0\n" \
|
|
96
|
+
"#EXT-X-TARGETDURATION:10\n" \
|
|
97
|
+
"#EXT-X-ENDLIST\n"
|
|
99
98
|
expect(io.string).to eq(expected)
|
|
100
99
|
end
|
|
101
100
|
end
|
|
102
101
|
|
|
103
102
|
context 'when playlist is a media playlist' do
|
|
104
103
|
it 'writes playlist to io' do
|
|
105
|
-
options = { version: 4, cache: false, target:
|
|
104
|
+
options = { version: 4, cache: false, target: 12, sequence: 1,
|
|
106
105
|
discontinuity_sequence: 10, type: 'EVENT',
|
|
107
106
|
iframes_only: true }
|
|
108
107
|
playlist = M3u8::Playlist.new(options)
|
|
@@ -111,16 +110,16 @@ describe M3u8::Writer do
|
|
|
111
110
|
playlist.items << item
|
|
112
111
|
|
|
113
112
|
expected = "#EXTM3U\n" \
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
113
|
+
"#EXT-X-PLAYLIST-TYPE:EVENT\n" \
|
|
114
|
+
"#EXT-X-VERSION:4\n" \
|
|
115
|
+
"#EXT-X-I-FRAMES-ONLY\n" \
|
|
116
|
+
"#EXT-X-MEDIA-SEQUENCE:1\n" \
|
|
117
|
+
"#EXT-X-DISCONTINUITY-SEQUENCE:10\n" \
|
|
118
|
+
"#EXT-X-ALLOW-CACHE:NO\n" \
|
|
119
|
+
"#EXT-X-TARGETDURATION:12\n" \
|
|
120
|
+
"#EXTINF:11.344644,\n" \
|
|
121
|
+
"1080-7mbps00000.ts\n" \
|
|
122
|
+
"#EXT-X-ENDLIST\n"
|
|
124
123
|
|
|
125
124
|
io = StringIO.open
|
|
126
125
|
writer = described_class.new(io)
|
|
@@ -133,7 +132,7 @@ describe M3u8::Writer do
|
|
|
133
132
|
it 'writes playlist to io' do
|
|
134
133
|
options = { duration: 11.344644, segment: '1080-7mbps00000.ts' }
|
|
135
134
|
item = M3u8::SegmentItem.new(options)
|
|
136
|
-
playlist = M3u8::Playlist.new(version: 7)
|
|
135
|
+
playlist = M3u8::Playlist.new(version: 7, target: 12)
|
|
137
136
|
playlist.items << item
|
|
138
137
|
|
|
139
138
|
options = { method: 'AES-128', uri: 'http://test.key',
|
|
@@ -149,7 +148,7 @@ describe M3u8::Writer do
|
|
|
149
148
|
expected = "#EXTM3U\n" \
|
|
150
149
|
"#EXT-X-VERSION:7\n" \
|
|
151
150
|
"#EXT-X-MEDIA-SEQUENCE:0\n" \
|
|
152
|
-
"#EXT-X-TARGETDURATION:
|
|
151
|
+
"#EXT-X-TARGETDURATION:12\n" \
|
|
153
152
|
"#EXTINF:11.344644,\n" \
|
|
154
153
|
"1080-7mbps00000.ts\n" +
|
|
155
154
|
%(#EXT-X-KEY:METHOD=AES-128,URI="http://test.key",) +
|
|
@@ -166,10 +165,49 @@ describe M3u8::Writer do
|
|
|
166
165
|
end
|
|
167
166
|
end
|
|
168
167
|
|
|
169
|
-
|
|
168
|
+
context 'when playlist is an LL-HLS media playlist' do
|
|
169
|
+
it 'writes server control and part inf in header' do
|
|
170
|
+
server_control = M3u8::ServerControlItem.new(
|
|
171
|
+
can_skip_until: 24.0, part_hold_back: 1.0,
|
|
172
|
+
can_block_reload: true
|
|
173
|
+
)
|
|
174
|
+
part_inf = M3u8::PartInfItem.new(part_target: 0.5)
|
|
175
|
+
playlist = M3u8::Playlist.new(
|
|
176
|
+
version: 9, target: 4, sequence: 100,
|
|
177
|
+
server_control: server_control, part_inf: part_inf,
|
|
178
|
+
live: true
|
|
179
|
+
)
|
|
180
|
+
item = M3u8::SegmentItem.new(duration: 4.0,
|
|
181
|
+
segment: 'seg100.mp4')
|
|
182
|
+
playlist.items << item
|
|
183
|
+
|
|
184
|
+
part = M3u8::PartItem.new(duration: 0.5,
|
|
185
|
+
uri: 'seg101.0.mp4',
|
|
186
|
+
independent: true)
|
|
187
|
+
playlist.items << part
|
|
188
|
+
|
|
189
|
+
io = StringIO.open
|
|
190
|
+
writer = described_class.new(io)
|
|
191
|
+
writer.write(playlist)
|
|
192
|
+
|
|
193
|
+
expect(io.string).to include(
|
|
194
|
+
'#EXT-X-SERVER-CONTROL:CAN-SKIP-UNTIL=24.0,' \
|
|
195
|
+
'PART-HOLD-BACK=1.0,CAN-BLOCK-RELOAD=YES'
|
|
196
|
+
)
|
|
197
|
+
expect(io.string).to include(
|
|
198
|
+
'#EXT-X-PART-INF:PART-TARGET=0.5'
|
|
199
|
+
)
|
|
200
|
+
expect(io.string).to include(
|
|
201
|
+
'#EXT-X-PART:DURATION=0.5,URI="seg101.0.mp4",INDEPENDENT=YES'
|
|
202
|
+
)
|
|
203
|
+
expect(io.string).not_to include('#EXT-X-ENDLIST')
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
it 'raises error with specific messages if item types are mixed' do
|
|
170
208
|
playlist = M3u8::Playlist.new
|
|
171
|
-
options = { program_id: 1, width: 1920, height: 1080,
|
|
172
|
-
bandwidth: 540,
|
|
209
|
+
options = { program_id: 1, width: 1920, height: 1080,
|
|
210
|
+
codecs: 'avc', bandwidth: 540, uri: 'test.url' }
|
|
173
211
|
item = M3u8::PlaylistItem.new(options)
|
|
174
212
|
playlist.items << item
|
|
175
213
|
|
|
@@ -177,7 +215,8 @@ describe M3u8::Writer do
|
|
|
177
215
|
item = M3u8::SegmentItem.new(options)
|
|
178
216
|
playlist.items << item
|
|
179
217
|
|
|
180
|
-
message = 'Playlist is invalid
|
|
218
|
+
message = 'Playlist is invalid: Playlist contains both ' \
|
|
219
|
+
'master and media items'
|
|
181
220
|
io = StringIO.new
|
|
182
221
|
writer = described_class.new(io)
|
|
183
222
|
expect { writer.write(playlist) }
|
|
@@ -220,8 +259,8 @@ describe M3u8::Writer do
|
|
|
220
259
|
expect(playlist.master?).to be true
|
|
221
260
|
|
|
222
261
|
expected = "#EXTM3U\n" \
|
|
223
|
-
|
|
224
|
-
|
|
262
|
+
"#EXT-X-VERSION:6\n" \
|
|
263
|
+
"#EXT-X-INDEPENDENT-SEGMENTS\n"
|
|
225
264
|
|
|
226
265
|
io = StringIO.open
|
|
227
266
|
writer = described_class.new(io)
|
|
@@ -242,9 +281,9 @@ describe M3u8::Writer do
|
|
|
242
281
|
writer.write_header(playlist)
|
|
243
282
|
|
|
244
283
|
expected = "#EXTM3U\n" \
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
284
|
+
"#EXT-X-VERSION:7\n" \
|
|
285
|
+
"#EXT-X-MEDIA-SEQUENCE:0\n" \
|
|
286
|
+
"#EXT-X-TARGETDURATION:10\n"
|
|
248
287
|
|
|
249
288
|
expect(io.string).to eq(expected)
|
|
250
289
|
end
|
data/spec/lib/m3u8_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
|
@@ -1,100 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
require 'm3u8'
|
|
3
2
|
require 'simplecov'
|
|
4
|
-
|
|
3
|
+
SimpleCov.start do
|
|
4
|
+
minimum_coverage 100
|
|
5
|
+
end
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
SimpleCov::Formatter::HTMLFormatter,
|
|
8
|
-
Coveralls::SimpleCov::Formatter
|
|
9
|
-
])
|
|
10
|
-
SimpleCov.start
|
|
7
|
+
require 'm3u8'
|
|
11
8
|
|
|
12
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
|
13
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
|
14
|
-
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
|
15
|
-
# file to always be loaded, without a need to explicitly require it in any files.
|
|
16
|
-
#
|
|
17
|
-
# Given that it is always loaded, you are encouraged to keep this file as
|
|
18
|
-
# light-weight as possible. Requiring heavyweight dependencies from this file
|
|
19
|
-
# will add to the boot time of your test suite on EVERY test run, even for an
|
|
20
|
-
# individual file that may not need all of that loaded. Instead, consider making
|
|
21
|
-
# a separate helper file that requires the additional dependencies and performs
|
|
22
|
-
# the additional setup, and require it from the spec files that actually need it.
|
|
23
|
-
#
|
|
24
|
-
# The `.rspec` file also contains a few flags that are not defaults but that
|
|
25
|
-
# users commonly want.
|
|
26
|
-
#
|
|
27
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
|
28
9
|
RSpec.configure do |config|
|
|
29
|
-
# rspec-expectations config goes here. You can use an alternate
|
|
30
|
-
# assertion/expectation library such as wrong or the stdlib/minitest
|
|
31
|
-
# assertions if you prefer.
|
|
32
10
|
config.expect_with :rspec do |expectations|
|
|
33
|
-
# This option will default to `true` in RSpec 4. It makes the `description`
|
|
34
|
-
# and `failure_message` of custom matchers include text for helper methods
|
|
35
|
-
# defined using `chain`, e.g.:
|
|
36
|
-
# be_bigger_than(2).and_smaller_than(4).description
|
|
37
|
-
# # => "be bigger than 2 and smaller than 4"
|
|
38
|
-
# ...rather than:
|
|
39
|
-
# # => "be bigger than 2"
|
|
40
11
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
41
12
|
end
|
|
42
13
|
|
|
43
|
-
# rspec-mocks config goes here. You can use an alternate test double
|
|
44
|
-
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
|
45
14
|
config.mock_with :rspec do |mocks|
|
|
46
|
-
# Prevents you from mocking or stubbing a method that does not exist on
|
|
47
|
-
# a real object. This is generally recommended, and will default to
|
|
48
|
-
# `true` in RSpec 4.
|
|
49
15
|
mocks.verify_partial_doubles = true
|
|
50
16
|
end
|
|
51
|
-
|
|
52
|
-
# The settings below are suggested to provide a good initial experience
|
|
53
|
-
# with RSpec, but feel free to customize to your heart's content.
|
|
54
|
-
=begin
|
|
55
|
-
# These two settings work together to allow you to limit a spec run
|
|
56
|
-
# to individual examples or groups you care about by tagging them with
|
|
57
|
-
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
|
58
|
-
# get run.
|
|
59
|
-
config.filter_run :focus
|
|
60
|
-
config.run_all_when_everything_filtered = true
|
|
61
|
-
|
|
62
|
-
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
|
63
|
-
# For more details, see:
|
|
64
|
-
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
|
65
|
-
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
|
66
|
-
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
|
67
|
-
config.disable_monkey_patching!
|
|
68
|
-
|
|
69
|
-
# This setting enables warnings. It's recommended, but in some cases may
|
|
70
|
-
# be too noisy due to issues in dependencies.
|
|
71
|
-
config.warnings = true
|
|
72
|
-
|
|
73
|
-
# Many RSpec users commonly either run the entire suite or an individual
|
|
74
|
-
# file, and it's useful to allow more verbose output when running an
|
|
75
|
-
# individual spec file.
|
|
76
|
-
if config.files_to_run.one?
|
|
77
|
-
# Use the documentation formatter for detailed output,
|
|
78
|
-
# unless a formatter has already been configured
|
|
79
|
-
# (e.g. via a command-line flag).
|
|
80
|
-
config.default_formatter = 'doc'
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
# Print the 10 slowest examples and example groups at the
|
|
84
|
-
# end of the spec run, to help surface which specs are running
|
|
85
|
-
# particularly slow.
|
|
86
|
-
config.profile_examples = 10
|
|
87
|
-
|
|
88
|
-
# Run specs in random order to surface order dependencies. If you find an
|
|
89
|
-
# order dependency and want to debug it, you can fix the order by providing
|
|
90
|
-
# the seed, which is printed after each run.
|
|
91
|
-
# --seed 1234
|
|
92
|
-
config.order = :random
|
|
93
|
-
|
|
94
|
-
# Seed global randomization in this process using the `--seed` CLI option.
|
|
95
|
-
# Setting this allows you to use `--seed` to deterministically reproduce
|
|
96
|
-
# test failures related to randomization by passing the same `--seed` value
|
|
97
|
-
# as the one that triggered the failure.
|
|
98
|
-
Kernel.srand config.seed
|
|
99
|
-
=end
|
|
100
17
|
end
|