Skip to content

Commit

Permalink
Merge pull request #5923 from avalonmediasystem/batch_ingest_field_up…
Browse files Browse the repository at this point in the history
…dates

Add new fields to caption/transcript batch ingest
  • Loading branch information
masaball authored Jul 12, 2024
2 parents 003b260 + 54a1fb3 commit c4bcd87
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
9 changes: 5 additions & 4 deletions lib/avalon/batch/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,14 @@ def self.derivativePath(filename, quality)
filename.dup.insert(filename.rindex('.'), ".#{quality}")
end

def self.caption_language(language)
def self.content_language(language)
begin
LanguageTerm.find(language.capitalize).code
rescue LanguageTerm::LookupError
Settings.caption_default.language
end
end
private_class_method :caption_language
private_class_method :content_language

def self.process_datastream(datastream, type, parent_id)
file_key, label_key, language_key = ["_file", "_label", "_language"].map { |item| item.prepend(type).to_sym }
Expand All @@ -292,10 +292,11 @@ def self.process_datastream(datastream, type, parent_id)
# Build out file metadata
filename = datastream[file_key].split('/').last
label = datastream[label_key].presence || filename
language = datastream[language_key].present? ? caption_language(datastream[language_key]) : Settings.caption_default.language
language = datastream[language_key].present? ? content_language(datastream[language_key]) : Settings.caption_default.language
treat_as_transcript = datastream[:treat_as_transcript].present? ? 'transcript' : nil
machine_generated = datastream[:machine_generated].present? ? 'machine_generated' : nil
# Create SupplementalFile
supplemental_file = SupplementalFile.new(label: label, tags: [type, machine_generated].compact, language: language, parent_id: parent_id)
supplemental_file = SupplementalFile.new(label: label, tags: [type, treat_as_transcript, machine_generated].uniq.compact, language: language, parent_id: parent_id)
supplemental_file.file.attach(io: FileLocator.new(datastream[file_key]).reader, filename: filename)
supplemental_file.save ? supplemental_file : nil
end
Expand Down
4 changes: 2 additions & 2 deletions lib/avalon/batch/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Manifest

EXTENSIONS = ['csv','xls','xlsx','ods']
FILE_FIELDS = [:file,:label,:offset,:skip_transcoding,:absolute_location,:date_digitized, :caption_file, :caption_label, :caption_language,
:transcript_file, :transcript_label, :machine_generated]
:treat_as_transcript, :transcript_file, :transcript_label, :transcript_language, :machine_generated]
SKIP_FIELDS = [:collection]

def_delegators :@entries, :each
Expand Down Expand Up @@ -142,7 +142,7 @@ def create_entries!
unless f.blank? || SKIP_FIELDS.include?(f) || values[i].blank?
if FILE_FIELDS.include?(f)
content << {} if f == :file
if ['caption', 'transcript', 'machine_generated'].any? { |type| f.to_s.include?(type) }
if ['caption', 'transcript', 'treat_as_transcript', 'machine_generated'].any? { |type| f.to_s.include?(type) }
supplementing_files(f, content, values, i)
next
end
Expand Down
31 changes: 18 additions & 13 deletions spec/lib/avalon/batch/entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,19 @@

describe '#gatherFiles' do
it 'should return a hash of files keyed with their quality' do
expect(Avalon::Batch::Entry.gatherFiles(filename)).to hash_match derivative_hash
expect(Avalon::Batch::Entry.gatherFiles(filename)).to hash_match derivative_hash
end
end

describe '#derivativePaths' do
it 'should return the paths to all derivative files that exist' do
expect(Avalon::Batch::Entry.derivativePaths(filename)).to eq derivative_paths
expect(Avalon::Batch::Entry.derivativePaths(filename)).to eq derivative_paths
end
end

describe '#derivativePath' do
it 'should insert supplied quality into filename' do
expect(Avalon::Batch::Entry.derivativePath(filename, 'low')).to eq filename_low
expect(Avalon::Batch::Entry.derivativePath(filename, 'low')).to eq filename_low
end
end
end
Expand Down Expand Up @@ -179,8 +179,8 @@

