Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ob_start();
- ini_set('error_reporting', E_ALL ^ E_NOTICE);
- ini_set('display_errors',1);
- $pid="";
- if(!empty($_GET['pid']))
- {
- $pid=$_GET['pid'];
- if(strstr($pid,"http://")!=$pid && strstr($pid,"https://")!=$pid)
- {
- $pid="http://$pid";
- }
- }
- ?>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <title>Youtube Playlist Download Script</title>
- <style type="text/css">
- body
- {
- font-family:Arial,Sans-Serif;
- line-height:1.5em;
- }
- form
- {
- margin-top:20px;
- margin-bottom:20px;
- }
- .ytLink
- {
- display:block;
- width:200px;
- float:left;
- border:1px solid #000000;
- padding:10px;
- color:#FF0000;
- height:100px;
- }
- .ytLink:hover
- {
- background-color:#FFFF00;
- }
- #pid
- {
- width:500px;
- }
- .clear
- {
- clear:both;
- line-height:1px;
- height:1px;
- }
- textarea
- {
- margin-top:20px;
- font-size:12pt;
- }
- a
- {
- color:#FF0000;
- }
- label
- {
- font-weight:bold;
- }
- </style>
- <script type="text/javascript">
- var btn;
- var form;
- function e(_)
- {return document.getElementById(_);}
- function send()
- {
- btn.disabled=true;
- btn.value="Please wait...";
- form.submit();
- return true;
- }
- window.onload=function()
- {
- btn=e("btnSub");
- form=document.getElementsByTagName("form")[0]
- btn.onclick=send;
- };
- </script>
- </head>
- <body>
- <h1>Youtube URL extractor</h1>
- This script extracts all the Video URLs from a given Page.<br />
- just enter the URL in the Field, for Example:
- http://www.youtube.com/playlist?list=PL1C44133D6731C5FB<br />
- <b>You can enter any URL, not only Youtube Pages</b><br />
- <form method="GET" action="<?php echo $_SERVER['PHP_SELF'] ?>">
- URL:
- <?php if(empty($pid)){?>
- <input type="text" name="pid" id="pid" /><br />
- <?php }else{ ?>
- <input type="text" name="pid" id="pid" value="<?php echo $pid; ?>" /><br />
- <?php } ?>
- API: <label><input type="checkbox" name="API" value="1" /> Use API Mode</label><br />
- In API Mode you see the Link List as a Text File, each Link on a single Line,
- so it is easy readable by Applications
- <br />
- <input id="btnSub" type="button" value="Get URLs" />
- </form>
- <?php
- //Check API Mode for flushing HTML output and set header
- if(!empty($pid) && !empty($_GET['API']) && $_GET['API']=="1")
- {
- ob_end_clean();
- ob_start();
- header("Content-Type: text/plain");
- }
- if(!empty($pid))
- {
- if($args=getLinks($pid))
- {
- //Generate Links to click
- foreach($args as $Link)
- {
- $parts=explode("=",$Link,2);
- $parts=$parts[1];
- $title=getYTtitle($Link);
- //Check API Mode for text or HTML output
- if(!empty($_GET['API']) && $_GET['API']=="1")
- {
- echo "$Link\r\n";
- }
- else
- {
- echo "<a class=\"ytLink\" target=\"_blank\" href=\"$Link\" title=\"/watch?v=$parts\">$title</a>";
- ob_flush();
- flush();
- }
- }
- //Check API Mode and exit
- if(!empty($_GET['API']) && $_GET['API']=="1")
- {
- ob_end_flush();
- die();
- }
- //Generate links to copy
- echo "<div class=\"clear\"> </div>";
- echo "<h3>Raw Links</h3>";
- echo "<br />You may add this Links into your Download Application, for Example ".
- "<a href=\"http://www.freemake.com/\">Freemake Video Downloader</a>".
- "</span><br />";
- echo "<textarea rows=\"".(count($args)+1)."\" cols=\"50\">";
- foreach($args as $Link)
- {
- echo "$Link\r\n";
- }
- echo "</textarea>";
- }
- else
- {
- if(!empty($_GET['API']) && $_GET['API']=="1")
- {
- echo "ERR: No Youtube Links found";
- ob_end_flush();
- die();
- }
- else
- {
- echo "There are no Youtube Links in this Page!";
- }
- }
- }
- //Extracts Youtube Links from a Page
- function getLinks($url)
- {
- $URLs="";
- $seite=HTTPget($url);
- preg_match_all('/watch\\?v=([0-9a-zA-Z_-]+)/', $seite, $erg);
- $erg=array_unique($erg[1]);
- foreach ($erg as $id)
- {
- $URLs.="http://www.youtube.com/watch?v=$id|";
- }
- if($URLs!="")
- {
- return explode("|",substr($URLs,0,-1));
- }
- return false;
- }
- //gets the Title of a Youtube Page
- function getYTtitle($url)
- {
- return trim(getStr(HTTPget($url),"<title>","</title>"));
- }
- // Gets a string between 2 strings
- function getStr($a,$b,$c)
- {
- $y = explode($b,$a);
- $x = explode($c,$y[1]);
- return $x[0];
- }
- //Gets contents of any webside by an URL.
- function HTTPget($url)
- {
- $urlElem=parse_url($url);
- $fp=fsockopen($urlElem['host'],80,$errno,$errstr,10);
- if(!$fp)
- {
- exit("Could not create socket: '$errnstr' ($errno)." );
- }
- $request="GET ".$urlElem['path'].(isset($urlElem['query'])?"?".$urlElem['query']:"")." HTTP/1.1\r\n";
- $request.="Host: ".$urlElem['host']."\r\n";
- $request.="User-Agent: Kekse 1.3.3.7\r\n";
- $request.="Connection: Close\r\n\r\n";
- fwrite($fp,$request);
- $response="";
- while(!feof($fp))
- {
- $response.=fgets($fp,128);
- }
- fclose($fp);
- // split headers from data
- $responseSplit=explode("\r\n\r\n",$response,2);
- return $responseSplit[1];
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement