Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions app/models/concerns/derivative_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ def absolute_location
derivativeFile
end

def streaming_url(is_mobile = false)
is_mobile ? hls_url : location_url
end

def download_path
Avalon::Configuration.construct_download_path.call(self)
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/concerns/derivative_intercom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def to_ingest_api_hash
{
label: "quality-#{quality}", # quality-low, quality-medium, quality-high
id: id,
url: location_url,
url: absolute_location,
hls_url: hls_url,
duration: duration,
mime_type: mime_type,
Expand All @@ -27,7 +27,7 @@ def to_ingest_api_hash
video_codec: video_codec,
width: (resolution.present? ? resolution.split('x')[0] || nil : nil),
height: (resolution.present? ? resolution.split('x')[1] || nil : nil),
location: location_url,
location: absolute_location,
track_id: track_id,
hls_track_id: hls_track_id,
managed: false,
Expand Down
13 changes: 5 additions & 8 deletions app/models/concerns/master_file_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def succeeded?
end

def stream_details
flash, hls = [], []
hls = []

common, caption_paths = nil, nil

Expand All @@ -41,13 +41,12 @@ def stream_details
bitrate: d.bitrate,
mimetype: d.mime_type,
format: d.format }
flash << common.merge(url: d.streaming_url(false))

hls_url = d.streaming_url(true)
hls_url = d.hls_url
# Quick fix for old items with mimetypes to deal with issue due to mp3 progressive download code in IIIFCanvasPresenter
common[:mimetype] = 'application/x-mpegURL' if File.extname(hls_url) == ".m3u8"

hls << common.merge(url: d.streaming_url(true))
hls << common.merge(url: d.hls_url)
end
if hls.length > 1
hls << { quality: 'auto',
Expand All @@ -57,7 +56,6 @@ def stream_details
end

# Sorts the streams in order of quality, note: Hash order only works in Ruby 1.9 or later
flash = sort_streams flash
hls = sort_streams hls

poster_path = Rails.application.routes.url_helpers.poster_master_file_path(self)
Expand All @@ -77,7 +75,6 @@ def stream_details
is_video: is_video?,
poster_image: poster_path,
embed_code: embed_code(EMBED_SIZE[:medium], {urlappend: '/embed'}),
stream_flash: flash,
stream_hls: hls,
cookie_auth: cookie_auth?,
caption_paths: caption_paths,
Expand All @@ -96,11 +93,11 @@ def hls_streams
mimetype: d.mime_type,
format: d.format }

hls_url = d.streaming_url(true)
hls_url = d.hls_url
# Quick fix for old items with mimetypes to deal with issue due to mp3 progressive download code in IIIFCanvasPresenter
common[:mimetype] = 'application/x-mpegURL' if File.extname(hls_url) == ".m3u8"

