Skip to content

Commit a0242c4

Browse files
committed
added OOB and more link fixing hopefully
1 parent be0e4b4 commit a0242c4

File tree

1 file changed

+174
-8
lines changed

1 file changed

+174
-8
lines changed

index.php

Lines changed: 174 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<?php
2+
session_start();
23
class YTDLP
34
{
4-
public static $yt_dl_base='yt-dlp --cache-dir .cache';
5+
public static $yt_dl_base='yt-dlp';
56
public static $output_format ="%(title)s.%(ext)s";
7+
public static $cache_dir=".cache";
8+
public static $removal_options=' --replace-in-metadata title "[\U00010000-\U0010ffff]" "" --replace-in-metadata title "&" "_" --replace-in-metadata title " " "_"';
69
public static $yt_dl_temp_path="./tmp";
710
public static $dl_dir_common='files';
811
public static $dl_dir_mp3='mp3';
@@ -13,11 +16,46 @@ class YTDLP
1316
public static $youtubemp3=" -x --audio-format mp3 ";
1417
public static $jobpath="jobs";
1518
public static $args=[];
16-
19+
20+
public static $user="";
21+
public static $passhash="";
22+
1723
public static $DOWNLOADER=[];
1824

1925
static $jobindex=0;
2026

27+
static function LoadConfig()
28+
{
29+
if(!file_exists(".dlconfig"))
30+
{
31+
return false;
32+
}
33+
else
34+
{
35+
$config=json_decode(file_get_contents(".dlconfig"),true);
36+
self::$dl_dir_common=$config['videopath'];
37+
self::$dl_dir_mp3=$config['musicpath'];
38+
self::$yt_dl_temp_path=$config['temppath'];
39+
self::$jobpath=$config['jobpath'];
40+
self::$user=$config['user'];
41+
self::$passhash=$config['pass'];
42+
self::$cache_dir=$config['cachepath'];
43+
}
44+
}
45+
static function SaveConfig()
46+
{
47+
$config=[
48+
"videopath"=>self::$dl_dir_common,
49+
"musicpath"=>self::$dl_dir_mp3,
50+
"temppath"=>self::$yt_dl_temp_path,
51+
"jobpath"=>self::$jobpath,
52+
"cachepath"=>self::$cache_dir,
53+
"user"=>self::$user,
54+
"pass"=>self::$passhash
55+
];
56+
file_put_contents(".dlconfig", json_encode($config));
57+
}
58+
2159
static function SaveDownloader()
2260
{
2361
$jobs=[];
@@ -99,17 +137,30 @@ static function buildCMD($dl_mode,$jobid,$vlist)
99137
{
100138
$vlist_args=implode(" ",array_map("escapeshellarg",$vlist));
101139

102-
$cmd="";
140+
$cmd_prefix="";
141+
$cmd_postfix=" &";
142+
// TODO: add a windows check here and alter the above to "start /b " and "" respectively
143+
$windows=false;
144+
if($windows)
145+
{
146+
$cmd_prefix="start /b ";
147+
$cmd_postfix="";
148+
}
149+
150+
$cmd=$cmd_prefix;
103151

104152
$cmd.=self::$yt_dl_base;
153+
$cmd.=" --cache-dir ";
154+
$cmd.=escapeshellarg(self::$cache_dir);
105155
$cmd.=" -P ".self::$args['tmp'];
106156
$cmd.=" -P ".self::$args['out-path'];
107157
$cmd.=$dl_mode;
158+
$cmd.=self::$removal_options;
108159
$cmd.=" -- ";
109160
$cmd.=$vlist_args;
110161
$cmd.="> ".self::$jobpath."/$jobid 2>&1";
111162

112-
$cmd.=" &";
163+
$cmd.=$cmd_postfix;
113164

114165
return $cmd;
115166
}
@@ -443,19 +494,134 @@ static function getJobIndex($jobid)
443494
return -1;
444495
}
445496
}
446-
YTDLP::Init();
447497

448498

