Advertisement
AyrA

Youtube Link finder

Jul 14th, 2014
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.15 KB | None | 0 0
  1. <?php
  2.     ob_start();
  3.     ini_set('error_reporting', E_ALL ^ E_NOTICE);
  4.     ini_set('display_errors',1);
  5.    
  6.     $pid="";
  7.     if(!empty($_GET['pid']))
  8.     {
  9.         $pid=$_GET['pid'];
  10.         if(strstr($pid,"http://")!=$pid && strstr($pid,"https://")!=$pid)
  11.         {
  12.             $pid="http://$pid";
  13.         }
  14.     }
  15. ?>
  16.  
  17. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  18. <html>
  19. <head>
  20.     <title>Youtube Playlist Download Script</title>
  21.     <style type="text/css">
  22.         body
  23.         {
  24.             font-family:Arial,Sans-Serif;
  25.             line-height:1.5em;
  26.         }
  27.         form
  28.         {
  29.             margin-top:20px;
  30.             margin-bottom:20px;
  31.         }
  32.         .ytLink
  33.         {
  34.             display:block;
  35.             width:200px;
  36.             float:left;
  37.             border:1px solid #000000;
  38.             padding:10px;
  39.             color:#FF0000;
  40.             height:100px;
  41.         }
  42.         .ytLink:hover
  43.         {
  44.             background-color:#FFFF00;
  45.         }
  46.         #pid
  47.         {
  48.             width:500px;
  49.         }
  50.         .clear
  51.         {
  52.             clear:both;
  53.             line-height:1px;
  54.             height:1px;
  55.         }
  56.         textarea
  57.         {
  58.             margin-top:20px;
  59.             font-size:12pt;
  60.         }
  61.         a
  62.         {
  63.             color:#FF0000;
  64.         }
  65.         label
  66.         {
  67.             font-weight:bold;
  68.         }
  69.     </style>
  70.     <script type="text/javascript">
  71.         var btn;
  72.         var form;
  73.         function e(_)
  74.         {return document.getElementById(_);}
  75.        
  76.         function send()
  77.         {
  78.             btn.disabled=true;
  79.             btn.value="Please wait...";
  80.             form.submit();
  81.             return true;
  82.         }
  83.        
  84.         window.onload=function()
  85.         {
  86.             btn=e("btnSub");
  87.             form=document.getElementsByTagName("form")[0]
  88.             btn.onclick=send;
  89.         };
  90.     </script>
  91. </head>
  92.  
  93. <body>
  94.     <h1>Youtube URL extractor</h1>
  95.     This script extracts all the Video URLs from a given Page.<br />
  96.     just enter the URL in the Field, for Example:
  97.     http://www.youtube.com/playlist?list=PL1C44133D6731C5FB<br />
  98.     <b>You can enter any URL, not only Youtube Pages</b><br />
  99.    
  100.     <form method="GET" action="<?php echo $_SERVER['PHP_SELF'] ?>">
  101.         URL:
  102.         <?php if(empty($pid)){?>
  103.             <input type="text" name="pid" id="pid" /><br />
  104.         <?php }else{ ?>
  105.             <input type="text" name="pid" id="pid" value="<?php echo $pid; ?>" /><br />
  106.         <?php } ?>
  107.             API: <label><input type="checkbox" name="API" value="1" /> Use API Mode</label><br />
  108.             In API Mode you see the Link List as a Text File, each Link on a single Line,
  109.             so it is easy readable by Applications
  110.             <br />
  111.         <input id="btnSub" type="button" value="Get URLs" />
  112.     </form>
  113. <?php
  114.     //Check API Mode for flushing HTML output and set header
  115.     if(!empty($pid) && !empty($_GET['API']) && $_GET['API']=="1")
  116.     {
  117.         ob_end_clean();
  118.         ob_start();
  119.         header("Content-Type: text/plain");
  120.     }
  121.     if(!empty($pid))
  122.     {
  123.         if($args=getLinks($pid))
  124.         {
  125.             //Generate Links to click
  126.             foreach($args as $Link)
  127.             {
  128.                 $parts=explode("=",$Link,2);
  129.                 $parts=$parts[1];
  130.                 $title=getYTtitle($Link);
  131.                
  132.                 //Check API Mode for text or HTML output
  133.                 if(!empty($_GET['API']) && $_GET['API']=="1")
  134.                 {
  135.                     echo "$Link\r\n";
  136.                 }
  137.                 else
  138.                 {
  139.                     echo "<a class=\"ytLink\" target=\"_blank\" href=\"$Link\" title=\"/watch?v=$parts\">$title</a>";
  140.                     ob_flush();
  141.                     flush();
  142.                 }
  143.             }
  144.  
  145.             //Check API Mode and exit
  146.             if(!empty($_GET['API']) && $_GET['API']=="1")
  147.             {
  148.                 ob_end_flush();
  149.                 die();
  150.             }
  151.  
  152.            
  153.             //Generate links to copy
  154.             echo "<div class=\"clear\">&nbsp;</div>";
  155.             echo "<h3>Raw Links</h3>";
  156.             echo "<br />You may add this Links into your Download Application, for Example ".
  157.                 "<a href=\"http://www.freemake.com/\">Freemake Video Downloader</a>".
  158.                 "</span><br />";
  159.             echo "<textarea rows=\"".(count($args)+1)."\" cols=\"50\">";
  160.             foreach($args as $Link)
  161.             {
  162.                 echo "$Link\r\n";
  163.             }
  164.             echo "</textarea>";
  165.         }
  166.         else
  167.         {
  168.             if(!empty($_GET['API']) && $_GET['API']=="1")
  169.             {
  170.                 echo "ERR: No Youtube Links found";
  171.                 ob_end_flush();
  172.                 die();
  173.             }
  174.             else
  175.             {
  176.                 echo "There are no Youtube Links in this Page!";
  177.             }
  178.         }
  179.     }
  180.  
  181.     //Extracts Youtube Links from a Page
  182.     function getLinks($url)
  183.     {
  184.         $URLs="";
  185.         $seite=HTTPget($url);
  186.         preg_match_all('/watch\\?v=([0-9a-zA-Z_-]+)/', $seite, $erg);
  187.         $erg=array_unique($erg[1]);
  188.         foreach ($erg as $id)
  189.         {
  190.             $URLs.="http://www.youtube.com/watch?v=$id|";
  191.         }
  192.         if($URLs!="")
  193.         {
  194.             return explode("|",substr($URLs,0,-1));
  195.         }
  196.         return false;
  197.     }
  198.    
  199.     //gets the Title of a Youtube Page
  200.     function getYTtitle($url)
  201.     {
  202.         return trim(getStr(HTTPget($url),"<title>","</title>"));
  203.     }
  204.    
  205.     // Gets a string between 2 strings
  206.     function getStr($a,$b,$c)
  207.     {
  208.         $y = explode($b,$a);
  209.         $x = explode($c,$y[1]);
  210.         return $x[0];
  211.     }
  212.  
  213.     //Gets contents of any webside by an URL.
  214.     function HTTPget($url)
  215.     {
  216.         $urlElem=parse_url($url);
  217.         $fp=fsockopen($urlElem['host'],80,$errno,$errstr,10);
  218.  
  219.         if(!$fp)
  220.         {
  221.             exit("Could not create socket: '$errnstr' ($errno)." );
  222.         }
  223.  
  224.         $request="GET ".$urlElem['path'].(isset($urlElem['query'])?"?".$urlElem['query']:"")." HTTP/1.1\r\n";
  225.         $request.="Host: ".$urlElem['host']."\r\n";
  226.         $request.="User-Agent: Kekse 1.3.3.7\r\n";
  227.         $request.="Connection: Close\r\n\r\n";
  228.  
  229.         fwrite($fp,$request);
  230.         $response="";
  231.         while(!feof($fp))
  232.         {
  233.             $response.=fgets($fp,128);
  234.         }
  235.         fclose($fp);
  236.  
  237.         // split headers from data
  238.         $responseSplit=explode("\r\n\r\n",$response,2);
  239.         return $responseSplit[1];
  240.     }
  241. ?>
  242. </body>
  243. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement