diff --git a/lib/avalon/batch/entry.rb b/lib/avalon/batch/entry.rb index 161d9693b3..3f07b5f925 100644 --- a/lib/avalon/batch/entry.rb +++ b/lib/avalon/batch/entry.rb @@ -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 } @@ -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 diff --git a/lib/avalon/batch/manifest.rb b/lib/avalon/batch/manifest.rb index b7ced32ce3..7e9d56b454 100644 --- a/lib/avalon/batch/manifest.rb +++ b/lib/avalon/batch/manifest.rb @@ -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 @@ -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 diff --git a/spec/lib/avalon/batch/entry_spec.rb b/spec/lib/avalon/batch/entry_spec.rb index ee67569b65..72fbe5ad6f 100644 --- a/spec/lib/avalon/batch/entry_spec.rb +++ b/spec/lib/avalon/batch/entry_spec.rb @@ -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 @@ -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 @@ -224,15 +224,15 @@ 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 @@ -240,10 +240,15 @@ 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