-
Notifications
You must be signed in to change notification settings - Fork 19
Zenodo video embeding #1300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
eilmiv
wants to merge
11
commits into
ElixirTeSS:master
Choose a base branch
from
pan-training:zenodo_video_embeding
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+94
−2
Open
Zenodo video embeding #1300
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
819131d
Initial implementation of embeding Zenodo videos
eilmiv 538148f
Zenodo video preview style improvements
eilmiv 5d415ff
Test zenodo video embedding
eilmiv 8ea2f80
Test zenodo video preview
eilmiv d1c97b6
Read preview_file parameter when previewing zenodo video
eilmiv 4ee1d87
Revert package.json changes
eilmiv c2db119
Revert sunspot.example.yml change
eilmiv 80887ed
Refactor zenodo.rb for slight performance improvement
eilmiv 7e90a2a
Remove unused VALID_HOSTS variable in Zenodo renderer
eilmiv 175e30f
Refactor Zenodo video embedding
eilmiv a45cd7b
Hide embedding element completely when there is no Zenodo video to embed
eilmiv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| function make_zenodo_video(video_element, files_url, preferred_key) { | ||
| const videoExtensions = ['.mp4', '.webm', '.ogg', '.ogv', '.mov', '.m4v', '.mkv']; | ||
| const audioExtensions = ['.mp3', '.ogg', '.wav', '.aac', '.flac', '.opus']; | ||
| video_element.parentElement.style.display = 'none'; | ||
|
|
||
| fetch(files_url) | ||
| .then(response => response.json()) | ||
| .then(data => { | ||
| let video_file = null; | ||
| if (preferred_key != null) { | ||
| video_file = data.entries.find(file => file.key === String(preferred_key)); | ||
| } | ||
| if (!video_file) { | ||
| video_file = data.entries.find(file => videoExtensions.some(ext => file.key.toLowerCase().endsWith(ext))); | ||
| } | ||
| if (!video_file) { // fallback to audio | ||
| video_file = data.entries.find(file => audioExtensions.some(ext => file.key.toLowerCase().endsWith(ext))); | ||
| } | ||
| if (video_file) { | ||
| const video_url = video_file.links.content; | ||
| video_element.src = video_url; | ||
| video_element.style.display = 'block'; | ||
| video_element.parentElement.style.display = 'block'; | ||
| } | ||
| }) | ||
| .catch(error => console.error('Error fetching Zenodo files:', error)); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| module Renderers | ||
| class Zenodo | ||
| VALID_SCHEMES = %w[http https].freeze | ||
| TEMPLATE = %(<video controls height="500" style="display:none;" id="zenodo-video"></video><script>make_zenodo_video(document.getElementById('zenodo-video'), '%<files_url>s', %<key>s);</script>) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be good to try and do this without using a |
||
|
|
||
| def initialize(resource) | ||
| @url = resource.url | ||
| @parsed_url = begin | ||
| Addressable::URI.parse(@url) | ||
| rescue StandardError | ||
| nil | ||
| end | ||
| end | ||
|
|
||
| def can_render? | ||
| @url && @parsed_url && zenodo_id && VALID_SCHEMES.include?(@parsed_url.scheme) | ||
| end | ||
|
|
||
| def render_content | ||
| files_url = "https://zenodo.org/api/records/#{zenodo_id}/files" | ||
| key = @parsed_url.query_values.to_h['preview_file'] | ||
| format(TEMPLATE, files_url:, key: key.to_json).html_safe | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def zenodo_id | ||
| match = @parsed_url.host == 'zenodo.org' && @url.match(%r{records/(\d+)}) || | ||
| @parsed_url.host == 'doi.org' && @url.match(%r{10\.5281/zenodo\.(\d+)}) | ||
| match[1] if match | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use camel case for JS code