|
|
@ -1,7 +1,6 @@
|
|
|
|
var googleUser = null;
|
|
|
|
var googleUser = null;
|
|
|
|
var videoInfo;
|
|
|
|
var videoInfo;
|
|
|
|
var currentRange = 1;
|
|
|
|
var currentRange = 1;
|
|
|
|
var globalLoadedRangeData = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener("DOMContentLoaded", async (event) => {
|
|
|
|
window.addEventListener("DOMContentLoaded", async (event) => {
|
|
|
|
commonPageSetup();
|
|
|
|
commonPageSetup();
|
|
|
@ -35,12 +34,12 @@ window.addEventListener("DOMContentLoaded", async (event) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const oldStart = getStartTime();
|
|
|
|
const oldStart = getStartTime();
|
|
|
|
const startAdjustment = newStart.diff(oldStart, "seconds").seconds;
|
|
|
|
const startAdjustment = newStart.diff(oldStart).as("seconds");
|
|
|
|
let newDuration = newEnd === null ? Infinity : newEnd.diff(newStart, "seconds").seconds;
|
|
|
|
let newDuration = newEnd === null ? Infinity : newEnd.diff(newStart).as("seconds");
|
|
|
|
|
|
|
|
|
|
|
|
// The video duration isn't precisely the video times, but can be padded by up to the
|
|
|
|
// The video duration isn't precisely the video times, but can be padded by up to the
|
|
|
|
// segment length on either side.
|
|
|
|
// segment length on either side.
|
|
|
|
const segmentList = getPlaylistData().segments;
|
|
|
|
const segmentList = getSegmentList();
|
|
|
|
newDuration += segmentList[0].duration;
|
|
|
|
newDuration += segmentList[0].duration;
|
|
|
|
newDuration += segmentList[segmentList.length - 1].duration;
|
|
|
|
newDuration += segmentList[segmentList.length - 1].duration;
|
|
|
|
|
|
|
|
|
|
|
@ -376,54 +375,51 @@ async function initializeVideoInfo() {
|
|
|
|
|
|
|
|
|
|
|
|
await loadVideoPlayerFromDefaultPlaylist();
|
|
|
|
await loadVideoPlayerFromDefaultPlaylist();
|
|
|
|
|
|
|
|
|
|
|
|
const player = getVideoJS();
|
|
|
|
const videoElement = document.getElementById("video");
|
|
|
|
player.on("loadedmetadata", () => {
|
|
|
|
const handleInitialSetupForDuration = (_event) => {
|
|
|
|
if (!globalLoadedRangeData) {
|
|
|
|
const rangeDefinitionsContainer = document.getElementById("range-definitions");
|
|
|
|
const rangeDefinitionsContainer = document.getElementById("range-definitions");
|
|
|
|
if (videoInfo.video_ranges && videoInfo.video_ranges.length > 0) {
|
|
|
|
if (videoInfo.video_ranges && videoInfo.video_ranges.length > 0) {
|
|
|
|
for (let rangeIndex = 0; rangeIndex < videoInfo.video_ranges.length; rangeIndex++) {
|
|
|
|
for (let rangeIndex = 0; rangeIndex < videoInfo.video_ranges.length; rangeIndex++) {
|
|
|
|
if (rangeIndex >= rangeDefinitionsContainer.children.length) {
|
|
|
|
if (rangeIndex >= rangeDefinitionsContainer.children.length) {
|
|
|
|
addRangeDefinition();
|
|
|
|
addRangeDefinition();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const startWubloaderTime = videoInfo.video_ranges[rangeIndex][0];
|
|
|
|
|
|
|
|
const endWubloaderTime = videoInfo.video_ranges[rangeIndex][1];
|
|
|
|
|
|
|
|
if (startWubloaderTime) {
|
|
|
|
|
|
|
|
const startField =
|
|
|
|
|
|
|
|
rangeDefinitionsContainer.children[rangeIndex].getElementsByClassName(
|
|
|
|
|
|
|
|
"range-definition-start"
|
|
|
|
|
|
|
|
)[0];
|
|
|
|
|
|
|
|
startField.value = videoHumanTimeFromWubloaderTime(startWubloaderTime);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (endWubloaderTime) {
|
|
|
|
|
|
|
|
const endField =
|
|
|
|
|
|
|
|
rangeDefinitionsContainer.children[rangeIndex].getElementsByClassName(
|
|
|
|
|
|
|
|
"range-definition-end"
|
|
|
|
|
|
|
|
)[0];
|
|
|
|
|
|
|
|
endField.value = videoHumanTimeFromWubloaderTime(endWubloaderTime);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const startWubloaderTime = videoInfo.video_ranges[rangeIndex][0];
|
|
|
|
const rangeStartField =
|
|
|
|
const endWubloaderTime = videoInfo.video_ranges[rangeIndex][1];
|
|
|
|
rangeDefinitionsContainer.getElementsByClassName("range-definition-start")[0];
|
|
|
|
if (startWubloaderTime) {
|
|
|
|
rangeStartField.value = videoHumanTimeFromWubloaderTime(globalStartTimeString);
|
|
|
|
const startField =
|
|
|
|
if (globalEndTimeString) {
|
|
|
|
rangeDefinitionsContainer.children[rangeIndex].getElementsByClassName(
|
|
|
|
const rangeEndField =
|
|
|
|
"range-definition-start"
|
|
|
|
rangeDefinitionsContainer.getElementsByClassName("range-definition-end")[0];
|
|
|
|
)[0];
|
|
|
|
rangeEndField.value = videoHumanTimeFromWubloaderTime(globalEndTimeString);
|
|
|
|
startField.value = videoHumanTimeFromWubloaderTime(startWubloaderTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (endWubloaderTime) {
|
|
|
|
|
|
|
|
const endField =
|
|
|
|
|
|
|
|
rangeDefinitionsContainer.children[rangeIndex].getElementsByClassName(
|
|
|
|
|
|
|
|
"range-definition-end"
|
|
|
|
|
|
|
|
)[0];
|
|
|
|
|
|
|
|
endField.value = videoHumanTimeFromWubloaderTime(endWubloaderTime);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
const rangeStartField =
|
|
|
|
|
|
|
|
rangeDefinitionsContainer.getElementsByClassName("range-definition-start")[0];
|
|
|
|
|
|
|
|
rangeStartField.value = videoHumanTimeFromWubloaderTime(globalStartTimeString);
|
|
|
|
|
|
|
|
if (globalEndTimeString) {
|
|
|
|
|
|
|
|
const rangeEndField =
|
|
|
|
|
|
|
|
rangeDefinitionsContainer.getElementsByClassName("range-definition-end")[0];
|
|
|
|
|
|
|
|
rangeEndField.value = videoHumanTimeFromWubloaderTime(globalEndTimeString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
globalLoadedRangeData = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Although we may or may not have updated the range data here, this is where we know the new video duration.
|
|
|
|
videoElement.removeEventListener("durationchange", handleInitialSetupForDuration);
|
|
|
|
// Because of this, we need to run this to properly update range-dependent things like the clip bar UI,
|
|
|
|
};
|
|
|
|
// which require a location.
|
|
|
|
videoElement.addEventListener("durationchange", handleInitialSetupForDuration);
|
|
|
|
|
|
|
|
videoElement.addEventListener("durationchange", (_event) => {
|
|
|
|
|
|
|
|
// Every time this is updated, we need to update based on the new video duration
|
|
|
|
rangeDataUpdated();
|
|
|
|
rangeDataUpdated();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
player.on("timeupdate", () => {
|
|
|
|
|
|
|
|
const player = getVideoJS();
|
|
|
|
videoElement.addEventListener("timeupdate", (_event) => {
|
|
|
|
const currentTime = player.currentTime();
|
|
|
|
const timePercent = (videoElement.currentTime / videoElement.duration) * 100;
|
|
|
|
const duration = player.duration();
|
|
|
|
|
|
|
|
const timePercent = (currentTime / duration) * 100;
|
|
|
|
|
|
|
|
document.getElementById("waveform-marker").style.left = `${timePercent}%`;
|
|
|
|
document.getElementById("waveform-marker").style.left = `${timePercent}%`;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -880,8 +876,8 @@ function getRangeSetClickHandler(startOrEnd) {
|
|
|
|
`range-definition-${startOrEnd}`
|
|
|
|
`range-definition-${startOrEnd}`
|
|
|
|
)[0];
|
|
|
|
)[0];
|
|
|
|
|
|
|
|
|
|
|
|
const player = getVideoJS();
|
|
|
|
const videoElement = document.getElementById("video");
|
|
|
|
const videoPlayerTime = player.currentTime();
|
|
|
|
const videoPlayerTime = videoElement.currentTime;
|
|
|
|
|
|
|
|
|
|
|
|
setField.value = videoHumanTimeFromVideoPlayerTime(videoPlayerTime);
|
|
|
|
setField.value = videoHumanTimeFromVideoPlayerTime(videoPlayerTime);
|
|
|
|
rangeDataUpdated();
|
|
|
|
rangeDataUpdated();
|
|
|
@ -923,8 +919,8 @@ function rangePlayFromStartHandler(event) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const player = getVideoJS();
|
|
|
|
const videoElement = document.getElementById("video");
|
|
|
|
player.currentTime(startTime);
|
|
|
|
videoElement.currentTime = startTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function rangePlayFromEndHandler(event) {
|
|
|
|
function rangePlayFromEndHandler(event) {
|
|
|
@ -936,16 +932,16 @@ function rangePlayFromEndHandler(event) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const player = getVideoJS();
|
|
|
|
const videoElement = document.getElementById("video");
|
|
|
|
player.currentTime(endTime);
|
|
|
|
videoElement.currentTime = endTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function rangeDataUpdated() {
|
|
|
|
function rangeDataUpdated() {
|
|
|
|
const clipBar = document.getElementById("clip-bar");
|
|
|
|
const clipBar = document.getElementById("clip-bar");
|
|
|
|
clipBar.innerHTML = "";
|
|
|
|
clipBar.innerHTML = "";
|
|
|
|
|
|
|
|
|
|
|
|
const player = getVideoJS();
|
|
|
|
const videoElement = document.getElementById("video");
|
|
|
|
const videoDuration = player.duration();
|
|
|
|
const videoDuration = videoElement.duration;
|
|
|
|
|
|
|
|
|
|
|
|
for (let rangeDefinition of document.getElementById("range-definitions").children) {
|
|
|
|
for (let rangeDefinition of document.getElementById("range-definitions").children) {
|
|
|
|
const rangeStartField = rangeDefinition.getElementsByClassName("range-definition-start")[0];
|
|
|
|
const rangeStartField = rangeDefinition.getElementsByClassName("range-definition-start")[0];
|
|
|
@ -973,8 +969,8 @@ function setCurrentRangeStartToVideoTime() {
|
|
|
|
const rangeStartField = document.querySelector(
|
|
|
|
const rangeStartField = document.querySelector(
|
|
|
|
`#range-definitions > div:nth-child(${currentRange}) .range-definition-start`
|
|
|
|
`#range-definitions > div:nth-child(${currentRange}) .range-definition-start`
|
|
|
|
);
|
|
|
|
);
|
|
|
|
const player = getVideoJS();
|
|
|
|
const videoElement = document.getElementById("video");
|
|
|
|
rangeStartField.value = videoHumanTimeFromVideoPlayerTime(player.currentTime());
|
|
|
|
rangeStartField.value = videoHumanTimeFromVideoPlayerTime(videoElement.currentTime);
|
|
|
|
rangeDataUpdated();
|
|
|
|
rangeDataUpdated();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -982,65 +978,40 @@ function setCurrentRangeEndToVideoTime() {
|
|
|
|
const rangeEndField = document.querySelector(
|
|
|
|
const rangeEndField = document.querySelector(
|
|
|
|
`#range-definitions > div:nth-child(${currentRange}) .range-definition-end`
|
|
|
|
`#range-definitions > div:nth-child(${currentRange}) .range-definition-end`
|
|
|
|
);
|
|
|
|
);
|
|
|
|
const player = getVideoJS();
|
|
|
|
const videoElement = document.getElementById("video");
|
|
|
|
rangeEndField.value = videoHumanTimeFromVideoPlayerTime(player.currentTime());
|
|
|
|
rangeEndField.value = videoHumanTimeFromVideoPlayerTime(videoElement.currentTime);
|
|
|
|
rangeDataUpdated();
|
|
|
|
rangeDataUpdated();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function videoPlayerTimeFromWubloaderTime(wubloaderTime) {
|
|
|
|
function videoPlayerTimeFromWubloaderTime(wubloaderTime) {
|
|
|
|
const videoPlaylist = getPlaylistData();
|
|
|
|
|
|
|
|
const wubloaderDateTime = dateTimeFromWubloaderTime(wubloaderTime);
|
|
|
|
const wubloaderDateTime = dateTimeFromWubloaderTime(wubloaderTime);
|
|
|
|
let highestDiscontinuitySegmentBefore = 0;
|
|
|
|
const segmentList = getSegmentList();
|
|
|
|
for (start of videoPlaylist.discontinuityStarts) {
|
|
|
|
for (const segment of segmentList) {
|
|
|
|
const discontinuityStartSegment = videoPlaylist.segments[start];
|
|
|
|
const segmentStart = DateTime.fromISO(segment.rawProgramDateTime, { zone: "utc" });
|
|
|
|
const discontinuityStartDateTime = DateTime.fromJSDate(
|
|
|
|
const segmentEnd = segmentStart.plus({ seconds: segment.duration });
|
|
|
|
discontinuityStartSegment.dateTimeObject,
|
|
|
|
if (segmentStart <= wubloaderDateTime && segmentEnd > wubloaderDateTime) {
|
|
|
|
{ zone: "utc" }
|
|
|
|
return segment.start + wubloaderDateTime.diff(segmentStart).as("seconds");
|
|
|
|
);
|
|
|
|
|
|
|
|
const highestDiscontinuitySegmentDateTime = DateTime.fromJSDate(
|
|
|
|
|
|
|
|
videoPlaylist.segments[highestDiscontinuitySegmentBefore].dateTimeObject,
|
|
|
|
|
|
|
|
{ zone: "utc" }
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
discontinuityStartDateTime.diff(wubloaderDateTime).milliseconds < 0 && // Discontinuity starts before the provided time
|
|
|
|
|
|
|
|
discontinuityStartDateTime.diff(highestDiscontinuitySegmentDateTime).milliseconds > 0 // Discontinuity starts after the latest found discontinuity
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
highestDiscontinuitySegmentBefore = start;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
let highestDiscontinuitySegmentStart = 0;
|
|
|
|
|
|
|
|
for (let segment = 0; segment < highestDiscontinuitySegmentBefore; segment++) {
|
|
|
|
|
|
|
|
highestDiscontinuitySegmentStart += videoPlaylist.segments[segment].duration;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const highestDiscontinuitySegmentDateTime = DateTime.fromJSDate(
|
|
|
|
|
|
|
|
videoPlaylist.segments[highestDiscontinuitySegmentBefore].dateTimeObject,
|
|
|
|
|
|
|
|
{ zone: "utc" }
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
|
|
highestDiscontinuitySegmentStart +
|
|
|
|
|
|
|
|
wubloaderDateTime.diff(highestDiscontinuitySegmentDateTime, "seconds").seconds
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function dateTimeFromVideoPlayerTime(videoPlayerTime) {
|
|
|
|
function dateTimeFromVideoPlayerTime(videoPlayerTime) {
|
|
|
|
const videoPlaylist = getPlaylistData();
|
|
|
|
const segmentList = getSegmentList();
|
|
|
|
let segmentStartTime = 0;
|
|
|
|
let segmentStartTime;
|
|
|
|
let segmentDateObj;
|
|
|
|
let segmentStartISOTime;
|
|
|
|
// Segments have start and end video player times on them, but only if the segments are already loaded.
|
|
|
|
for (const segment of segmentList) {
|
|
|
|
// This is not the case before the video is loaded for the first time, or outside the video's buffer if it hasn't played that far/part.
|
|
|
|
const segmentEndTime = segment.start + segment.duration;
|
|
|
|
for (segment of videoPlaylist.segments) {
|
|
|
|
if (videoPlayerTime >= segment.start && videoPlayerTime < segmentEndTime) {
|
|
|
|
const segmentEndTime = segmentStartTime + segment.duration;
|
|
|
|
segmentStartTime = segment.start;
|
|
|
|
if (segmentStartTime <= videoPlayerTime && segmentEndTime >= videoPlayerTime) {
|
|
|
|
segmentStartISOTime = segment.rawProgramDateTime;
|
|
|
|
segmentDateObj = segment.dateTimeObject;
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
segmentStartTime = segmentEndTime;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (segmentDateObj === undefined) {
|
|
|
|
if (segmentStartISOTime === undefined) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let wubloaderDateTime = DateTime.fromJSDate(segmentDateObj, { zone: "utc" });
|
|
|
|
const wubloaderDateTime = DateTime.fromISO(segmentStartISOTime, { zone: "utc" });
|
|
|
|
const offset = videoPlayerTime - segmentStartTime;
|
|
|
|
const offset = videoPlayerTime - segmentStartTime;
|
|
|
|
return wubloaderDateTime.plus({ seconds: offset });
|
|
|
|
return wubloaderDateTime.plus({ seconds: offset });
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1097,10 +1068,6 @@ function wubloaderTimeFromVideoHumanTime(videoHumanTime) {
|
|
|
|
return wubloaderTimeFromVideoPlayerTime(videoPlayerTime);
|
|
|
|
return wubloaderTimeFromVideoPlayerTime(videoPlayerTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getPlaylistData() {
|
|
|
|
function getSegmentList() {
|
|
|
|
const player = getVideoJS();
|
|
|
|
return globalPlayer.latencyController.levelDetails.fragments;
|
|
|
|
// Currently, this only supports a single playlist. We only give one playlist (or master playlist file) to VideoJS,
|
|
|
|
|
|
|
|
// so this should be fine for now. If we need to support multiple playlists in the future (varying quality levels,
|
|
|
|
|
|
|
|
// etc.), this and all callers will need to be updated.
|
|
|
|
|
|
|
|
return player.tech("OK").vhs.playlists.master.playlists[0];
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|