context 'with caption and transcript files' do
let(:caption_file) { File.join(Rails.root, 'spec/fixtures/dropbox/example_batch_ingest/assets/sheephead_mountain.mov.vtt')}
let(:caption) {{ :caption_file => caption_file, :caption_label => 'Sheephead Captions', :caption_language => 'English' }}
let(:transcript) {{ :transcript_file => caption_file, :transcript_label => 'Sheephead Transcript', :machine_generated => 'yes' }}
let(:caption) {{ :caption_file => caption_file, :caption_label => 'Sheephead Captions', :caption_language => 'English', :treat_as_transcript => 'yes', :machine_generated => 'yes' }}
let(:transcript) {{ :transcript_file => caption_file, :transcript_label => 'Sheephead Transcript', :transcript_language => 'French', :machine_generated => 'yes' }}
let(:entry_files) { [{ file: File.join(testdir, filename), offset: '00:00:00.500', label: 'Quis quo', date_digitized: '2015-10-30', skip_transcoding: false, caption_1: caption, transcript_1: transcript }] }

it 'adds captions and transcripts to masterfile' do
Expand Down Expand Up @@ -224,26 +224,31 @@
end

context 'with multiple captions and transcripts' do
let(:caption) { [{ :caption_file => caption_file, :caption_label => 'Sheephead Captions', :caption_language => 'english' },
{ :caption_file => caption_file, :caption_label => 'Second Caption', :caption_language => 'fre' }] }
let(:caption) { [{ :caption_file => caption_file, :caption_label => 'Sheephead Captions', :caption_language => 'english', :treat_as_transcript => 'yes' },
{ :caption_file => caption_file, :caption_label => 'Second Caption', :caption_language => 'fre', :machine_generated => 'yes' }] }
let(:transcript) { [{ :transcript_file => caption_file, :transcript_label => 'Sheephead Transcript' },
{ :transcript_file => caption_file, :machine_generated => 'yes' }] }
{ :transcript_file => caption_file, :transcript_language => 'french', :machine_generated => 'yes' }] }
it 'should attach all captions and transcripts to master file' do
expect(master_file.has_captions?).to eq true
expect(master_file.supplemental_file_captions.count).to eq 2
expect(master_file.has_transcripts?).to eq true
expect(master_file.supplemental_file_transcripts.count).to eq 2
expect(master_file.supplemental_file_transcripts.count).to eq 3
end

it 'assigns metadata properly' do
expect(master_file.supplemental_file_captions[0].label).to eq 'Sheephead Captions'
expect(master_file.supplemental_file_captions[1].label).to eq 'Second Caption'
expect(master_file.supplemental_file_captions[0].language).to eq 'eng'
expect(master_file.supplemental_file_captions[1].language).to eq 'fre'
expect(master_file.supplemental_file_transcripts[0].label).to eq 'Sheephead Transcript'
expect(master_file.supplemental_file_transcripts[1].label).to eq 'sheephead_mountain.mov.vtt'
expect(master_file.supplemental_file_transcripts[0].tags).to_not include 'machine_generated'
expect(master_file.supplemental_file_transcripts[1].tags).to include 'machine_generated'
expect(master_file.supplemental_file_captions[0].tags).to_not include 'machine_generated'
expect(master_file.supplemental_file_captions[1].tags).to include 'machine_generated'
expect(master_file.supplemental_file_transcripts[0]).to eq master_file.supplemental_file_captions[0]
expect(master_file.supplemental_file_transcripts[1].label).to eq 'Sheephead Transcript'
expect(master_file.supplemental_file_transcripts[2].label).to eq 'sheephead_mountain.mov.vtt'
expect(master_file.supplemental_file_transcripts[1].language).to eq 'eng'
expect(master_file.supplemental_file_transcripts[2].language).to eq 'fre'
expect(master_file.supplemental_file_transcripts[1].tags).to_not include 'machine_generated'
expect(master_file.supplemental_file_transcripts[2].tags).to include 'machine_generated'
expect(master_file.supplemental_files.all? { |sf| sf.parent_id == master_file.id }).to be true
end
end
Expand Down

0 comments on commit c4bcd87

Please sign in to comment.