2020-12-29 06:33:37 +01:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
let downloadFormButton;
|
2020-12-29 10:38:25 +01:00
|
|
|
let modalVideoContainer;
|
2020-12-29 06:33:37 +01:00
|
|
|
let closeAndResetVideoContainer;
|
|
|
|
let downloadFormUrl;
|
|
|
|
let downloadVideo;
|
2020-12-30 05:30:51 +01:00
|
|
|
let downloadVideoPrepare;
|
|
|
|
let downloadVideoLoading;
|
2020-12-29 06:33:37 +01:00
|
|
|
let downloadForm;
|
|
|
|
let video;
|
2020-12-30 05:30:51 +01:00
|
|
|
let modalLoading;
|
|
|
|
let filename;
|
|
|
|
let url;
|
2020-12-30 20:18:42 +01:00
|
|
|
let popingNotice;
|
|
|
|
let closePopingNotice;
|
2020-12-29 06:33:37 +01:00
|
|
|
|
|
|
|
function downloadFormButtonHandler(event) {
|
|
|
|
event.preventDefault();
|
2020-12-30 05:30:51 +01:00
|
|
|
modalLoading.classList.add('active');
|
2020-12-29 06:33:37 +01:00
|
|
|
getRealURL(downloadFormUrl.value).then( (response) => {
|
|
|
|
video.src = response.url;
|
2020-12-30 05:30:51 +01:00
|
|
|
filename = response.filename;
|
|
|
|
url = response.url;
|
2020-12-30 20:18:42 +01:00
|
|
|
video.addEventListener('canplay', (event) => {
|
|
|
|
modalLoading.classList.remove('active');
|
|
|
|
modalVideoContainer.style.display = 'block';
|
|
|
|
});
|
2020-12-30 05:30:51 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function downloadVideoPrepareHandler(event) {
|
|
|
|
downloadVideoPrepare.classList.remove('active');
|
|
|
|
downloadVideoLoading.classList.add('active');
|
|
|
|
generateBlobVideo(url).then( blob => {
|
|
|
|
downloadVideo.href = URL.createObjectURL(blob);
|
|
|
|
downloadVideo.download = filename;
|
|
|
|
downloadVideoLoading.classList.remove('active');
|
|
|
|
downloadVideo.classList.add('active');
|
2020-12-29 06:33:37 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function downloadFormHandler(event) {
|
|
|
|
downloadFormButtonHandler(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function generateBlobVideo(url) {
|
|
|
|
const blob = await fetch(url, {
|
|
|
|
mode: 'cors',
|
|
|
|
})
|
|
|
|
.then(res => res.blob())
|
|
|
|
.catch( err => generateBlobVideoByProxy(url) );
|
|
|
|
return blob;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function generateBlobVideoByProxy(url) {
|
|
|
|
const blob = await fetch( '/proxy_to_get', {
|
|
|
|
method: 'POST',
|
|
|
|
mode: 'cors',
|
|
|
|
cache: 'no-cache',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
|
|
|
body: JSON.stringify({url: url}),
|
|
|
|
}
|
|
|
|
).then(res => res.blob());
|
|
|
|
return blob;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getRealURL(url) {
|
|
|
|
const response = await fetch('/api', {
|
|
|
|
method: 'POST',
|
|
|
|
mode: 'cors',
|
|
|
|
cache: 'no-cache',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
body: JSON.stringify({url: url}),
|
|
|
|
});
|
|
|
|
return response.json();
|
|
|
|
}
|
|
|
|
|
|
|
|
function closeAndResetVideoContainerHandler(event) {
|
|
|
|
event.preventDefault();
|
2020-12-29 10:38:25 +01:00
|
|
|
modalVideoContainer.style.display = 'none';
|
2020-12-30 05:30:51 +01:00
|
|
|
downloadVideo.classList.remove('active');
|
|
|
|
downloadVideoLoading.classList.remove('active');
|
|
|
|
downloadVideoPrepare.classList.add('active');
|
2020-12-29 06:33:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener('load', (event) => {
|
|
|
|
downloadFormButton = document.querySelector('#download-form-button');
|
|
|
|
downloadForm = document.querySelector('#download-form');
|
2020-12-29 10:38:25 +01:00
|
|
|
modalVideoContainer = document.querySelector('#modal-video-container');
|
2020-12-29 06:33:37 +01:00
|
|
|
video = document.querySelector('#video');
|
|
|
|
downloadFormUrl = document.querySelector('#download-form-url');
|
|
|
|
downloadVideo = document.querySelector('#download-video');
|
2020-12-30 05:30:51 +01:00
|
|
|
downloadVideoLoading = document.querySelector('#download-video-loading');
|
|
|
|
downloadVideoPrepare = document.querySelector('#download-video-prepare');
|
2020-12-29 06:33:37 +01:00
|
|
|
closeAndResetVideoContainer = document.querySelector('#close-and-reset-video-container');
|
2020-12-30 05:30:51 +01:00
|
|
|
modalLoading = document.querySelector('#modal-loading');
|
2020-12-30 20:18:42 +01:00
|
|
|
popingNotice = document.querySelector('#poping-notice');
|
|
|
|
closePopingNotice = document.querySelector('#close-poping-notice');
|
2020-12-30 05:30:51 +01:00
|
|
|
|
2020-12-29 06:33:37 +01:00
|
|
|
downloadFormButton.addEventListener('click', downloadFormButtonHandler);
|
2020-12-30 05:30:51 +01:00
|
|
|
downloadVideoPrepare.addEventListener('click', downloadVideoPrepareHandler);
|
2020-12-29 06:33:37 +01:00
|
|
|
downloadForm.addEventListener('submit', downloadFormHandler);
|
|
|
|
closeAndResetVideoContainer.addEventListener('click', closeAndResetVideoContainerHandler);
|
2020-12-30 20:18:42 +01:00
|
|
|
closePopingNotice.addEventListener('click', (event) => {
|
|
|
|
popingNotice.classList.remove('active');
|
|
|
|
});
|
|
|
|
|
|
|
|
popingNotice.classList.add('active');
|
2020-12-29 06:33:37 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|