Skip to content

Commit

Permalink
handles multi file sets
Browse files Browse the repository at this point in the history
  • Loading branch information
jwellnit committed Sep 9, 2024
1 parent a428423 commit 57f7207
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 20 deletions.
9 changes: 9 additions & 0 deletions app/helpers/audio_visual_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ def s3_url(key)
url
end

def get_original_name(presenters, derivative)
presenters.each do |presenter|
if presenter.id.to_s == derivative.split("-")[0]
return presenter.original_filenames[0]
end
end
return ""
end

def get_derivative_list(file_set)
file_set.parent.stored_derivatives.to_a
end
Expand Down
16 changes: 16 additions & 0 deletions app/services/spot/derivatives/audio_derivative_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ def create_derivatives(filename)
end
end

# Check to see if any premade derivatives exist, process them if so.
#
# @return [Boolean]
def check_premade_derivatives
premade_derivatives = file_set.parent.premade_derivatives.to_a
stored_derivatives = file_set.parent.stored_derivatives.to_a

return false if premade_derivatives.empty?
return true if !stored_derivatives.empty?

premade_derivatives.each_with_index do |derivative, index|
rename_premade_derivative(derivative, index)
end
true
end

# Check to see if any premade derivatives exist, process them if so.
#
# @param [String] derivative, the s3 key of a premade derivative
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,6 @@ def cleanup_derivatives
s3_client.delete_objects(bucket: s3_bucket, delete: delete)
end

# Check to see if any premade derivatives exist, process them if so.
#
# @return [Boolean]
def check_premade_derivatives
premade_derivatives = file_set.parent.premade_derivatives.to_a

return false if premade_derivatives.empty?

premade_derivatives.each_with_index do |derivative, index|
rename_premade_derivative(derivative, index)
end
true
end

# Placeholder for rename function in children
def rename_premade_derivative(derivative, index); end

# Placeholder for file specific paths in children
def derivative_paths; end

Expand Down Expand Up @@ -99,7 +82,7 @@ def s3_derivative_keys; end
# keys to the s3 bucket. Adds all uploaded keys to the stored_derivatives metadata field
def upload_derivatives_to_s3(keys, paths)
parent = file_set.parent
stored_derivatives = []
stored_derivatives = parent.stored_derivatives.to_a
paths.each_with_index do |path, index|
stored_derivatives.push(keys[index])
s3_client.put_object(
Expand Down
16 changes: 16 additions & 0 deletions app/services/spot/derivatives/video_derivative_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ def create_derivatives(filename)
end
end

# Check to see if any premade derivatives exist, process them if so.
#
# @return [Boolean]
def check_premade_derivatives
premade_derivatives = file_set.parent.premade_derivatives.to_a
stored_derivatives = file_set.parent.stored_derivatives.to_a

return true if !stored_derivatives.empty?
return false if premade_derivatives.empty?

premade_derivatives.each_with_index do |derivative, index|
rename_premade_derivative(derivative, index)
end
true
end

# Check to see if any premade derivatives exist, process them if so.
#
# @param [String] derivative, the s3 key of a premade derivative
Expand Down
4 changes: 2 additions & 2 deletions app/views/hyrax/file_sets/media_display/_audio.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
<th>Track <%= index+1 %></th>
<% if index == 0 %>
<% if @presenter.premade_derivatives.length == 0 %>
<td class="track-title active-track"><a class="playlist-track" href="#" data-play-track="<%= index %>"><%= @presenter.member_presenters[0].original_filenames[0] %></a></td>
<td class="track-title active-track"><a class="playlist-track" href="#" data-play-track="<%= index %>"><%= get_original_name(@presenter.member_presenters, derivative) %></a></td>
<% else %>
<td class="track-title active-track"><a class="playlist-track" href="#" data-play-track="<%= index %>"><%= @presenter.premade_derivatives[index] %></a></td>
<% end %>
<% else %>
<% if @presenter.premade_derivatives.length == 0 %>
<td class="track-title"><a class="playlist-track" href="#" data-play-track="<%= index %>"><%= @presenter.member_presenters[0].original_filenames[0] %></a></td>
<td class="track-title"><a class="playlist-track" href="#" data-play-track="<%= index %>"><%= get_original_name(@presenter.member_presenters, derivative) %></a></td>
<% else %>
<td class="track-title"><a class="playlist-track" href="#" data-play-track="<%= index %>"><%= @presenter.premade_derivatives[index] %></a></td>
<% end %>
Expand Down

0 comments on commit 57f7207

Please sign in to comment.