feat: support specifying media index in url
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Ashhhleyyy 2023-03-03 11:43:21 +00:00
parent 2efde30fc1
commit 4e417e81cc
Signed by: ash
GPG key ID: 83B789081A0878FB

View file

@ -40,6 +40,8 @@ function parseQuery() {
if (window.location.hash.length > 1) {
const qs = window.location.hash.substring(1);
const query = new URLSearchParams(qs);
if (query.has('source')) {
const source = query.get('source');
const sourceType = query.get('source_type');
const captions = query.getAll('captions');
@ -55,10 +57,14 @@ function parseQuery() {
source, sourceType,
captions, captionLanguages, captionLabels,
}
} else {
return null;
} else if (query.has('base')) {
return {
base: query.get('base'),
}
}
}
return null;
}
function parseTimestamp(timestamp) {
const results = /^(0|[1-9]+):([0-9]{2}):([0-9]{2}).([0-9]+)$/g.exec(timestamp);
@ -79,7 +85,7 @@ function formatTimestamp({ hours, mins, secs, frac }) {
const query = parseQuery();
if (query !== null) {
if (query !== null && query.source) {
const {
source, sourceType,
captions, captionLanguages, captionLabels
@ -131,9 +137,16 @@ if (query !== null) {
});
});
} else {
const BASE = '/videos/';
let base = '/videos/';
if (query !== null && query.base) {
base = query.base;
}
fetch(BASE+'media.json')
if (!base.endsWith('/')) {
base = base + '/';
}
fetch(base+'media.json')
.then(res => res.json())
.then(({ videos }) => {
const ul = document.createElement('ul');
@ -141,9 +154,9 @@ if (query !== null) {
for (const video of videos) {
//if (!video.filename.includes('telescope')) continue;
const query = [
['source', BASE+video.filename],
['source', base+video.filename],
['source_type', 'video/mp4'],
...video.subtitles.map(subName => ['captions', BASE+subName]),
...video.subtitles.map(subName => ['captions', base+subName]),
...video.subtitles.map(subName => {
const s = subName.split('.');
return ['caption_langs', s[s.length - 2]];
@ -158,7 +171,7 @@ if (query !== null) {
durationEle.classList.add('thumbnail-duration');
durationEle.innerText = formatTimestamp(duration);
const img = document.createElement('img');
img.src = BASE+thumbnail;
img.src = base+thumbnail;
img.classList.add('thumbnail');
const qs = new URLSearchParams(query).toString();
const ele = document.createElement('li');