Skip to content

Commit

Permalink
Use relative urls in hls playlists
Browse files Browse the repository at this point in the history
Ensure that smil playlists still include absolute URLs since these are
needed to have Akamai generate HLS playlists on the fly.
  • Loading branch information
tf committed Aug 16, 2017
1 parent 6fb73d6 commit 11a2a0a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
10 changes: 5 additions & 5 deletions lib/pageflow/zencoder_video_output_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,17 +350,17 @@ def hls_stream_definitions
[
{
source: 'hls-medium',
path: video_file.hls_medium.url(host: :hls_origin, default_protocol: 'http'),
path: video_file.hls_medium.url_relative_to(video_file.hls_playlist),
bandwidth: 1769
},
{
source: 'hls-low',
path: video_file.hls_low.url(host: :hls_origin, default_protocol: 'http'),
path: video_file.hls_low.url_relative_to(video_file.hls_playlist),
bandwidth: 619
},
{
source: 'hls-high',
path: video_file.hls_high.url(host: :hls_origin, default_protocol: 'http'),
path: video_file.hls_high.url_relative_to(video_file.hls_playlist),
bandwidth: 3538
}
] + hls_highdef_stream_definitions
Expand All @@ -371,12 +371,12 @@ def hls_highdef_stream_definitions
[
{
source: 'hls-fullhd',
path: video_file.hls_fullhd.url(host: :hls_origin, default_protocol: 'http'),
path: video_file.hls_fullhd.url_relative_to(video_file.hls_playlist),
bandwidth: 8575
},
{
source: 'hls-4k',
path: video_file.hls_4k.url(host: :hls_origin, default_protocol: 'http'),
path: video_file.hls_4k.url_relative_to(video_file.hls_playlist),
bandwidth: 32000
}
]
Expand Down
21 changes: 20 additions & 1 deletion spec/pageflow/zencoder_video_output_definition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,32 @@ module Pageflow
end

it 'uses relative urls in dash playlist' do
video_file = build(:video_file, :with_highdef_encoding)
video_file = build_stubbed(:video_file, :with_highdef_encoding)
definition = ZencoderVideoOutputDefinition.new(video_file)

expect(definition).to have_output
.with_label('dash-playlist')
.with_all_streams_having(path: a_relative_url)
end

it 'uses relative urls in hls playlist' do
video_file = build_stubbed(:video_file, :with_highdef_encoding)
definition = ZencoderVideoOutputDefinition.new(video_file)

expect(definition).to have_output
.with_label('hls-playlist')
.with_all_streams_having(path: a_relative_url)
end

it 'uses absolute urls in smil playlist' do
video_file = build_stubbed(:video_file, :with_highdef_encoding)
definition = ZencoderVideoOutputDefinition.new(video_file)
definition.skip_smil = false

expect(definition).to have_output
.with_format('highwinds')
.with_all_streams_having(path: an_absolute_url)
end
end
end
end
4 changes: 4 additions & 0 deletions spec/support/matchers/have_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
output_matchers[:label] = label
end

chain :with_format do |format|
output_matchers[:format] = format
end

chain :with_stream do |stream_attributes|
output_matchers[:streams] = array_including(hash_including(stream_attributes))
end
Expand Down
13 changes: 13 additions & 0 deletions spec/support/matchers/url_matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,16 @@
end

RSpec::Matchers.alias_matcher :a_relative_url, :be_relative_url

RSpec::Matchers.define :be_absolute_url do
match do |url|
begin
uri = URI.parse(url)
uri.host.present? && uri.scheme.present?
rescue URI::InvalidURIError
false
end
end
end

RSpec::Matchers.alias_matcher :an_absolute_url, :be_absolute_url

0 comments on commit 11a2a0a

Please sign in to comment.