Skip to content

Commit e889f79

Browse files
committed
removing lots of random trash, fix file downloading, split downloading into view/download
1 parent 904c470 commit e889f79

1 file changed

Lines changed: 31 additions & 13 deletions

File tree

index.php

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ class YTDLP
88
public static $yt_dl_base='yt-dlp';
99
public static $output_format ="%(title)s.%(ext)s";
1010
public static $cache_dir=".cache";
11-
public static $removal_options=' --replace-in-metadata title "[\U00010000-\U0010ffff]" "" --replace-in-metadata title "&" "_" --replace-in-metadata title " " "_"';
12-
public static $yt_dl_temp_path="./tmp";
13-
public static $dl_dir_common='files';
11+
public static $removal_options=' --replace-in-metadata title "[\U00010000-\U0010ffff]" "" --replace-in-metadata title "&" "_" --replace-in-metadata title "," "_" --replace-in-metadata title "=" "_" --replace-in-metadata title " " "_"';
12+
public static $yt_dl_temp_path="tmp";
13+
public static $dl_dir_common='mp4';
1414
public static $dl_dir_mp3='mp3';
1515
public static $yt_dl_format_1080p=' -S res:1080,fps,+codec:avc:m4a ';
16-
public static $yt_dl_subs_yes=' --write-sub --write-auto-sub --sub-langs "en,no,no-nb,no-bm,ru,nl,nl-be" --embed-subs --compat-options no-keep-subs ';
1716
public static $yt_dl_pls_no_sponsor=' --sponsorblock-remove sponsor --sponsorblock-mark all,-filler ';
1817
public static $youtubedl_video_standard;
1918
public static $youtubemp3=" -x --audio-format mp3 ";
@@ -78,6 +77,11 @@ static function SaveDownloader()
7877
setcookie("jobs",json_encode($jobs),time()+60*60*24*30);
7978
}
8079

80+
static function LoadJob($jobid)
81+
{
82+
return json_decode(file_get_contents(self::$jobpath."/".basename($jobid).".job"),true);
83+
}
84+
8185
static function LoadDownloader()
8286
{
8387
if(!isset($_COOKIE['jobs']))
@@ -90,7 +94,7 @@ static function LoadDownloader()
9094
{
9195
if(file_exists(self::$jobpath."/".basename($job).".job"))
9296
{
93-
self::$DOWNLOADER[]=json_decode(file_get_contents(self::$jobpath."/".basename($job).".job"),true);
97+
self::$DOWNLOADER[]=self::LoadJob($job);
9498
}
9599
}
96100
}
@@ -588,6 +592,7 @@ function ShowConfigurator()
588592
Job file path:<input name="jobpath" value="<?php echo YTDLP::$jobpath;?>" /><br />
589593
Temp path:<input name="tempopath" value="<?php echo YTDLP::$yt_dl_temp_path;?>" /><br />
590594
Cache Path:<input name="cachepath" value="<?php echo YTDLP::$cache_dir;?>" /><br />
595+
Time to keep downloaded files, minutes:<input name="job_ttl" value="<?php echo YTDLP::$job_ttl;?>" /><br />
591596
Username (leave blank to disable login):<input name="username" value="<?php echo YTDLP::$user;?>" /><br />
592597
Password (leave blank to keep the same):<input name="password" type="password" /><br />
593598
Reset configuration password:<input name="erase_password" type="password" /><br />
@@ -690,6 +695,7 @@ function ConfirmErase($error="")
690695
YTDLP::$jobpath=$_POST['jobpath'];
691696
YTDLP::$yt_dl_temp_path=$_POST['tempopath'];
692697
YTDLP::$cache_dir=$_POST['cachepath'];
698+
YTDLP::$job_ttl=$_POST['job_ttl'];
693699
if($_POST['username']!=="")
694700
{
695701
YTDLP::$user=$_POST['username'];
@@ -703,6 +709,8 @@ function ConfirmErase($error="")
703709
YTDLP::$erase_pass=password_hash($_POST['erase_password'], PASSWORD_DEFAULT);
704710
}
705711
YTDLP::SaveConfig();
712+
header("Location: index.php");
713+
die;
706714
}
707715
}
708716

@@ -762,10 +770,7 @@ function ConfirmErase($error="")
762770
$_SESSION['user']=$user;
763771
}
764772
else
765-
{ print_r($_POST);
766-
print_r($_SESSION);
767-
print_r((array)YTDLP::$user);
768-
print_r((array)YTDLP::$passhash);
773+
{
769774
ShowLogin("haha nope");
770775
die;
771776
}
@@ -835,7 +840,7 @@ function ConfirmErase($error="")
835840
{
836841
$dlinfo['tasks'][]=[
837842
"mode"=>$mode,
838-
"status"=>"waitng",
843+
"status"=>"waiting",
839844
"provider"=>"unknown",
840845
"progress"=>0
841846
];
@@ -868,6 +873,7 @@ function ConfirmErase($error="")
868873
{
869874
$dljobid=$_GET['dljob'];
870875
$dlidx=basename($_GET['dlidx']);
876+
$force_dl=isset($_GET['force']);
871877
if(YTDLP::getJobIndex($dljobid)!==-1)
872878
{
873879
$mode="";
@@ -880,7 +886,11 @@ function ConfirmErase($error="")
880886
if(file_exists($path))
881887
{
882888
$ctype=($mode==="mp3")?"audio/mp3":"video/mp4";
883-
header("Content-Disposition: attachment; filename="+$dlidx);
889+
if($force_dl)
890+
{
891+
header("Content-Disposition: attachment; filename=\"".rawurlencode($dlidx)."\"");
892+
}
893+
884894
header("Content-Type: ".$ctype);
885895
header("Content-Length: ".filesize($path));
886896
$file=fopen($path,"r");
@@ -970,6 +980,10 @@ function handleUpdate(update)
970980
s.dataset.status="done";
971981
s.href="index.php?dljob="+update.jobid+"&dlidx="+encodeURIComponent(update.filename);
972982
td.appendChild(s);
983+
var forcelink=document.createElement("a");
984+
forcelink.href="index.php?force=true&dljob="+update.jobid+"&dlidx="+encodeURIComponent(update.filename);
985+
forcelink.append(" ⬇ ");
986+
td.appendChild(forcelink);
973987
break;
974988
}
975989
case "error":
@@ -1129,6 +1143,10 @@ function DisplayJob(job)
11291143
percent_bar.dataset.progress=task.progress.percent;
11301144
percent_number.dataset.progress=task.progress.percent+"%";
11311145
status_icon.href="index.php?dljob="+job.jobid+"&dlidx="+encodeURIComponent(task.filename);
1146+
var forcelink=document.createElement("a");
1147+
forcelink.href="index.php?force=true&dljob="+job.jobid+"&dlidx="+encodeURIComponent(task.filename);
1148+
forcelink.append(" ⬇ ");
1149+
td_status.appendChild(forcelink);
11321150
break;
11331151
}
11341152
default:
@@ -1291,7 +1309,7 @@ function showInfo(info)
12911309
</tbody>
12921310
</table>
12931311
<br />
1294-
<a href="/files">download dir</a><br />
1295-
<a href="/mp3">music</a><br />
1312+
<a href="index.php?reset">reset configuration</a><br />
1313+
<a href="index.php?logout">log out</a><br />
12961314
</body>
12971315
</html>

0 commit comments

Comments
 (0)