hls << common.merge(url: d.streaming_url(true))
hls << common.merge(url: d.hls_url)
end
if hls.length > 1
hls << { quality: 'auto',
Expand Down
25 changes: 5 additions & 20 deletions app/models/derivative.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ class Derivative < ActiveFedora::Base

belongs_to :master_file, class_name: 'MasterFile', predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isDerivationOf

property :location_url, predicate: Avalon::RDFVocab::EBUCore.locator, multiple: false do |index|
index.as :stored_sortable
end
property :hls_url, predicate: Avalon::RDFVocab::Derivative.hlsURL, multiple: false do |index|
index.as :stored_sortable
end
Expand Down Expand Up @@ -87,29 +84,19 @@ def hls_url
nil
end

alias_method :'_location_url', :'location_url'
def location_url
if managed
path = Addressable::URI.parse(absolute_location).path
Avalon::StreamMapper.stream_path(path)
else
_location_url
end
rescue
nil
end

def absolute_location=(value)
self.derivativeFile = value
derivativeFile
end

def to_solr
path = Addressable::URI.parse(absolute_location)&.path
stream = Avalon::StreamMapper.stream_path(path) rescue nil
super.tap do |solr_doc|
solr_doc['stream_path_ssi'] = if location_url&.start_with?("rtmp")
location_url.split(/:/).last
solr_doc['stream_path_ssi'] = if stream&.start_with?("rtmp")
stream.split(/:/).last
else
location_url
stream
end
solr_doc['format_sim'] = self.format
end
Expand All @@ -135,8 +122,6 @@ def self.from_output(output, managed = true)
derivative.mime_type ||= "audio/mpeg"
end

# FIXME: Transform to stream url here? How do we distribute to the streaming server?
derivative.location_url = output[:url]
# For Intercom push
derivative.hls_url = output[:hls_url] if output[:hls_url].present?

Expand Down
11 changes: 0 additions & 11 deletions app/presenters/speedy_af/proxy/derivative.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,4 @@ def hls_url
rescue
nil
end

def location_url
if managed
path = Addressable::URI.parse(absolute_location).path
Avalon::StreamMapper.stream_path(path)
else
@attrs[:location_url]
end
rescue
nil
end
end
2 changes: 1 addition & 1 deletion spec/controllers/derivative_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
describe DerivativesController, type: :controller do
describe 'authorize' do
let(:derivative) { FactoryBot.create(:derivative, :with_master_file) }
let(:auth_path) { derivative.location_url.split(/:/).last }
let(:auth_path) { Avalon::StreamMapper.stream_path(Addressable::URI.parse(derivative.absolute_location).path).split(/:/).last }
let(:target) { derivative.master_file.id }
let(:session) { { } }
let(:token) { StreamToken.find_or_create_session_token(session, target) }
Expand Down
3 changes: 1 addition & 2 deletions spec/controllers/media_objects_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@
expect(new_media_object.sections.first.captions.has_content?).to be_truthy
expect(new_media_object.sections.first.captions.mime_type).to eq('text/vtt')
expect(new_media_object.sections.first.derivatives.count).to eq(2)
expect(new_media_object.sections.first.derivatives.first.location_url).to eq(absolute_location)
expect(new_media_object.workflow.last_completed_step).to eq([HYDRANT_STEPS.last.step])
end
context "without files" do
Expand Down Expand Up @@ -492,7 +491,7 @@
expect(new_media_object.sections.first.captions.has_content?).to be_truthy
expect(new_media_object.sections.first.captions.mime_type).to eq(media_object.sections.first.captions.mime_type)
expect(new_media_object.sections.first.derivatives.count).to eq(media_object.sections.first.derivatives.count)
expect(new_media_object.sections.first.derivatives.first.location_url).to eq(media_object.sections.first.derivatives.first.location_url)
expect(new_media_object.sections.first.derivatives.first.hls_url).to eq(media_object.sections.first.derivatives.first.hls_url)
expect(new_media_object.workflow.last_completed_step).to eq(media_object.workflow.last_completed_step)
end
it "should return 422 if master_file update failed" do
Expand Down
1 change: 0 additions & 1 deletion spec/factories/derivatives.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
FactoryBot.define do
factory :derivative do
duration { "21575" }
location_url { nil }
track_id { "track-6" }
hls_url { nil }
hls_track_id { "track-8" }
Expand Down
30 changes: 16 additions & 14 deletions spec/models/derivative_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
id: 'track-1',
label: 'quality-high',
url: 'http://www.test.com/test.mp4.m3u8',
hls_url: 'http://www.test.com/test.mp4.m3u8',
duration: "6315",
mime_type: "video/mp4",
audio_bitrate: "127716.0",
Expand All @@ -33,9 +34,10 @@
}
end
let(:derivative) { described_class.from_output(api_output, false) }

it "Call from ingest API should populate :url and :hls_url" do
expect(derivative.location_url).to eq('http://www.test.com/test.mp4.m3u8')
expect(derivative.absolute_location).to eq('http://www.test.com/test.mp4.m3u8')
expect(derivative.hls_url).to eq('http://www.test.com/test.mp4.m3u8')
end
end

Expand Down Expand Up @@ -78,11 +80,11 @@
end

it "HTTP video" do
expect(video_derivative.streaming_url(true)).to eq("#{http_base}/c5e0f8b8-3f69-40de-9524-604f03b5f867/8c871d4b-a9a6-4841-8e2a-dd98cf2ee625/content.mp4.m3u8")
expect(video_derivative.hls_url).to eq("#{http_base}/c5e0f8b8-3f69-40de-9524-604f03b5f867/8c871d4b-a9a6-4841-8e2a-dd98cf2ee625/content.mp4.m3u8")
end

it "HTTP audio" do
expect(audio_derivative.streaming_url(true)).to eq("#{http_base}/c5e0f8b8-3f69-40de-9524-604f03b5f867/8c871d4b-a9a6-4841-8e2a-dd98cf2ee625/content.mp4.m3u8")
expect(audio_derivative.hls_url).to eq("#{http_base}/c5e0f8b8-3f69-40de-9524-604f03b5f867/8c871d4b-a9a6-4841-8e2a-dd98cf2ee625/content.mp4.m3u8")
end
end

Expand All @@ -92,11 +94,11 @@
end

it "HTTP video" do
expect(video_derivative.streaming_url(true)).to eq("#{http_base}/c5e0f8b8-3f69-40de-9524-604f03b5f867/8c871d4b-a9a6-4841-8e2a-dd98cf2ee625/content.mp4.m3u8")
expect(video_derivative.hls_url).to eq("#{http_base}/c5e0f8b8-3f69-40de-9524-604f03b5f867/8c871d4b-a9a6-4841-8e2a-dd98cf2ee625/content.mp4.m3u8")
end

