m3uzi 0.4.3 → 0.5.0
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.
- data/lib/m3uzi.rb +23 -3
- data/lib/m3uzi/tag.rb +3 -5
- data/lib/m3uzi/version.rb +1 -1
- metadata +6 -8
data/lib/m3uzi.rb
CHANGED
@@ -9,14 +9,18 @@ require 'm3uzi/version'
|
|
9
9
|
class M3Uzi
|
10
10
|
|
11
11
|
attr_accessor :header_tags, :playlist_items
|
12
|
-
attr_accessor :final_media_file
|
13
|
-
attr_accessor :version
|
12
|
+
attr_accessor :playlist_type, :final_media_file
|
13
|
+
attr_accessor :version, :initial_media_sequence, :sliding_window_duration
|
14
14
|
|
15
15
|
def initialize
|
16
16
|
@header_tags = {}
|
17
17
|
@playlist_items = []
|
18
18
|
@final_media_file = true
|
19
19
|
@version = 1
|
20
|
+
@initial_media_sequence = 0
|
21
|
+
@sliding_window_duration = nil
|
22
|
+
@removed_file_count = 0
|
23
|
+
@playlist_type = :live
|
20
24
|
end
|
21
25
|
|
22
26
|
|
@@ -74,6 +78,8 @@ class M3Uzi
|
|
74
78
|
check_version_restrictions
|
75
79
|
io_stream << "#EXTM3U\n"
|
76
80
|
io_stream << "#EXT-X-VERSION:#{@version.to_i}\n" if @version > 1
|
81
|
+
io_stream << "#EXT-X-MEDIA-SEQUENCE:#{@initial_media_sequence+@removed_file_count}\n" if @playlist_type == :live
|
82
|
+
io_stream << "#EXT-X-PLAYLIST-TYPE:#{@playlist_type.to_s.upcase}\n" if [:event,:vod].include?(@playlist_type)
|
77
83
|
|
78
84
|
if items(File).length > 0
|
79
85
|
max_duration = valid_items(File).map { |f| f.duration.to_f }.max || 10.0
|
@@ -98,7 +104,7 @@ class M3Uzi
|
|
98
104
|
io_stream << (item.format + "\n")
|
99
105
|
end
|
100
106
|
|
101
|
-
io_stream << "#EXT-X-ENDLIST\n" if items(File).length > 0 && @final_media_file
|
107
|
+
io_stream << "#EXT-X-ENDLIST\n" if items(File).length > 0 && (@final_media_file || @playlist_type == :vod)
|
102
108
|
end
|
103
109
|
|
104
110
|
def write(path)
|
@@ -192,6 +198,7 @@ class M3Uzi
|
|
192
198
|
new_file.duration = duration if duration
|
193
199
|
yield(new_file) if block_given?
|
194
200
|
@playlist_items << new_file
|
201
|
+
cleanup_sliding_window
|
195
202
|
end
|
196
203
|
|
197
204
|
def filenames
|
@@ -323,6 +330,19 @@ protected
|
|
323
330
|
# match.scan(/([A-Z-]+)\s*=\s*("[^"]*"|[^,]*)/) # return attributes as array of arrays
|
324
331
|
# end
|
325
332
|
|
333
|
+
def cleanup_sliding_window
|
334
|
+
return unless @sliding_window_duration && @playlist_type == :live
|
335
|
+
while total_duration > @sliding_window_duration
|
336
|
+
first_file = @playlist_items.detect { |item| item.kind_of?(File) && item.valid? }
|
337
|
+
@playlist_items.delete(first_file)
|
338
|
+
@removed_file_count += 1
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
def total_duration
|
343
|
+
valid_items(File).inject(0.0) { |d,f| d + f.duration.to_f }
|
344
|
+
end
|
345
|
+
|
326
346
|
def self.format_iv(num)
|
327
347
|
'0x' + num.to_s(16).rjust(32,'0')
|
328
348
|
end
|
data/lib/m3uzi/tag.rb
CHANGED
@@ -4,10 +4,10 @@ class M3Uzi
|
|
4
4
|
attr_reader :name
|
5
5
|
attr_accessor :value
|
6
6
|
|
7
|
-
VALID_TAGS = %w{
|
7
|
+
VALID_TAGS = %w{ALLOW-CACHE}
|
8
8
|
|
9
|
-
# Unsupported tags:
|
10
|
-
# Autogenerated tags: EXTM3U, VERSION, ENDLIST, BYTERANGE, TARGETDURATION
|
9
|
+
# Unsupported tags: I-FRAMES-ONLY
|
10
|
+
# Autogenerated tags: EXTM3U, VERSION, ENDLIST, BYTERANGE, TARGETDURATION, MEDIA-SEQUENCE, PLAYLIST-TYPE
|
11
11
|
|
12
12
|
def name=(n)
|
13
13
|
@name = n.to_s.upcase.gsub("_", "-")
|
@@ -21,8 +21,6 @@ class M3Uzi
|
|
21
21
|
|
22
22
|
def valid?
|
23
23
|
case name
|
24
|
-
when 'PLAYLIST-TYPE'
|
25
|
-
['EVENT','VOD'].include?(value)
|
26
24
|
when 'ALLOW-CACHE'
|
27
25
|
['YES','NO'].include?(value)
|
28
26
|
else
|
data/lib/m3uzi/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: m3uzi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 0.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brandon Arbini
|
@@ -16,8 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date:
|
20
|
-
default_executable:
|
19
|
+
date: 2012-02-23 00:00:00 Z
|
21
20
|
dependencies: []
|
22
21
|
|
23
22
|
description: Read and write M3U files with (relative) ease.
|
@@ -44,7 +43,6 @@ files:
|
|
44
43
|
- LICENSE
|
45
44
|
- Rakefile
|
46
45
|
- README.md
|
47
|
-
has_rdoc: true
|
48
46
|
homepage: http://github.com/zencoder/m3uzi
|
49
47
|
licenses: []
|
50
48
|
|
@@ -74,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
72
|
requirements: []
|
75
73
|
|
76
74
|
rubyforge_project:
|
77
|
-
rubygems_version: 1.
|
75
|
+
rubygems_version: 1.8.15
|
78
76
|
signing_key:
|
79
77
|
specification_version: 3
|
80
78
|
summary: Read and write M3U files with (relative) ease.
|