add youtube download, and look if I can fix the download progress ....
This commit is contained in:
79
index.php
79
index.php
@@ -29,37 +29,6 @@ function readfile_chunked($filename, $retbytes = TRUE) {
|
|||||||
return $status;
|
return $status;
|
||||||
}
|
}
|
||||||
|
|
||||||
// write stdin to a file chunk by chunk
|
|
||||||
function writefile_chunked($filename, $retbytes = TRUE) {
|
|
||||||
$buffer = '';
|
|
||||||
$cnt =0;
|
|
||||||
// $handle = fopen($filename, 'rb');
|
|
||||||
$handleIn = fopen("php://input", 'rb');
|
|
||||||
if ($handleIn === false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
//$handleOut = fopen($filename, 'wb');
|
|
||||||
$handleOut = fopen($filename, 'wb');
|
|
||||||
if ($handleOut === false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
while (!feof($handleIn)) {
|
|
||||||
$buffer = fread($handleIn, CHUNK_SIZE);
|
|
||||||
$retbytes=fwrite($handleOut,$buffer);
|
|
||||||
if ($retbytes) {
|
|
||||||
$cnt += strlen($buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$statusOut = fclose($handleOut);
|
|
||||||
$statusIn = fclose($handleIn);
|
|
||||||
$status = $statusIn;
|
|
||||||
if ($retbytes && $statusOut) {
|
|
||||||
return $cnt; // return num. bytes written.
|
|
||||||
}
|
|
||||||
|
|
||||||
return $status;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($_GET['dlFile'])){
|
if (isset($_GET['dlFile'])){
|
||||||
# doesn't work -- always gets killed (out of memory?)
|
# doesn't work -- always gets killed (out of memory?)
|
||||||
header('Content-disposition: attachment; filename='. $_GET["dlFile"]);
|
header('Content-disposition: attachment; filename='. $_GET["dlFile"]);
|
||||||
@@ -77,6 +46,11 @@ if (isset($_GET['url'])) {
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($_GET['ytdl'])) {
|
||||||
|
system("cd '" . $FP . "';/var/www/dl/ytdl.sh '" . $_GET["ytdl"] . "'");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($_GET['getFileList'])) {
|
if (isset($_GET['getFileList'])) {
|
||||||
header('Content-type: application/json');
|
header('Content-type: application/json');
|
||||||
header("Pragma: no-cache");
|
header("Pragma: no-cache");
|
||||||
@@ -96,8 +70,7 @@ if (isset($_SERVER['HTTP_X_FILENAME'])) {
|
|||||||
$fileName=$origFileName . "." . ++$i;
|
$fileName=$origFileName . "." . ++$i;
|
||||||
}
|
}
|
||||||
|
|
||||||
//file_put_contents( $FP . $fileName, file_get_contents('php://input'));
|
file_put_contents( $FP . $fileName, file_get_contents('php://input'));
|
||||||
writefile_chunked($FP . $fileName);
|
|
||||||
echo $fileName . " uploaded";
|
echo $fileName . " uploaded";
|
||||||
system("cd '" . $FP . "';/usr/bin/md5sum '" . $fileName . "' | /usr/bin/cut -c1-32 > '." . $fileName . ".md5'");
|
system("cd '" . $FP . "';/usr/bin/md5sum '" . $fileName . "' | /usr/bin/cut -c1-32 > '." . $fileName . ".md5'");
|
||||||
exit(0);
|
exit(0);
|
||||||
@@ -179,7 +152,7 @@ if (isset($_GET['kill'])) {
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<span style='font-size:40px'><span style='color:#777777'>Down</span>-<span style='color:#FF0000'>loader</span></span><span style='font-size:14px'> by <a href='mailto:joe@netsquat.com'>joe@netsquat.com</a></span>
|
<span style='font-size:40px'><span style='color:#777777'>Down</span>-<span style='color:#FF0000'>loader</span></span><span style='font-size:14px'> by <a href='mailto:joe@kawomi.com'>joe@kawomi.com</a></span>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<fieldset class='upload'><legend class='upload'>Upload local file</legend>
|
<fieldset class='upload'><legend class='upload'>Upload local file</legend>
|
||||||
@@ -194,10 +167,14 @@ if (isset($_GET['kill'])) {
|
|||||||
<br>
|
<br>
|
||||||
<fieldset class='upload'><legend class='upload'>Download remote url</legend>
|
<fieldset class='upload'><legend class='upload'>Download remote url</legend>
|
||||||
<input name="url" id="url" size="100">
|
<input name="url" id="url" size="100">
|
||||||
<button id='btnDownload' onclick="downloader.downloadURL(document.getElementById('url').value)" >Download</button>
|
<button id='btnDownload' onclick="downloader.downloadURL(document.getElementById('url').value,'url')" >Download</button>
|
||||||
|
</fieldset>
|
||||||
|
<fieldset class='upload'><legend class='upload'>Download youtube</legend>
|
||||||
|
<input name="ytdl" id="ytdl" size="100">
|
||||||
|
<button id='btnDownload' onclick="downloader.downloadURL(document.getElementById('ytdl').value,'ytdl')" >Download</button>
|
||||||
|
</fieldset>
|
||||||
<div id="DownloadProgressBars">
|
<div id="DownloadProgressBars">
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
|
||||||
<hr>
|
<hr>
|
||||||
<table id="fileList" class='fileList' style="font-family:monospace">
|
<table id="fileList" class='fileList' style="font-family:monospace">
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -308,11 +285,11 @@ var downloader = (function () {
|
|||||||
fillFileList();
|
fillFileList();
|
||||||
}
|
}
|
||||||
|
|
||||||
function downloadURL(url) {
|
function downloadURL(url,type) {
|
||||||
var progressBarId=Math.random()*100000000000000000;
|
var progressBarId=Math.random()*100000000000000000;
|
||||||
$id("DownloadProgressBars").add(progressBarId,url)
|
$id("DownloadProgressBars").add(progressBarId,url)
|
||||||
$id("DownloadProgressBars").setMax(progressBarId,100)
|
$id("DownloadProgressBars").setMax(progressBarId,100)
|
||||||
$id("url").value = "";
|
$id(type).value = "";
|
||||||
|
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.onreadystatechange = function() {
|
xhr.onreadystatechange = function() {
|
||||||
@@ -321,22 +298,40 @@ var downloader = (function () {
|
|||||||
fillFileList();
|
fillFileList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xhr.open("GET", "?url=" + encodeURIComponent(url), true);
|
// TODO: The progress update only fires at the end, used to work before.. have to look sure if it's server or client...
|
||||||
|
xhr.onprogress = function(event) {
|
||||||
|
// report progress
|
||||||
|
console.log(`Loaded ${event.loaded} of ${event.total}`);
|
||||||
|
var tmpResponse=event.currentTarget.response;
|
||||||
|
var lastIndex=tmpResponse.lastIndexOf("%");
|
||||||
|
console.log(new Date(),tmpResponse,lastIndex);
|
||||||
|
if (lastIndex>0) {
|
||||||
|
var pctFinish=tmpResponse.substring(lastIndex-3,lastIndex);
|
||||||
|
//console.log(pctFinish,tmpResponse);
|
||||||
|
$id("DownloadProgressBars").setProgress(progressBarId,pctFinish);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
xhr.addEventListener("progress",xhr.onprogress,false);
|
||||||
|
xhr.open("GET", "?" + type + "=" + encodeURIComponent(url), true);
|
||||||
xhr.send();
|
xhr.send();
|
||||||
|
|
||||||
|
|
||||||
var timer;
|
var timer;
|
||||||
timer = window.setInterval(function() {
|
timer = window.setInterval(function() {
|
||||||
if (xhr.readyState === 4) {
|
if (xhr.readyState === 4) {
|
||||||
window.clearTimeout(timer);
|
window.clearTimeout(timer);
|
||||||
Output('UrlDownload done <br />');
|
Output('UrlDownload done <br />');
|
||||||
}
|
}
|
||||||
var tmpResponse=xhr.responseText;
|
/* var tmpResponse=xhr.responseText;
|
||||||
var lastIndex=tmpResponse.lastIndexOf("%");
|
var lastIndex=tmpResponse.lastIndexOf("%");
|
||||||
|
console.log(tmpResponse,lastIndex);
|
||||||
if (lastIndex>0) {
|
if (lastIndex>0) {
|
||||||
var pctFinish=tmpResponse.substring(lastIndex-3,lastIndex);
|
var pctFinish=tmpResponse.substring(lastIndex-3,lastIndex);
|
||||||
|
//console.log(pctFinish,tmpResponse);
|
||||||
$id("DownloadProgressBars").setProgress(progressBarId,pctFinish);
|
$id("DownloadProgressBars").setProgress(progressBarId,pctFinish);
|
||||||
}
|
}
|
||||||
// console.log(xhr.responseText);
|
console.log(xhr.responseText); */
|
||||||
}, 300);
|
}, 300);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -423,8 +418,10 @@ function setPct(id){
|
|||||||
|
|
||||||
function setProgress(id,value){
|
function setProgress(id,value){
|
||||||
current=value;
|
current=value;
|
||||||
|
if ($id("progressUL" + id) !== null) {
|
||||||
$id("progressUL" + id).value = value;
|
$id("progressUL" + id).value = value;
|
||||||
setPct(id);
|
setPct(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove(id){
|
function remove(id){
|
||||||
|
|||||||
6
ytdl.sh
Normal file
6
ytdl.sh
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
echo $1 >> /tmp/dlX
|
||||||
|
#/usr/bin/stdbuf -i0 -o0 -e0 /usr/local/bin/youtube-dl --newline -f 160 $1 2>&1 | cut -c 11-13 | while read x; do echo ${x}% $(seq 1 2094 | xargs /usr/bin/stdbuf -i0 -o0 -e0 echo); done
|
||||||
|
/usr/bin/stdbuf -i0 -o0 -e0 /usr/local/bin/youtube-dl --newline -f 160 $1 2>&1 | /usr/bin/stdbuf -i0 -o0 -e0 cut -c 11-14 | while read x
|
||||||
|
do /usr/bin/stdbuf -i0 -o0 -e0 printf "%3d%% .................................................................................................... \r\n" ${x}
|
||||||
|
done
|
||||||
Reference in New Issue
Block a user