Skip to content

Commit

Permalink
Merge pull request #2927 from avalonmediasystem/staging
Browse files Browse the repository at this point in the history
6.4.2 Release
  • Loading branch information
bkeese authored Apr 19, 2018
2 parents 61f648c + 4e03e38 commit 6d6885f
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 52 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,11 @@ migration_report
config/settings.local.yml
config/settings/*.local.yml
config/environments/*.local.yml

# Ignore the docker-compose override file
docker-compose.override.yml

# Emacs files
*~
\#*
.\#*
17 changes: 15 additions & 2 deletions app/controllers/master_files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,7 @@ def get_frame
def hls_adaptive_manifest
master_file = MasterFile.find(params[:id])
authorize! :read, master_file
stream_info = secure_streams(master_file.stream_details)
@hls_streams = stream_info[:stream_hls].reject { |stream| stream[:quality] == 'auto' }
@hls_streams = gather_hls_streams(master_file)
end

protected
Expand All @@ -285,4 +284,18 @@ def ensure_readable_filedata
end
end
end

def gather_hls_streams(master_file)
stream_info = secure_streams(master_file.stream_details)
hls_streams = stream_info[:stream_hls].reject { |stream| stream[:quality] == 'auto' }
hls_streams.each { |stream| unnest_wowza_stream(stream) } if Settings.streaming.server == "wowza"
hls_streams
end

def unnest_wowza_stream(stream)
playlist = Avalon::M3U8Reader.read(stream[:url], recursive: false).playlist
stream[:url] = playlist[:playlists][0]
bandwidth = playlist["stream_inf"].match(/BANDWIDTH=(\d*)/).try(:[], 1)
stream[:bitrate] = bandwidth if bandwidth
end
end
2 changes: 1 addition & 1 deletion app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def find_user(auth_type)
elsif auth_type == 'lti' && user_session[:virtual_groups].present?
redirect_to search_catalog_path('f[read_access_virtual_group_ssim][]' => user_session[:lti_group])
else
redirect_to root_url
redirect_to root_path
end
end

Expand Down
16 changes: 13 additions & 3 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,25 @@ def release_text
"#{application_name} #{t(:release_label)} #{Avalon::VERSION}"
end

def share_link_for(obj)
def share_link_for(obj, only_path: false)
if obj.nil?
I18n.t('media_object.empty_share_link')
elsif obj.permalink.present?
obj.permalink
else
case obj
when MediaObject then media_object_url(obj)
when MasterFileBehavior then id_section_media_object_url(obj.media_object_id, obj.id)
when MediaObject
if only_path
media_object_path(obj)
else
media_object_url(obj)
end
when MasterFileBehavior
if only_path
id_section_media_object_path(obj.media_object_id, obj.id)
else
id_section_media_object_url(obj.media_object_id, obj.id)
end
end
end
end
Expand Down
14 changes: 13 additions & 1 deletion app/helpers/media_objects_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ def structure_html section, index, show_progress
if sectionnode.children.present?
tracknumber = 0
label = "#{index+1}. #{sectionnode.attribute('label').value} #{duration}".html_safe
link = link_to label, share_link_for( section ), id: 'section-title-' + section.id, data: data, class: 'playable wrap' + (current ? ' current-stream current-section' : '')
link = link_to label, share_link_for(section, only_path: true),
id: 'section-title-' + section.id, data: data,
class: 'playable wrap' + (current ? ' current-stream current-section' : '')
wrapperopen = <<EOF
#{headeropen}
<button class="fa fa-minus-square #{current ? '' : 'hidden'}" data-toggle="collapse" data-target="#section#{index}" aria-expanded="#{current ? 'true' : 'false' }" aria-controls="collapse#{index}"></button>
Expand Down Expand Up @@ -251,4 +253,14 @@ def get_duration node, section
def get_duration_from_fragment(start, stop)
milliseconds_to_formatted_time((stop.to_i - start.to_i) * 1000)
end

# This method mirrors the one in the MediaObject model but makes use of the master files passed in which can be SpeedyAF Objects
# This would be good to refactor in the future but speeds things up considerably for now
def gather_all_comments(media_object, master_files)
media_object.comment.sort + master_files.collect do |mf|
mf.comment.reject(&:blank?).collect do |c|
mf.display_title.present? ? "[#{mf.display_title}] #{c}" : c
end.sort
end.flatten.uniq
end
end
3 changes: 3 additions & 0 deletions app/models/master_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,9 @@ def extract_frame(options={})

def get_ffmpeg_frame_data frame_source, new_width, new_height
ffmpeg = Settings.ffmpeg.path
unless File.executable?(ffmpeg)
raise RuntimeError, "FFMPEG not at configured location: #{ffmpeg}"
end
base = id.gsub(/\//,'_')
aspect = new_width/new_height
Tempfile.open([base,'.jpg']) do |jpeg|
Expand Down
2 changes: 1 addition & 1 deletion app/views/master_files/hls_adaptive_manifest.m3u8.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#EXTM3U
<% @hls_streams.each do |hls| %>
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=<%= hls[:bitrate] %>
#EXT-X-STREAM-INF:BANDWIDTH=<%= hls[:bitrate] %>
<%= hls[:url] %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/media_objects/_metadata_display.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Unless required by applicable law or agreed to in writing, software distributed
<%= display_metadata('Related Item', display_related_item(@media_object)) %>
<%= display_metadata('Notes', display_notes(@media_object)) %>
<%= display_metadata('Other Identifier', display_other_identifiers(@media_object)) %>
<%= display_metadata('Comments', @media_object.all_comments) %>
<%= display_metadata('Comments', gather_all_comments(@media_object, @masterFiles)) %>

</dl>
<% if can? :inspect, @media_object %>
Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Bundler.require(*Rails.groups)

module Avalon
VERSION = '6.4.0'
VERSION = '6.4.2'

class Application < Rails::Application
require 'avalon/configuration'
Expand Down
13 changes: 0 additions & 13 deletions config/initializers/fixnum_to_hms.rb

This file was deleted.

21 changes: 21 additions & 0 deletions config/initializers/integer_to_hms.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
int_class = if RUBY_VERSION < "2.4"
Fixnum # rubocop:disable Lint/UnifiedInteger
else
Integer
end

int_class.class_eval do
def to_hms
h = 1.hour * 1000
m = 1.minute * 1000
s = 1000.0

v = self
hour = v / h
v -= hour * h
min = v / m
v -= min * m
sec = v / s
format('%2.2d:%2.2d:%06.3f', hour, min, sec)
end
end
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ services:
- FEDORA_BASE_PATH
- FEDORA_NAMESPACE=avalon
- FEDORA_URL=http://fedoraAdmin:fedoraAdmin@fedora:8080/fedora/rest
- FFMPEG_PATH=/usr/bin/ffmpeg
- SETTINGS__FFMPEG__PATH=/usr/bin/ffmpeg
- MASTER_FILE_PATH
- MASTER_FILE_STRATEGY=delete
- MATTERHORN_URL=http://matterhorn_system_account:CHANGE_ME@matterhorn:8080/
Expand Down
4 changes: 3 additions & 1 deletion lib/avalon/batch/ingest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def process_valid_package(package: nil)
@current_package = package
end

# We have a valid batch so we can go ahead and delete the manifest file
@current_package.manifest.delete

br = register_batch unless replay?
br = register_replay if replay?
@current_batch_registry = br.reload
Expand All @@ -81,7 +84,6 @@ def process_valid_package(package: nil)
else
logger.error "Persisting BatchRegistry failed for package #{@current_package.title}"
end
@current_package.manifest.delete
end

# Register the individual rows on a spreadsheet for a valid package
Expand Down
54 changes: 27 additions & 27 deletions lib/avalon/m3u8_reader.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright 2011-2018, The Trustees of Indiana University and Northwestern
# University. Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
#
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
Expand All @@ -17,72 +17,72 @@

module Avalon
class M3U8Reader

attr_reader :playlist

def self.read(io)
def self.read(io, recursive: true)
if io.is_a?(IO)
self.new(io.read)
new(io.read, recursive: recursive)
elsif io.is_a?(String)
if io =~ /^https?:/
open(io) { |resp| self.new(resp, URI.parse(io)) }
open(io) { |resp| new(resp, URI.parse(io), recursive: recursive) }
elsif io =~ /\.m3u8?$/i
self.new(File.read(io), io)
new(File.read(io), io, recursive: recursive)
else
self.new(io)
new(io, recursive: recursive)
end
end
end

def initialize(playlist, base='')
def initialize(playlist, base = '', recursive: true)
@base = base
@playlist = { files: [] }
@playlist = { files: [], playlists: [] }
tags = {}
playlist.lines.each { |l|
playlist.lines.each do |l|
line = l.chomp
if line =~ /^#EXTM3U/
# ignore
elsif line =~ /^#EXT-X-(.+):(.+)$/
value = $2
tag = $1.downcase.gsub(/-/,"_")
value = Regexp.last_match(2)
tag = Regexp.last_match(1).downcase.tr('-', "_")
@playlist[tag] = value
elsif line =~ /^#EXTINF:(.+),(.*)$/
tags[:duration] = $1.to_f
tags[:title] = $2
elsif line =~ /\.m3u8?.*$/i
url = @base.is_a?(URI) ? @base.merge(line).to_s : File.expand_path(line,@base.to_s)
tags[:duration] = Regexp.last_match(1).to_f
tags[:title] = Regexp.last_match(2)
elsif line =~ /\.m3u8?.*$/i && recursive
url = @base.is_a?(URI) ? @base.merge(line).to_s : File.expand_path(line, @base.to_s)
@playlist.merge!(Avalon::M3U8Reader.read(url).playlist)
elsif line =~ /\.m3u8?.*$/i
url = @base.is_a?(URI) ? @base.merge(line).to_s : File.expand_path(line, @base.to_s)
@playlist[:playlists] << url
elsif line =~ /^[^#]/
tags[:filename] = line
@playlist[:files] << tags
tags = {}
end
}
end
end

def duration
files.inject(0.0) { |v,f| v + f[:duration] }
files.inject(0.0) { |v, f| v + f[:duration] }
end

def at(offset)
offset = offset.to_i
if offset < 0
raise RangeError, "Offset out of range"
end
raise RangeError, "Offset out of range" if offset < 0
elapsed = 0.0
files.each { |f|
files.each do |f|
duration = f[:duration] * 1000
if elapsed + duration > offset
location = @base.is_a?(URI) ? @base.merge(f[:filename]).to_s : File.expand_path(f[:filename],@base.to_s)
location = @base.is_a?(URI) ? @base.merge(f[:filename]).to_s : File.expand_path(f[:filename], @base.to_s)
return { location: location, filename: f[:filename], offset: offset - elapsed }
end
elapsed += duration
}
end
raise RangeError, "Offset out of range"
end

def method_missing(sym, *args)
if @playlist.has_key?(sym)
if @playlist.key?(sym)
@playlist[sym]
else
super
Expand Down
17 changes: 17 additions & 0 deletions spec/helpers/media_objects_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,21 @@
expect(helper.get_duration_from_fragment(100, 20000)).to eq "5:31:40"
end
end

describe '#gather_all_comments' do
let(:media_object) { instance_double("MediaObject", comment: ['MO Comment']) }
let(:master_files) { [instance_double("MasterFile", comment: [])] }

it 'returns a list of unique comment strings' do
expect(helper.gather_all_comments(media_object, master_files)).to eq ["MO Comment"]
end

context 'with a master file comment' do
let(:master_files) { [instance_double("MasterFile", comment: ["MF Comment"], display_title: "MF1")] }

it 'returns a list of unique comment strings' do
expect(helper.gather_all_comments(media_object, master_files)).to eq ["MO Comment", "[MF1] MF Comment"]
end
end
end
end

0 comments on commit 6d6885f

Please sign in to comment.