forked from WWBN/AVideo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdownloadExternalVideo.php
177 lines (170 loc) · 9.52 KB
/
downloadExternalVideo.php
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
require_once '../videos/configuration.php';
require_once $global['systemRootPath'] . 'objects/user.php';
if (!User::canUpload()) {
header("location: {$global['webSiteRootURL']}user");
exit;
}
function isYoutubeDl() {
return trim(shell_exec('which youtube-dl'));
}
?>
<!DOCTYPE html>
<html lang="<?php echo $_SESSION['language']; ?>">
<head>
<title><?php echo $config->getWebSiteTitle(); ?> :: <?php echo __("User"); ?></title>
<?php
include $global['systemRootPath'] . 'view/include/head.php';
?>
</head>
<body>
<?php
include 'include/navbar.php';
?>
<div class="container">
<?php
if (!isYoutubeDl()) {
?>
<div class="alert alert-danger">
<h1><?php echo __("Sorry you not able to download videos right now!"); ?></h1>
<h2><?php echo __("You need to install"); ?> youtube-dl</h2>
<?php echo __("We use youtube-dl to download videos from youtube.com or other video platforms"); ?><br>
<?php echo __("To installations instructions try this link: "); ?><a href="https://github.com/rg3/youtube-dl/blob/master/README.md#installation">Youtube-dl</a><br><br>
<?php echo __("youtube-dl uses Python and some servers does not came with python as dafault, to install Python type:"); ?>
<pre><code>sudo apt-get install python</code></pre>
<br>
<?php echo __("To install it right away for all UNIX users (Linux, OS X, etc.), type: "); ?>
<pre><code>sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl && sudo chmod a+rx /usr/local/bin/youtube-dl</code></pre>
<br>
<?php echo __("If you do not have curl, you can alternatively use a recent wget: "); ?>
<pre><code>sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl && sudo chmod a+rx /usr/local/bin/youtube-dl</code></pre>
</div>
<?php
} else {
?>
<div class="row">
<div class="col-xs-1 col-sm-1 col-lg-2"></div>
<div class="col-xs-10 col-sm-10 col-lg-8">
<form class="form-compact well form-horizontal" id="updateUserForm" onsubmit="">
<fieldset>
<legend><?php echo __("Download Video"); ?></legend>
<div class="form-group">
<label class="col-md-4 control-label"><?php echo __("Video URL"); ?></label>
<div class="col-md-8 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-film"></i></span>
<input id="inputVideoURL" placeholder="<?php echo __("Video URL"); ?>" class="form-control" type="text" value="" required >
</div>
</div>
</div>
<!-- TODO audio only -->
<div class="form-group" style="display: none">
<label class="col-md-4 control-label"><?php echo __("Audio only"); ?></label>
<div class="col-md-8 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-headphones"></i></span>
<input id="inputAudioOnly" class="form-control" type="checkbox" value="1" >
</div>
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label"></label>
<div class="col-md-8">
<button type="submit" class="btn btn-primary" ><?php echo __("Download"); ?> <span class="glyphicon glyphicon-download"></span></button>
</div>
</div>
</fieldset>
</form>
<div class="progress progress-striped active">
<div id="downloadProgress" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0px"></div>
</div>
</div>
<div class="col-xs-1 col-sm-1 col-lg-2">
<?php
if (!empty($global['videoStorageLimitMinutes'])) {
$minutesTotal = getMinutesTotalVideosLength();
?>
<div class="alert alert-warning">
<?php printf(__("Make sure that the video you are going to download has a duration of less than %d minute(s)!"), ($global['videoStorageLimitMinutes']-$minutesTotal)); ?>
</div>
<?php
}
?>
</div>
</div>
<script>
$(document).ready(function () {
$('#updateUserForm').submit(function (evt) {
evt.preventDefault();
modal.showPleaseWait();
$.ajax({
url: 'downloadNow',
data: {"videoURL": $('#inputVideoURL').val(), "audioOnly": $('#inputAudioOnly').is(":checked")},
type: 'post',
success: function (response) {
if (response.error) {
swal({
title: response.title,
text: response.text,
type: response.type,
html: true
});
} else {
swal({
title: "<?php echo __("Congratulations!"); ?>",
text: "<?php echo __("Your video is downloading now"); ?>",
type: "success",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "<?php echo __("Go to manager videos page!"); ?>",
closeOnConfirm: false
},
function () {
window.location.href = '<?php echo $global['webSiteRootURL']; ?>mvideos';
});
if (response.filename) {
checkProgress(response.filename);
}
}
modal.hidePleaseWait();
}
});
});
});
function checkProgress(filename) {
console.log(filename);
$.ajax({
url: 'getDownloadProgress',
data: {"filename": filename},
type: 'post',
success: function (response) {
$("#downloadProgress").css({'width': response.progress + '%'});
if (response.progress < 100) {
setTimeout(function () {
checkProgress(filename);
}, 1000);
} else if (response.progress == 100) {
$("#downloadProgress").css({'width': '100%'});
swal({
title: "<?php echo __("Congratulations!"); ?>",
text: "<?php echo __("Your video download is complete, it is encoding now"); ?>",
type: "success"
},
function () {
window.location.href = '<?php echo $global['webSiteRootURL']; ?>mvideos';
});
}
}
});
}
</script>
<?php
}
?>
</div><!--/.container-->
<?php
include 'include/footer.php';
?>
</body>
</html>