Skip to content
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

Updating master w/recent changes #103

Merged
merged 37 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7aa00d1
Bump axios, @h5web/app and @h5web/h5wasm
dependabot[bot] Aug 12, 2024
7ecfeb9
Bump vite in /previewers/react-source/hdf5-previewer
dependabot[bot] Sep 17, 2024
c6705ee
Bump rollup in /previewers/react-source/hdf5-previewer
dependabot[bot] Sep 27, 2024
6ee7f2b
Update localinstall.sh
qqmyers Oct 25, 2024
ea57ad0
Add audio/mp4 example
qqmyers Nov 4, 2024
5be5244
max 100% width/height for video previewer
jo-pol Nov 12, 2024
bb6cd64
moved change to betatest
jo-pol Nov 12, 2024
d1b7de0
Merge pull request #89 from DANS-KNAW-jp/11014-video-size
qqmyers Nov 14, 2024
8dd90eb
add subtitles to video previews
jo-pol Nov 21, 2024
49e5ab7
Merge pull request #88 from gdcc/qqmyers-patch-1
qqmyers Dec 17, 2024
5cd1705
Merge pull request #81 from gdcc/dependabot/npm_and_yarn/previewers/r…
qqmyers Dec 17, 2024
df20151
Merge pull request #83 from gdcc/dependabot/npm_and_yarn/previewers/r…
qqmyers Dec 17, 2024
74feab6
Merge pull request #84 from gdcc/dependabot/npm_and_yarn/previewers/r…
qqmyers Dec 17, 2024
879e8f3
Bump axios in /previewers/react-source/hdf5-previewer
dependabot[bot] Dec 17, 2024
dcd795d
Merge pull request #92 from gdcc/dependabot/npm_and_yarn/previewers/r…
qqmyers Dec 17, 2024
18d2603
drop API-key
jo-pol Dec 19, 2024
2931f35
rogue content, fix default track
jo-pol Dec 19, 2024
83974df
fall back to first for default track
jo-pol Dec 19, 2024
74d0a3a
don't count as download
jo-pol Dec 19, 2024
6870e09
fall back in case of signed URLs
jo-pol Jan 6, 2025
a42d710
Merge pull request #91 from DANS-KNAW-jp/11041-video-subtitles
qqmyers Jan 7, 2025
1dbdf47
Bump vite and @vitejs/plugin-react
dependabot[bot] Jan 21, 2025
56d6924
Merge pull request #95 from gdcc/dependabot/npm_and_yarn/previewers/r…
qqmyers Jan 22, 2025
98ae8a5
cleanup of video css
jo-pol Feb 3, 2025
d99cbc5
Merge pull request #96 from DANS-KNAW-jp/video-css-cleanup
qqmyers Feb 3, 2025
ee4d966
show subtitles for draft datasets
jo-pol Feb 6, 2025
79b2a5d
Merge pull request #97 from DANS-KNAW-jp/11041-subtitles-draft-dataset
qqmyers Feb 6, 2025
d87abf6
Adjustments by @bjosel in the localinstall.sh to make it work complet…
BenediktMeierUIT Feb 7, 2025
1f56241
Merge branch 'develop' into 86-bug-in-localinstall.sh-leads-to-css-fi…
BenediktMeierUIT Feb 10, 2025
83acc62
sync video.js with v1.4-DANS-PATCH-1
jo-pol Feb 10, 2025
4711800
Merge pull request #100 from DANS-KNAW-jp/sync-DANS-PATCH-1
qqmyers Feb 10, 2025
06807bb
sync video.js with v1.4-DANS-PATCH-2
jo-pol Feb 11, 2025
860ea28
Update spreadsheet.js to handle quotes cells
qqmyers Feb 13, 2025
05d13bd
set delimiters
qqmyers Feb 13, 2025
59fca11
Merge pull request #102 from gdcc/qqmyers-patch-2
qqmyers Feb 13, 2025
73b5778
Merge pull request #101 from DANS-KNAW-jp/sync-dans-patch-2
qqmyers Feb 18, 2025
6c3e560
Merge pull request #98 from DataverseNO/86-bug-in-localinstall.sh-lea…
qqmyers Feb 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions 6.1curlcommands.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,47 @@ curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin
]
}'
```
```bash
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
'{
"displayName":"Play Audio",
"description":"Listen to an audio file.",
"toolName":"audioPreviewer",
"scope":"file",
"types":["preview"],
"toolUrl":"https://gdcc.github.io/dataverse-previewers/previewers/v1.4/AudioPreview.html",
"toolParameters": {
"queryParameters":[
{"fileid":"{fileId}"},
{"siteUrl":"{siteUrl}"},
{"datasetid":"{datasetId}"},
{"datasetversion":"{datasetVersion}"},
{"locale":"{localeCode}"}
]
},
"contentType":"audio/mp4",
"allowedApiCalls": [
{
"name": "retrieveFileContents",
"httpMethod": "GET",
"urlTemplate": "/api/v1/access/datafile/{fileId}?gbrecs=true",
"timeOut": 3600
},
{
"name": "downloadFile",
"httpMethod": "GET",
"urlTemplate": "/api/v1/access/datafile/{fileId}?gbrecs=false",
"timeOut": 3600
},
{
"name": "getDatasetVersionMetadata",
"httpMethod": "GET",
"urlTemplate": "/api/v1/datasets/{datasetId}/versions/{datasetVersion}",
"timeOut": 3600
}
]
}'
```

```bash
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
Expand Down
22 changes: 20 additions & 2 deletions localinstall.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,20 @@ source replace_js.sh
cat urls_js.txt

