1
1
<?php
2
+ session_start ();
2
3
class YTDLP
3
4
{
4
- public static $ yt_dl_base ='yt-dlp --cache-dir .cache ' ;
5
+ public static $ yt_dl_base ='yt-dlp ' ;
5
6
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 " " "_" ' ;
6
9
public static $ yt_dl_temp_path ="./tmp " ;
7
10
public static $ dl_dir_common ='files ' ;
8
11
public static $ dl_dir_mp3 ='mp3 ' ;
@@ -13,11 +16,46 @@ class YTDLP
13
16
public static $ youtubemp3 =" -x --audio-format mp3 " ;
14
17
public static $ jobpath ="jobs " ;
15
18
public static $ args =[];
16
-
19
+
20
+ public static $ user ="" ;
21
+ public static $ passhash ="" ;
22
+
17
23
public static $ DOWNLOADER =[];
18
24
19
25
static $ jobindex =0 ;
20
26
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
+
21
59
static function SaveDownloader ()
22
60
{
23
61
$ jobs =[];
@@ -99,17 +137,30 @@ static function buildCMD($dl_mode,$jobid,$vlist)
99
137
{
100
138
$ vlist_args =implode (" " ,array_map ("escapeshellarg " ,$ vlist ));
101
139
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 ;
103
151
104
152
$ cmd .=self ::$ yt_dl_base ;
153
+ $ cmd .=" --cache-dir " ;
154
+ $ cmd .=escapeshellarg (self ::$ cache_dir );
105
155
$ cmd .=" -P " .self ::$ args ['tmp ' ];
106
156
$ cmd .=" -P " .self ::$ args ['out-path ' ];
107
157
$ cmd .=$ dl_mode ;
158
+ $ cmd .=self ::$ removal_options ;
108
159
$ cmd .=" -- " ;
109
160
$ cmd .=$ vlist_args ;
110
161
$ cmd .="> " .self ::$ jobpath ."/ $ jobid 2>&1 " ;
111
162
112
- $ cmd .=" & " ;
163
+ $ cmd .=$ cmd_postfix ;
113
164
114
165
return $ cmd ;
115
166
}
@@ -443,19 +494,134 @@ static function getJobIndex($jobid)
443
494
return -1 ;
444
495
}
445
496
}
446
- YTDLP ::Init ();
447
497
448
498
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
+
449
542
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
+ }
450
549
451
550
452
- ///////////////////////////////////////////
453
- // LET THE MOTHERFUCKING GAMES BEGIN ///
454
- ///////////////////////////////////////////
455
551
456
552
457
553
458
554
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
459
625
if (isset ($ _POST ['urls ' ]))
460
626
{
461
627
0 commit comments