m3uzi 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/m3uzi/file.rb CHANGED
@@ -4,6 +4,12 @@ class M3Uzi
4
4
 
5
5
  attr_accessor :path, :duration, :description
6
6
 
7
+ def attribute_string
8
+ s = []
9
+ s << duration
10
+ s << description if description
11
+ s.join(',')
12
+ end
7
13
  end
8
14
 
9
15
  end
data/lib/m3uzi/stream.rb CHANGED
@@ -2,8 +2,16 @@ class M3Uzi
2
2
 
3
3
  class Stream
4
4
 
5
- attr_accessor :bandwidth, :program_id, :codecs, :resolution
5
+ attr_accessor :path, :bandwidth, :program_id, :codecs, :resolution
6
6
 
7
+ def attribute_string
8
+ s = []
9
+ s << "PROGRAM-ID=#{program_id || 1}"
10
+ s << "BANDWIDTH=#{bandwidth}" if bandwidth
11
+ s << "CODECS=\"#{codecs}\"" if codecs
12
+ s << "RESOLUTION=#{resolution}" if resolution
13
+ s.join(',')
14
+ end
7
15
  end
8
16
 
9
17
  end
data/lib/m3uzi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class M3Uzi
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
data/lib/m3uzi.rb CHANGED
@@ -6,16 +6,19 @@ require 'm3uzi/version'
6
6
 
7
7
  class M3Uzi
8
8
 
9
- # Unsupported: KEY PROGRAM-DATE-TIME STREAM-INF DISCONTINUITY
10
- VALID_TAGS = %w{TARGETDURATION MEDIA-SEQUENCE ALLOW-CACHE STREAM-INF ENDLIST VERSION}
9
+ # Unsupported: KEY PROGRAM-DATE-TIME DISCONTINUITY
10
+ VALID_TAGS = %w{TARGETDURATION MEDIA-SEQUENCE ALLOW-CACHE ENDLIST VERSION}
11
11
 
12
- attr_accessor :files
12
+ attr_accessor :files, :streams
13
13
  attr_accessor :tags, :comments
14
+ attr_accessor :final_media_file
14
15
 
15
16
  def initialize
16
17
  @files = []
18
+ @streams = []
17
19
  @tags = []
18
20
  @comments = []
21
+ @final_media_file = true
19
22
  end
20
23
 
21
24
 
@@ -41,6 +44,20 @@ class M3Uzi
41
44
  file.duration = duration
42
45
  file.description = description
43
46
  end
47
+ m3u.final_media_file = false
48
+ when :stream
49
+ attributes = parse_stream_tag(line)
50
+ m3u.add_stream do |stream|
51
+ stream.path = lines[i+1].strip
52
+ attributes.each_pair do |k,v|
53
+ k = k.to_s.downcase.sub('-','_')
54
+ next unless [:bandwidth, :program_id, :codecs, :resolution].include?(k)
55
+ v = $1 if v.to_s =~ /^"(.*)"$/
56
+ stream.send("#{k}=", v)
57
+ end
58
+ end
59
+ when :final
60
+ m3u.final_media_file = true
44
61
  else
45
62
  next
46
63
  end
@@ -65,11 +82,14 @@ class M3Uzi
65
82
  f << "\n"
66
83
  end
67
84
  files.each do |file|
68
- f << "#EXTINF:#{file.duration}"
69
- file.description && f << ", #{file.description}"
85
+ f << "#EXTINF:#{file.attribute_string}"
70
86
  f << "\n#{file.path}\n"
71
87
  end
72
- f << "#EXT-X-ENDLIST\n"
88
+ streams.each do |stream|
89
+ f << "#EXT-X-STREAM-INF:#{stream.attribute_string}"
90
+ f << "\n#{stream.path}\n"
91
+ end
92
+ f << "#EXT-X-ENDLIST\n" if files.length > 0 && final_media_file
73
93
  f.close()
74
94
  end
75
95
 
@@ -89,6 +109,21 @@ class M3Uzi
89
109
  end
90
110
 
91
111
 
112
+ #-------------------------------------
113
+ # Streams
114
+ #-------------------------------------
115
+
116
+ def add_stream(&block)
117
+ new_stream = M3Uzi::Stream.new
118
+ yield(new_stream)
119
+ @streams << new_stream
120
+ end
121
+
122
+ def stream_names
123
+ streams.map{|stream| stream.path }
124
+ end
125
+
126
+
92
127
  #-------------------------------------
93
128
  # Tags
94
129
  #-------------------------------------
@@ -136,6 +171,10 @@ protected
136
171
  :comment
137
172
  when /^#EXTINF/
138
173
  :info
174
+ when /^#EXT(-X)?-STREAM-INF/
175
+ :stream
176
+ when /^#EXT(-X)?-ENDLIST/
177
+ :final
139
178
  when /^#EXT(?!INF)/
140
179
  :tag
141
180
  else
@@ -153,8 +192,7 @@ protected
153
192
 
154
193
  def self.parse_stream_tag(line)
155
194
  match = line.match(/^#EXT-X-STREAM-INF:(.*)$/)[1]
156
- attributes = match.split(/\s*,\s*/)
157
- attributes.map{|a| a.split(/\s*=\s*/) }
195
+ match.scan(/([A-Z-]+)\s*=\s*("[^"]*"|[^,]*)/) # return attributes as array of arrays
158
196
  end
159
197
 
160
198
  end
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: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brandon Arbini
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-27 00:00:00 -05:00
18
+ date: 2010-12-30 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies: []
21
21