lib/m3u8/writer.rb in m3u8-0.7.1 vs lib/m3u8/writer.rb in m3u8-0.8.0
- old
+ new
@@ -3,25 +3,38 @@
# Writer provides generation of text output of playlists in m3u8 format
class Writer
attr_accessor :io
def initialize(io)
- self.io = io
+ @io = io
end
def write(playlist)
validate(playlist)
write_header(playlist)
playlist.items.each do |item|
io.puts item.to_s
end
- return if playlist.master?
+ write_footer(playlist)
+ end
+
+ def write_footer(playlist)
+ return if playlist.live? || playlist.master?
io.puts '#EXT-X-ENDLIST'
end
+ def write_header(playlist)
+ io.puts '#EXTM3U'
+ if playlist.master?
+ write_master_playlist_header(playlist)
+ else
+ write_media_playlist_header(playlist)
+ end
+ end
+
private
def target_duration_format(playlist)
format('#EXT-X-TARGETDURATION:%d', playlist.target)
end
@@ -35,17 +48,14 @@
return if cache.nil?
io.puts "#EXT-X-ALLOW-CACHE:#{cache ? 'YES' : 'NO'}"
end
- def write_header(playlist)
- io.puts '#EXTM3U'
- if playlist.master?
- write_master_playlist_header(playlist)
- else
- write_media_playlist_header(playlist)
- end
+ def write_discontinuity_sequence_tag(sequence)
+ return if sequence.nil?
+
+ io.puts "#EXT-X-DISCONTINUITY-SEQUENCE:#{sequence}"
end
def write_independent_segments_tag(independent_segments)
return unless independent_segments
@@ -61,9 +71,10 @@
io.puts "#EXT-X-PLAYLIST-TYPE:#{playlist.type}" unless playlist.type.nil?
write_version_tag(playlist.version)
write_independent_segments_tag(playlist.independent_segments)
io.puts '#EXT-X-I-FRAMES-ONLY' if playlist.iframes_only
io.puts "#EXT-X-MEDIA-SEQUENCE:#{playlist.sequence}"
+ write_discontinuity_sequence_tag(playlist.discontinuity_sequence)
write_cache_tag(playlist.cache)
io.puts target_duration_format(playlist)
end
def write_version_tag(version)