forked from WWBN/AVideo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.download.js
86 lines (80 loc) · 2.93 KB
/
script.download.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
var downloadURLOrAlertErrorInterval;
var downloadURLOrAlertModal;
_setPleaseWait();
function _setPleaseWait(){
if(typeof getPleaseWait== 'undefined'){
setTimeout(() => {
_setPleaseWait();
}, 1000);
}else{
downloadURLOrAlertModal = getPleaseWait();
}
}
function downloadURLOrAlertError(jsonURL, data, filename, FFMpegProgress) {
if (empty(jsonURL)) {
console.log('downloadURLOrAlertError error empty jsonURL', jsonURL, data, filename, FFMpegProgress);
return false;
}
downloadURLOrAlertModal.showPleaseWait();
avideoToastInfo('Converting');
console.log('downloadURLOrAlertError 1', jsonURL, FFMpegProgress);
checkFFMPEGProgress(FFMpegProgress);
$.ajax({
url: jsonURL,
method: 'POST',
data: data,
success: function (response) {
clearInterval(downloadURLOrAlertErrorInterval);
if (response.error) {
avideoAlertError(response.msg);
downloadURLOrAlertModal.hidePleaseWait();
} else if (response.url) {
if (response.msg) {
avideoAlertInfo(response.msg);
}
if (
isMobile()
//|| /cdn.ypt.me/.test(response.url)
) {
console.log('downloadURLOrAlertError 2', response.url);
window.open(response.url, '_blank');
avideoToastInfo('Opening file');
//document.location = response.url
} else {
console.log('downloadURLOrAlertError 3', response.url, filename);
downloadURL(response.url, filename);
}
} else {
console.log('downloadURLOrAlertError 4', response);
avideoResponse(response);
}
//downloadURLOrAlertModal.hidePleaseWait();
}
});
}
function checkFFMPEGProgress(FFMpegProgress) {
if (empty(FFMpegProgress)) {
return false;
}
$.ajax({
url: FFMpegProgress,
success: function (response) {
console.log('checkFFMPEGProgress',response);
if (typeof response.progress.progress !== 'undefined') {
var text = 'Converting ...';
if (typeof response.progress.progress !== 'undefined') {
text += response.progress.progress + '% ';
downloadURLOrAlertModal.setProgress(response.progress.progress);
}
downloadURLOrAlertModal.setText(text);
if (response.progress.progress !== 100) {
setTimeout(function () {
checkFFMPEGProgress(FFMpegProgress);
}, 10000);
}else if(response.progress.progress >= 100){
downloadURLOrAlertModal.hidePleaseWait();
}
}
}
});
}