thrimbletrimmer: Add transitions to download URL

pull/414/head
Mike Lang 2 months ago committed by Mike Lang
parent 8c6141b5ca
commit ca60852b3d

@ -1315,7 +1315,7 @@ function handleLeavePage(event) {
return event.returnValue; return event.returnValue;
} }
function generateDownloadURL(timeRanges, downloadType, allowHoles, quality) { function generateDownloadURL(timeRanges, transitions, downloadType, allowHoles, quality) {
const queryParts = [`type=${downloadType}`, `allow_holes=${allowHoles}`]; const queryParts = [`type=${downloadType}`, `allow_holes=${allowHoles}`];
for (const range of timeRanges) { for (const range of timeRanges) {
let timeRangeString = ""; let timeRangeString = "";
@ -1328,6 +1328,9 @@ function generateDownloadURL(timeRanges, downloadType, allowHoles, quality) {
} }
queryParts.push(`range=${timeRangeString}`); queryParts.push(`range=${timeRangeString}`);
} }
for (const transition of transitions) {
queryParts.push(`transition=${transition}`);
}
const downloadURL = `/cut/${globalStreamName}/${quality}.ts?${queryParts.join("&")}`; const downloadURL = `/cut/${globalStreamName}/${quality}.ts?${queryParts.join("&")}`;
return downloadURL; return downloadURL;
@ -1338,7 +1341,25 @@ function updateDownloadLink() {
const allowHoles = document.getElementById("advanced-submission-option-allow-holes").checked; const allowHoles = document.getElementById("advanced-submission-option-allow-holes").checked;
const timeRanges = []; const timeRanges = [];
const transitions = [];
for (const rangeContainer of document.getElementById("range-definitions").children) { for (const rangeContainer of document.getElementById("range-definitions").children) {
// First range container has no transition.
const transitionTypeElements = rangeContainer.getElementsByClassName("range-transition-type");
if (transitionTypeElements.length > 0) {
const transitionType = transitionTypeElements[0].value;
const transitionDurationStr = rangeContainer.getElementsByClassName("range-transition-duration")[0].value;
if (transitionType === "") {
transitions.push("");
} else {
let transitionDuration = Number(transitionDurationStr);
// We don't have a sensible way to error out here, so default invalid durations to 1s
if ( !(transitionDuration > 0) ) {
transitionDuration = 1;
}
transitions.push(`${transitionType},${transitionDuration}`);
}
}
const startField = rangeContainer.getElementsByClassName("range-definition-start")[0]; const startField = rangeContainer.getElementsByClassName("range-definition-start")[0];
const endField = rangeContainer.getElementsByClassName("range-definition-end")[0]; const endField = rangeContainer.getElementsByClassName("range-definition-end")[0];
const timeRangeData = {}; const timeRangeData = {};
@ -1355,6 +1376,7 @@ function updateDownloadLink() {
const downloadURL = generateDownloadURL( const downloadURL = generateDownloadURL(
timeRanges, timeRanges,
transitions,
downloadType, downloadType,
allowHoles, allowHoles,
videoInfo.video_quality, videoInfo.video_quality,
@ -1506,6 +1528,7 @@ function rangeDefinitionDOM() {
} else { } else {
transitionDurationSection.classList.remove("hidden"); transitionDurationSection.classList.remove("hidden");
} }
updateDownloadLink();
handleFieldChange(); handleFieldChange();
}); });
const transitionDuration = makeElement("input", ["range-transition-duration"], { const transitionDuration = makeElement("input", ["range-transition-duration"], {
@ -1513,6 +1536,7 @@ function rangeDefinitionDOM() {
value: "1", value: "1",
}); });
transitionDuration.addEventListener("change", (event) => { transitionDuration.addEventListener("change", (event) => {
updateDownloadLink();
handleFieldChange(); handleFieldChange();
}); });
transitionDurationSection.append(" over ", transitionDuration, " seconds"); transitionDurationSection.append(" over ", transitionDuration, " seconds");

Loading…
Cancel
Save