Module: HydraHls::FileSetBehavior

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/hydra_hls/file_set_behavior.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#create_derivatives(filename) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/models/concerns/hydra_hls/file_set_behavior.rb', line 8

def create_derivatives(filename)
  case mime_type
  when *self.class.audio_mime_types
    hls_dir = File.join(derivative_dir,"hls")
    create_audio_derivates filename, hls_dir
  when *self.class.video_mime_types
    hls_dir = File.join(derivative_dir,"hls")
    create_video_derivates filename, hls_dir
  else
    super
  end
end

#hls_master_playlist(root_url) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/concerns/hydra_hls/file_set_behavior.rb', line 25

def hls_master_playlist root_url
    type = mime_type.split('/')[0]
    defaults = hls_config[type]["default"]
    playlist = "#EXTM3U\n"
    playlist << "#EXT-X-VERSION:6\n"
    variants.each{|variant| 
      next if variant.blank?
      path, filename = File.split(variant)
      format = filename.gsub(".m3u8","")
      options = defaults.merge(hls_config[type][format])
      playlist << "#EXT-X-STREAM-INF:PROGRAM-ID=1,"
      playlist << "BANDWIDTH=#{options["maxrate"]},"
      playlist << "CODECS=\"#{options["codec_code"]}\","
      playlist << "RESOLUTION=#{options["resolution"]}\n"
      playlist << File.join(root_url,variant_url(format)) + "\n"
    }
    playlist
end

#hls_master_urlObject



21
22
23
# File 'app/models/concerns/hydra_hls/file_set_behavior.rb', line 21

def hls_master_url
    File.join("file_set",id,"hls.m3u8")
end

#hls_segment_playlist(root_url, format) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/models/concerns/hydra_hls/file_set_behavior.rb', line 44

def hls_segment_playlist root_url, format
  playlist = ""
  File.open(segment_playlist_path(format),'r') {|file|
    file.each_line do |line|
      if line.include? ".ts" then
        playlist << File.join(root_url,
                              segment_url_base,
                              timestamp.to_s,
                              token(line),
                              line).strip+"\n"
      else
        playlist << line.strip+"\n"
      end
    end
  }
  playlist
end