499+
function ShowConfigurator()
500+
{
501+
?><!doctype html>
502+
<html>
503+
<head>
504+
<title>YT-DLP Configuration Page</title>
505+
</head>
506+
<body>
507+
<p>This is the first time this application has been run, please complete setup.</p>
508+
<form action="index.php" method="POST">
509+
Video path:<input name="videopath" value="<?php echo YTDLP::$dl_dir_common;?>" /><br />
510+
Music path:<input name="musicpath" value="<?php echo YTDLP::$dl_dir_mp3;?>" /><br />
511+
Job file path:<input name="jobpath" value="<?php echo YTDLP::$jobpath;?>" /><br />
512+
Temp path:<input name="tempopath" value="<?php echo YTDLP::$yt_dl_temp_path;?>" /><br />
513+
Cache Path:<input name="cachepath" value="<?php echo YTDLP::$cache_dir;?>" /><br />
514+
Username (leave blank to disable login):<input name="username" value="<?php echo YTDLP::$user;?>" /><br />
515+
Password (leave blank to keep the same):<input name="password" type="password"/><br />
516+
<button type="submit">Save</button>
517+
</form>
518+
</body>
519+
</html>
520+
<?php
521+
}
522+
523+
function ShowLogin($error="")
524+
{
525+
?><!doctype html>
526+
<html>
527+
<head>
528+
<title>Log in</title>
529+
</head>
530+
<body>
531+
<h3><?php echo $error; ?></h3>
532+
<form action="index.php?login" method="GET">
533+
Username:<input name="username" /><br />
534+
Password:<input name="password" type="password"><br />
535+
<button type="submit">Log in</button>
536+
</form>
537+
</body>
538+
</html>
539+
<?php
540+
}
541+
449542

543+
// get a hash if creating a pre-made file
544+
if(isset($_GET['password']))
545+
{
546+
echo password_hash($_GET['password']);
547+
die;
548+
}
450549

451550

452-
///////////////////////////////////////////
453-
// LET THE MOTHERFUCKING GAMES BEGIN ///
454-
///////////////////////////////////////////
455551

456552

457553

458554

555+
556+
///////////////////////////////////////////\
557+
// LET THE MOTHERFUCKING GAMES BEGIN ////\\
558+
////////////////////////////////////////////__\\
559+
560+
561+
562+
563+
if(!YTDLP::LoadConfig())
564+
{
565+
if(!isset($_POST['videopath']))
566+
{
567+
ShowConfigurator();
568+
die;
569+
}
570+
else
571+
{
572+
// i mean yeah but
573+
// 1) if you run php as root you deserve everything that happens
574+
// 2) don't open your unconfigured app to the public
575+
// 3) it's a one-time thing (and you can include a premade file)
576+
YTDLP::$dl_dir_common=$_POST['videopath'];
577+
YTDLP::$dl_dir_mp3=$_POST['musicpath'];
578+
YTDLP::$jobpath=$_POST['jobpath'];
579+
YTDLP::$yt_dl_temp_path=$_POST['tempopath'];
580+
YTDLP::$cache_dir=$_POST['cachepath'];
581+
if($_POST['username']!=="")
582+
{
583+
YTDLP::$user=$_POST['username'];
584+
}
585+
if($_POST['password']!=="")
586+
{
587+
YTDLP::$passhash=password_hash($_POST['password']);
588+
}
589+
YTDLP::SaveConfig();
590+
}
591+
}
592+
593+
594+
YTDLP::Init();
595+
596+
if(isset($_GET['logout']))
597+
{
598+
unset($_SESSION['user']);
599+
}
600+
601+
602+
// if username was set blank, don't ask auth
603+
if(YTDLP::$user!=="" && !isset($_SESSION['user']))
604+
{
605+
ShowLogin();
606+
die;
607+
}
608+
// login attemptss >:3
609+
if(isset($_GET['login']))
610+
{
611+
$user=$_POST['username'];
612+
$pass=password_verify($_POST['password'],YTDLP::$passhash);
613+
if($pass && $user===YTDLP::$user)
614+
{
615+
$_SESSION['user']=$user;
616+
}
617+
else
618+
{
619+
ShowLogin("haha nope");
620+
die;
621+
}
622+
}
623+
624+
// the regular stuff as scheduled
459625
if(isset($_POST['urls']))
460626
{
461627

0 commit comments

Comments
 (0)