echo Downloading local copies of remote CSS files:
sed -n 's/.*<link.*href="\(http[^"]*\)".*/\1/p' *.html | sort -u | sed -n 's/^\(.*\/\)*\(.*\)/sed -i \x27s,\0\,lib\/\2,\x27 *.html/p' > replace_css.sh
sed -n 's/.*<link.*href="\(http[^"]*\)".*/\1/p' *.html | sort -u | sed -n 's/^\(.*\/\)*\(.*\)/sed -i \x27s,\0\,css\/\2,\x27 *.html/p' > replace_css.sh
sed -n 's/.*<link.*href="\(http[^"]*\)".*/\1/p' *.html | sort -u > urls_css.txt
source replace_css.sh
cat urls_css.txt


echo Downloading local copies of remote fonts:
fonturl=`grep -m 1 https://stackpath.bootstrapcdn.com/ replace_css.sh | cut -d',' -f 2 | sed s,css/bootstrap.min.css,fonts,`
echo $fonturl/glyphicons-halflings-regular.eot > urls_fonts.txt
echo $fonturl/glyphicons-halflings-regular.svg >> urls_fonts.txt
echo $fonturl/glyphicons-halflings-regular.ttf >> urls_fonts.txt
echo $fonturl/glyphicons-halflings-regular.woff >> urls_fonts.txt
echo $fonturl/glyphicons-halflings-regular.woff2 >> urls_fonts.txt

if [ ! -d ./lib ]; then
mkdir ./lib
fi
Expand All @@ -38,6 +47,14 @@ while read url; do
wget --quiet $url
done < "../urls_js.txt"

cd ".."
if [ ! -d ./fonts ]; then
mkdir ./fonts
fi
cd ./fonts
while read url; do
wget --quiet $url
done < "../urls_fonts.txt"

cd ".."
if [ ! -d ./css ]; then
Expand All @@ -63,8 +80,9 @@ fi
echo Cleaning Up...
rm urls_js.txt
rm urls_css.txt
rm urls_fonts.txt
rm replace_js.sh
rm replace_css.sh

echo Done
exit 0
exit 0
3 changes: 2 additions & 1 deletion previewers/betatest/css/preview.css
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ This has been done for the Rich Html Previewer, which also has the reverse issue
min-width: 600px;
display: table;
max-width: 100%;
max-height: 100%;
}

