Skip to content

Commit

Permalink
Merge pull request #5448 from avalonmediasystem/encode_titles
Browse files Browse the repository at this point in the history
Shorten title for encodes using s3 urls
  • Loading branch information
cjcolvar authored Nov 3, 2023
2 parents 1032b41 + 5011981 commit 212b0f1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
13 changes: 11 additions & 2 deletions app/models/watched_encode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class WatchedEncode < ActiveEncode::Base
end

def persistence_model_attributes(encode, create_options = nil)
display_title = encode.input.url.to_s.split('/').last
options_hash = { display_title: display_title }
display_title = parse_filename(encode.input.url)
options_hash = { title: display_title, display_title: display_title }
if create_options.present? && create_options[:master_file_id].present?
master_file = MasterFile.find(create_options[:master_file_id])
options_hash[:master_file_id] = create_options[:master_file_id]
Expand All @@ -75,4 +75,13 @@ def persistence_model_attributes(encode, create_options = nil)
def localize_s3_file(url)
FileLocator.new(url).local_location
end

def parse_filename(url)
escaped_url = Addressable::URI.escape(url)
uri = URI.parse(escaped_url)
escaped_filename = uri.path.split('/').last
Addressable::URI.unescape(escaped_filename)
rescue URI::InvalidURIError
url
end
end
33 changes: 32 additions & 1 deletion spec/models/watched_encode_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,18 @@
encode.create!
expect(master_file.reload.workflow_id).to eq encode.id.to_s
end

it 'creates an encode record' do
encode.create!
encode_record = ActiveEncode::EncodeRecord.last
expect(encode_record.title).to eq 'sample.mp4'
expect(encode_record.display_title).to eq 'sample.mp4'
end
end

describe 'polling update' do
around(:example) do |example|
# In Rails 5.1+ this can be restricted to whitelist jobs allowed to be performed
# In Rails 5.1+ this can be restricted to allow listed jobs to be performed
perform_enqueued_jobs { example.run }
end

Expand All @@ -73,6 +80,9 @@
end

context 'using Minio and ffmpeg adapter' do
let(:encode) { described_class.new(minio_url, master_file_id: master_file.id) }
let(:minio_url) { "http://minio:9000/masterfiles/uploads/c0b216da-bb53-4afd-8d4c-c4761a78e230/#{fixture_file}?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minio%2F20231101%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20231101T202236Z&X-Amz-Expires=900&X-Amz-SignedHeaders=host&X-Amz-Signature=982ffe02232c053ee38f470f4ec4844c3302ceb35afd4f3f8564731c51b5a044" }

before do
Settings.minio = double("minio", endpoint: "http://minio:9000", public_host: "http://domain:9000")
allow(Settings).to receive(:encoding).and_return(double(engine_adapter: "ffmpeg", derivative_bucket: "derivs"))
Expand All @@ -84,6 +94,13 @@
expect(master_file).to have_received(:update_progress_on_success!)
end

it 'creates an encode record' do
encode.create!
encode_record = ActiveEncode::EncodeRecord.last
expect(encode_record.title).to eq fixture_file
expect(encode_record.display_title).to eq fixture_file
end

after do
Settings.minio = nil
end
Expand All @@ -95,6 +112,13 @@
encode.create!
expect(master_file).to have_received(:update_progress_on_success!)
end

it 'creates an encode record' do
encode.create!
encode_record = ActiveEncode::EncodeRecord.last
expect(encode_record.title).to eq fixture_file
expect(encode_record.display_title).to eq fixture_file
end
end

context 'with filename with escaped spaces' do
Expand All @@ -104,6 +128,13 @@
encode.create!
expect(master_file).to have_received(:update_progress_on_success!)
end

it 'creates an encode record' do
encode.create!
encode_record = ActiveEncode::EncodeRecord.last
expect(encode_record.title).to eq fixture_file
expect(encode_record.display_title).to eq fixture_file
end
end
end
end
Expand Down

0 comments on commit 212b0f1

Please sign in to comment.