mirror of https://github.com/ekimekim/wubloader
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
3.4 KiB
JavaScript
114 lines
3.4 KiB
JavaScript
3 years ago
|
const TIME_FRAME_UTC = 1;
|
||
|
const TIME_FRAME_BUS = 2;
|
||
|
const TIME_FRAME_AGO = 3;
|
||
3 years ago
|
|
||
3 years ago
|
var globalLoadedVideoPlayer = false;
|
||
|
var globalVideoTimeReference = TIME_FRAME_AGO;
|
||
|
|
||
3 years ago
|
window.addEventListener("DOMContentLoaded", async (event) => {
|
||
3 years ago
|
commonPageSetup();
|
||
3 years ago
|
const timeSettingsForm = document.getElementById("stream-time-settings");
|
||
|
timeSettingsForm.addEventListener("submit", (event) => {
|
||
|
event.preventDefault();
|
||
|
updateTimeSettings();
|
||
|
});
|
||
|
await loadDefaults();
|
||
|
updateTimeSettings();
|
||
|
});
|
||
|
|
||
|
async function loadDefaults() {
|
||
|
const defaultDataResponse = await fetch("/thrimshim/defaults");
|
||
|
if (!defaultDataResponse.ok) {
|
||
3 years ago
|
addError(
|
||
|
"Failed to load Thrimbletrimmer data. This probably means that everything is broken (or, possibly, just that the Wubloader host is down). Please sound the alarm."
|
||
|
);
|
||
3 years ago
|
return;
|
||
|
}
|
||
|
const defaultData = await defaultDataResponse.json();
|
||
|
|
||
|
const streamNameField = document.getElementById("stream-time-setting-stream");
|
||
|
streamNameField.value = defaultData.video_channel;
|
||
|
|
||
|
globalBusStartTime = new Date(defaultData.bustime_start);
|
||
|
}
|
||
|
|
||
3 years ago
|
// Gets the start time of the video from settings. Returns an invalid date object if the user entered bad data.
|
||
|
function getStartTime() {
|
||
|
switch (globalVideoTimeReference) {
|
||
|
case 1:
|
||
|
return new Date(globalStartTimeString + "Z");
|
||
|
case 2:
|
||
3 years ago
|
return new Date(
|
||
|
globalBusStartTime.getTime() + 1000 * parseInputTimeAsNumberOfSeconds(globalStartTimeString)
|
||
|
);
|
||
3 years ago
|
case 3:
|
||
3 years ago
|
return new Date(
|
||
|
new Date().getTime() - 1000 * parseInputTimeAsNumberOfSeconds(globalStartTimeString)
|
||
|
);
|
||
3 years ago
|
}
|
||
|
}
|
||
|
|
||
|
// Gets the end time of the video from settings. Returns null if there's no end time. Returns an invalid date object if the user entered bad data.
|
||
|
function getEndTime() {
|
||
|
if (globalEndTimeString === "") {
|
||
|
return null;
|
||
|
}
|
||
|
switch (globalVideoTimeReference) {
|
||
|
case 1:
|
||
|
return new Date(globalEndTimeString + "Z");
|
||
|
case 2:
|
||
3 years ago
|
return new Date(
|
||
|
globalBusStartTime.getTime() + 1000 * parseInputTimeAsNumberOfSeconds(globalEndTimeString)
|
||
|
);
|
||
3 years ago
|
case 3:
|
||
3 years ago
|
return new Date(
|
||
|
new Date().getTime() - 1000 * parseInputTimeAsNumberOfSeconds(globalEndTimeString)
|
||
|
);
|
||
3 years ago
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
function updateTimeSettings() {
|
||
|
updateStoredTimeSettings();
|
||
|
if (globalLoadedVideoPlayer) {
|
||
|
updateSegmentPlaylist();
|
||
|
} else {
|
||
|
loadVideoPlayerFromDefaultPlaylist();
|
||
|
globalLoadedVideoPlayer = true;
|
||
|
}
|
||
|
|
||
|
updateDownloadLink();
|
||
|
|
||
3 years ago
|
const startTime = getStartTime();
|
||
|
const endTime = getEndTime();
|
||
|
if (endTime && endTime < startTime) {
|
||
3 years ago
|
addError(
|
||
|
"End time is before the start time. This will prevent video loading and cause other problems."
|
||
|
);
|
||
3 years ago
|
}
|
||
3 years ago
|
}
|
||
|
|
||
|
function updateSegmentPlaylist() {
|
||
3 years ago
|
const playlistURL = `/playlist/${globalStreamName}.m3u8`;
|
||
3 years ago
|
updateVideoPlayer(playlistURL);
|
||
|
}
|
||
|
|
||
|
function updateDownloadLink() {
|
||
|
const downloadLink = document.getElementById("download");
|
||
3 years ago
|
const downloadURL = generateDownloadURL(getStartTime(), getEndTime(), "rough", true, "source");
|
||
3 years ago
|
downloadLink.href = downloadURL;
|
||
3 years ago
|
}
|
||
|
|
||
|
function updateStoredTimeSettings() {
|
||
|
globalStreamName = document.getElementById("stream-time-setting-stream").value;
|
||
|
globalStartTimeString = document.getElementById("stream-time-setting-start").value;
|
||
|
globalEndTimeString = document.getElementById("stream-time-setting-end").value;
|
||
|
|
||
|
const radioSelection = document.querySelectorAll("#stream-time-frame-of-reference > input");
|
||
|
for (radioItem of radioSelection) {
|
||
|
if (radioItem.checked) {
|
||
|
globalVideoTimeReference = +radioItem.value;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
3 years ago
|
}
|