#logo {
Expand Down Expand Up @@ -204,4 +205,4 @@ This has been done for the Rich Html Previewer, which also has the reverse issue
max-height: 500px;
word-break: break-all;
overflow-y: auto;
}
}
6 changes: 4 additions & 2 deletions previewers/betatest/js/spreadsheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ function writeContent(fileUrl, file, title, authors) {
var csv = e.target.result;
var data = Papa.parse(csv, {
header: true,
skipEmptyLines: true
skipEmptyLines: true,
quoteChar:'"',
delimitersToGuess:['\t',',']
})

handsontableContainer.innerHTML = '';
Expand All @@ -42,4 +44,4 @@ function writeContent(fileUrl, file, title, authors) {
request.send();
}



116 changes: 115 additions & 1 deletion previewers/betatest/js/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,119 @@ function translateBaseHtmlPage() {

function writeContent(fileUrl, file, title, authors) {
addStandardPreviewHeader(file, title, authors);
$(".preview").append($("<video/>").prop("controls",true).append($('<source/>').attr("src",fileUrl)));

const queryParams = new URLSearchParams(window.location.search.substring(1));
const id = queryParams.get("datasetid");
const siteUrl = queryParams.get("siteUrl");
const apiKey = queryParams.get("key");
if (!siteUrl || !id) {
// fallback to simple video element in case of signed URLs
$(".preview").append($("<video/>") .prop("controls", true) .append($('<source/>').attr("src", fileUrl)))
return;
}
const versionUrl = `${siteUrl}/api/datasets/${id}/versions/`
+ queryParams.get("datasetversion")
+ (apiKey?`?key=${apiKey}`:'');
const videoId =queryParams.get("fileid") * 1; // converted to number
const userLanguages = [...navigator.languages];
const locale = queryParams.get("locale");
if (locale && !userLanguages.includes(locale)) {
userLanguages.unshift(locale); // add query argument as first element
}

$.ajax({
type: 'GET',
dataType: 'json',
crosssite: true,
url: versionUrl,
success: function(data, status) {
appendVideoElements(fileUrl, videoId, data.data.files, siteUrl, userLanguages, apiKey);
},
error: function(response, status, error) {
// fallback to simple video element
$(".preview").append($("<video/>") .prop("controls", true) .append($('<source/>').attr("src", fileUrl)))
}
});
}

function appendVideoElements(fileUrl, videoId, files, siteUrl, userLanguages, apiKey) {

const baseName = files // the video file name without extension
.find(item => item.dataFile.id === videoId)
.label.replace(/\.[a-z0-9]+$/i,'');

// find labels like "baseName.en.vtt", "baseName.de-CH.vtt" or "baseName.vtt"
const regex = new RegExp(`${baseName}(\\.([-a-z]+))?\\.vtt$`, 'i')

// create a map of URLs with their (optional) language
let trackUrlWithoutLang = null;
const subtitles = files
.filter(item => regex.test(item.label))
.reduce((map, item) => {
const lang = item.label.match(regex)[2];
const url = apiKey
?`${siteUrl}/api/access/datafile/${item.dataFile.id}?gbrecs=true&amp;key=${apiKey}`
:`${siteUrl}/api/access/datafile/${item.dataFile.id}?gbrecs=true`
map.set(url, lang);
if (!lang) {
trackUrlWithoutLang = url;
}
return map;
}, new Map());

// sort subtitles by language value, 'de-CH' before 'de'
const sortedSubtitles = new Map([...subtitles.entries()].sort((a, b) => {
if (!a[1]) return 1;
if (!b[1]) return -1;
if (a[1].startsWith(b[1])) return -1;
if (b[1].startsWith(a[1])) return 1;
return a[1].localeCompare(b[1]);
}));

// determine default track
let defaultTrackUrl = null;
loop: for (const lang of userLanguages) {
// match user preferences with available subtitles
for (const [url, trackLang] of sortedSubtitles) {
if (trackLang) {
if (trackLang === lang || trackLang.startsWith(lang.replace(/-.*/, ''))) {
defaultTrackUrl = url;
break loop;
}
}
}
}
if (!defaultTrackUrl && subtitles) {
// no match found, use track without language
defaultTrackUrl = trackUrlWithoutLang;
}
if (!defaultTrackUrl && subtitles.size === 1) {
// no match found, and only one track available, use that one
defaultTrackUrl = subtitles.keys().next().value;
}

const videoElement = $("<video/>")
.attr("crossorigin", "anonymous") // required for getting subtitles from object storage
.prop("controls", true)
.append($('<source/>').attr("src", fileUrl));

sortedSubtitles.forEach((trackLang, url) => {
const trackElement = $('<track/>')
.attr("kind", "subtitles")
.attr("src", url);
if (trackLang) {
trackElement
.attr("label", trackLang)
.attr("srclang", trackLang);
} else {
trackElement.attr("label", "default");
}
console.log("url: ", url, "defaultTrackUrl: ", defaultTrackUrl);
if (url === defaultTrackUrl) {
trackElement.attr("default", true);
}
videoElement.append(trackElement);
});

$(".preview").append(videoElement);
}
Loading