Added update to motherless-dl.py.
[Python-Scripts.git] / MiniScripts / youtube-dl.php
blob1463c206a63c7ab12c603ab232608fc7b86e1672
1 <?php
2 @ob_start();
3 if(!isset($_GET['act'])) { $_GET['act'] = "url"; }
4 if($_GET['act']=="download") { $_GET['act'] = "get"; }
5 if($_GET['act']=="view") { $_GET['act'] = "get"; }
6 if($_GET['act']=="geturl") { $_GET['act'] = "url"; }
7 if($_GET['act']=="viewurl") { $_GET['act'] = "url"; }
8 if($_GET['act']=="redir") { $_GET['act'] = "goto"; }
9 if($_GET['act']=="redirect") { $_GET['act'] = "goto"; }
10 if($_GET['act']=="location") { $_GET['act'] = "goto"; }
11 if($_GET['act']=="gourl") { $_GET['act'] = "goto"; }
12 if($_GET['act']=="gotourl") { $_GET['act'] = "goto"; }
13 if($_GET['act']=="url") {
14 if(isset($_GET['fmt'])) { $_GET['fmt'] = 18; }
15 header("Content-type: text/plain; charset=utf-8");
16 exec("/usr/bin/youtube-dl --get-url --format ".$_GET['fmt']." https://www.youtube.com/watch?v=".$_GET['v'], $get_value);
17 $get_value = implode($get_value);
18 $get_value = trim($get_value);
19 echo $get_value; }
20 if($_GET['act']=="goto") {
21 if(isset($_GET['fmt'])) { $_GET['fmt'] = 18; }
22 header("Content-type: text/plain; charset=utf-8");
23 exec("/usr/bin/youtube-dl --get-url --format ".$_GET['fmt']." https://www.youtube.com/watch?v=".$_GET['v'], $get_value);
24 $get_value = implode($get_value);
25 $get_value = trim($get_value);
26 header("Location: ".$get_value);
27 echo $get_value; }
28 if($_GET['act']=="get") {
29 exec("/usr/bin/youtube-dl --dump-user-agent", $get_ua_value);
30 $get_ua_value = implode($get_ua_value);
31 $get_ua_value = trim($get_ua_value);
32 $default_opts = array(
33 'http'=>array(
34 'method'=>"GET",
35 'header'=>"User-Agent: ".$get_ua_value."\r\n".
36 "Referer: https://www.youtube.com/watch?fmt=".$_GET['fmt']."v=".$_GET['v']."\r\n"
39 $default = stream_context_set_default($default_opts);
40 if(isset($_GET['fmt'])) { $_GET['fmt'] = 18; }
41 exec("/usr/bin/youtube-dl --get-filename -f ".$_GET['fmt']." https://www.youtube.com/watch?v=".$_GET['v'], $get_fname);
42 $get_fname = implode($get_fname);
43 $get_fname = trim($get_fname);
44 header('Content-Disposition: attachment; filename="'.$get_fname.'"');
45 exec("/usr/bin/youtube-dl --get-url --format ".$_GET['fmt']." https://www.youtube.com/watch?v=".$_GET['v'], $get_value);
46 $get_value = implode($get_value);
47 $get_value = trim($get_value);
48 $getvidheaders = get_headers($get_value, 1);
49 header("Content-Type: ".$getvidheaders['Content-Type']);
50 echo file_get_contents($get_value); }