it "HTTP audio" do
expect(audio_derivative.streaming_url(true)).to eq("#{http_base}/audio-only/c5e0f8b8-3f69-40de-9524-604f03b5f867/8c871d4b-a9a6-4841-8e2a-dd98cf2ee625/content.mp4.m3u8")
expect(audio_derivative.hls_url).to eq("#{http_base}/audio-only/c5e0f8b8-3f69-40de-9524-604f03b5f867/8c871d4b-a9a6-4841-8e2a-dd98cf2ee625/content.mp4.m3u8")
end
end

Expand All @@ -106,11 +108,11 @@
end

it "HTTP video" do
expect(video_derivative.streaming_url(true)).to eq("#{http_base}/mp4:c5e0f8b8-3f69-40de-9524-604f03b5f867/8c871d4b-a9a6-4841-8e2a-dd98cf2ee625/content.mp4/playlist.m3u8")
expect(video_derivative.hls_url).to eq("#{http_base}/mp4:c5e0f8b8-3f69-40de-9524-604f03b5f867/8c871d4b-a9a6-4841-8e2a-dd98cf2ee625/content.mp4/playlist.m3u8")
end

it "HTTP audio" do
expect(audio_derivative.streaming_url(true)).to eq("#{http_base}/mp4:c5e0f8b8-3f69-40de-9524-604f03b5f867/8c871d4b-a9a6-4841-8e2a-dd98cf2ee625/content.mp4/playlist.m3u8")
expect(audio_derivative.hls_url).to eq("#{http_base}/mp4:c5e0f8b8-3f69-40de-9524-604f03b5f867/8c871d4b-a9a6-4841-8e2a-dd98cf2ee625/content.mp4/playlist.m3u8")
end
end

Expand All @@ -120,24 +122,24 @@
let(:hls_url) { 'http://streaming.server/hls.m3u8' }

it "does not map stored hls_url" do
expect(video_derivative.streaming_url(true)).to eq hls_url
expect(audio_derivative.streaming_url(true)).to eq hls_url
expect(video_derivative.hls_url).to eq hls_url
expect(audio_derivative.hls_url).to eq hls_url
end
end

describe "dynamic based on config" do
it "HTTP video" do
Avalon::StreamMapper.streaming_server = :wowza
expect(video_derivative.streaming_url(true)).to eq("#{http_base}/mp4:c5e0f8b8-3f69-40de-9524-604f03b5f867/8c871d4b-a9a6-4841-8e2a-dd98cf2ee625/content.mp4/playlist.m3u8")
expect(video_derivative.hls_url).to eq("#{http_base}/mp4:c5e0f8b8-3f69-40de-9524-604f03b5f867/8c871d4b-a9a6-4841-8e2a-dd98cf2ee625/content.mp4/playlist.m3u8")
Avalon::StreamMapper.streaming_server = :generic
expect(video_derivative.streaming_url(true)).to eq("#{http_base}/c5e0f8b8-3f69-40de-9524-604f03b5f867/8c871d4b-a9a6-4841-8e2a-dd98cf2ee625/content.mp4.m3u8")
expect(video_derivative.hls_url).to eq("#{http_base}/c5e0f8b8-3f69-40de-9524-604f03b5f867/8c871d4b-a9a6-4841-8e2a-dd98cf2ee625/content.mp4.m3u8")
end

it "HTTP audio" do
Avalon::StreamMapper.streaming_server = :wowza
expect(audio_derivative.streaming_url(true)).to eq("#{http_base}/mp4:c5e0f8b8-3f69-40de-9524-604f03b5f867/8c871d4b-a9a6-4841-8e2a-dd98cf2ee625/content.mp4/playlist.m3u8")
expect(audio_derivative.hls_url).to eq("#{http_base}/mp4:c5e0f8b8-3f69-40de-9524-604f03b5f867/8c871d4b-a9a6-4841-8e2a-dd98cf2ee625/content.mp4/playlist.m3u8")
Avalon::StreamMapper.streaming_server = :generic
expect(audio_derivative.streaming_url(true)).to eq("#{http_base}/c5e0f8b8-3f69-40de-9524-604f03b5f867/8c871d4b-a9a6-4841-8e2a-dd98cf2ee625/content.mp4.m3u8")
expect(audio_derivative.hls_url).to eq("#{http_base}/c5e0f8b8-3f69-40de-9524-604f03b5f867/8c871d4b-a9a6-4841-8e2a-dd98cf2ee625/content.mp4.m3u8")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/master_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
end

describe "derivatives=" do
let(:derivative) {Derivative.create}
let(:derivative) { Derivative.create }
let(:master_file) {FactoryBot.create(:master_file)}
it "should set hasDerivation relationships on self" do
master_file.derivatives += [derivative]
Expand Down
1 change: 0 additions & 1 deletion spec/presenters/speedy_af/proxy/derivative_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
let(:derivative) { FactoryBot.create(:derivative, mime_type: 'video/mp4') }

it 'returns all attributes' do
expect(presenter.location_url).to be_present #also stored as stream_path_ssi?
expect(presenter.hls_url).to be_present
expect(presenter.duration).to be_present
expect(presenter.track_id).to be_present
Expand Down