stefaniv
Members-
Posts
18 -
Joined
-
Last visited
stefaniv's Achievements
Newbie (1/7)
0
Reputation
-
Can someone edit this code,so that it simply gives a link to the .flv file from a url,that was submitted as $_POST['url']; ,because now it downloads the file to the server,I've been trying to figure it out myself,but this time I couldn't... Thanks <?phpclass youtubegrabber{ var $youtube_video_url; var $test; var $final_flv_filename; var $cookies_path; var $curl_headers; var $flv_url; function __construct($youtube_video_url, $final_flv_filename, $test = 0){ $this->youtube_video_url = $youtube_video_url; $this->test = $test; $this->final_flv_filename = $final_flv_filename; $this->youtube_video_id = $this->get_youtube_video_id(); $this->cookies_path = "cookies.txt"; $clear_cookies = $this->clear_cookies(); $this->curl_headers = array( "Accept-Language: en-us", "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Firefox/3.6.15", "Connection: Keep-Alive", "Cache-Control: no-cache" ); $this->flv_url = $this->get_flv_url(); $save_binary = $this->get_curl_binary(); $clear_cookies = $this->clear_cookies(); } function get_youtube_video_id(){ $thearray = explode("watch?v=", $this->youtube_video_url); return $thearray[1]; } function clear_cookies(){ if(file_exists($this->cookies_path)){ unlink($this->cookies_path); } $ourFileName = $this->cookies_path; $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fclose($ourFileHandle); } function get_flv_url(){ $html = $this->curl_get_url($this->youtube_video_url); preg_match_all("/var.*?swf.*?=.*?\"(.*?)watch-player.*?innerHTML.*?=.*?swf/is", $html, $matches); $decoded = urldecode($matches[1][0]); preg_match_all("/url=(.*?)\,/is", $decoded, $matches); $matches = $matches[1]; for($i = 0; $i < count($matches); $i++){ $test = explode("&", $matches[$i]); $matches[$i] = $test[0]; $matches[$i] = urldecode($matches[$i]); } $final_flv_url = ""; foreach($matches AS $this_url){ $headers = $this->curl_get_headers($this_url); $headers = split("\n", trim($headers)); foreach($headers as $line) { if (strtok($line, ':') == 'Content-Type') { $parts = explode(":", $line); $content_type = strtolower(trim($parts[1])); if ( $this->contains("video/x-flv", $content_type) ){ $final_flv_url = $this_url; return $final_flv_url; } } } } return false; } function curl_get_url($url){ $cookie_path = $this->cookies_path; $headers = $this->curl_headers; $ch = curl_init(); //$referer = 'http://www.google.com/search'; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // this pretends this scraper to be browser client IE6 on Windows XP, of course you can pretend to be other browsers just you have to know the correct headers //curl_setopt($get, CURLOPT_REFERER, $referer); // lie to the server that we are some visitor who arrived here through google search curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // set user agent //curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13"); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_path); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_path); curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true ); curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 5 ); $output = curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch); return $output; } function curl_get_headers($url){ $cookie_path = $this->cookies_path; $headers = $this->curl_headers; $ch = curl_init(); //$referer = 'http://www.google.com/search'; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_path); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_path); curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true ); curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 5 ); $results = curl_exec($ch); return $results; } function get_curl_binary(){ $url = $this->flv_url; $cookie_path = $this->cookies_path; $headers = $this->curl_headers; $final_flv_filename = $this->final_flv_filename; $ch = curl_init($url); $fp = fopen($final_flv_filename, "w"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true ); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_path); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_path); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // this pretends this scraper to be browser client IE6 on Windows XP, of course you can pretend to be other browsers just you have to know the correct headers curl_exec($ch); curl_close($ch); fclose($fp); } function contains($substring, $string) { $pos = strpos($string, $substring); if($pos === false) { // string needle NOT found in haystack return false; } else { // string needle found in haystack return true; } }}//$url = "http://www.youtube.com/watch?v=XZxo7IznQnk";//$filename = "test.flv";//$youtubegrabber = new youtubegrabber($url, $filename, 0);//echo "Should be done.<br>";?>
-
Hi ! It's me again... So there is this php code: $url = "http://google.com";$file = file($url);$file = implode("",$file);if(preg_match("/<title>(.+)<\/title>/i",$file,$m))print "<b>$m[1]";elseprint "No Title"; It works perfectly for every site except for http://vbox7.com ( Example: http://vbox7.com/play:7a98330863). Any ideas ?
-
*edit I fixed it myself.Thanks for the help guys,I really appreciate it.
-
Can you fix it for me,because i'm a newbie and i run my non-profit website,just because people are using it...Thanks in advance !
-
The function after elseif in the php file.Can you fix it for me ?
-
I have another problem: Here's my submit form: <script type="text/javascript"> jQuery(function (){ jQuery("#posturl").click(function (){ var link = jQuery("#link").val(); if(link.length!=0 && link!='Линк към vbox7 клипче'){ jQuery("#resp").slideDown("fast").html("<img src='load.gif' alt='loading' /> Зареждане.."); jQuery.post("getlink.php",{url:link},function(data){ jQuery("#resp").slideUp("fast").html(data).slideDown("fast"); }); }else{ alert("Въведи линк!"); } }); });</script><form method="post" action="javascript:;"><input type="text" name="url" id="link" value="Линк към vbox7 клипче" onclick="if(this.value=='Линк към vbox7 клипче'){this.value='';}" style="width: 300px" /><br><input type="submit" value="Покажи линкове" id="posturl" /><input type="submit" value="mp3" name="postmp" /><br /><span class="example">Пример: <b>http://vbox7.com/play:6f5aed4772 </span></form> The problem is that the second button is dead...Here's the php file <?phpfunction send_load_post($Host, $Uri, $SendVars){ $Result = array(); $ContentLength = strlen($SendVars); $ReqHeader = "POST $Uri HTTP/1.1\n" . "Host: $Host\n" . "Content-Type: application/x-www-form-urlencoded\n" . "Content-Length: $ContentLength\n\n" . "$SendVars\n"; $socket = fsockopen($Host, 80, &$errno, &$errstr); if (!$socket) { $Result["errno"] = $errno; $Result["errstr"] = $errstr; return false; } $idx = 0; fputs($socket, $ReqHeader); while (!feof($socket)) { $Result[$idx++] = fgets($socket, 128); } return $Result;} if (!$_POST['posturl']){ $url2 = $_POST['url']; $pr=preg_match_all('/http:\/\/vbox7.com\/play:(.*)/', $url2, $match); $Post = send_load_post('www.vbox7.com', 'http://www.vbox7.com/play/magare.do', 'vid='.$match[1][0]); foreach ($Post as $Row) { if (preg_match('/&videoFile=(.*)&/i', $Row, $found)) { $url = $found[1];$url = explode("&", $url);$url = $url[0]; echo "<br><br><a href=".$url." target=_new style=' color:#969696;font-size:14px'><b>Свали!</b></a><br />"; echo "Линк: <a href=".$url." target=_new style=' color:#969696;font-size:14px' >".$url."</a><br />"; echo "За да гледаш клипчетата ти е нужен <a href='http://search.data.bg/ready/3217b93884c69fb7c9b3a5f19490979e/FLV%20player%20setup.exe' target=_new style=' color: #969696; text-decoration: none;'>FLV player</a>"; echo "</font>"; break; } }}elseif (!$_POST['postmp']){ $url2 = $_POST['url']; $pr=preg_match_all('/http:\/\/vbox7.com\/play:(.*)/', $url2, $match); $Post = send_load_post('www.vbox7.com', 'http://www.vbox7.com/play/magare.do', 'vid='.$match[1][0]); foreach ($Post as $Row) { if (preg_match('/&videoFile=(.*)&/i', $Row, $found)) { $url = $found[1];$url = explode("&", $url);$url = $url[0];exec("/usr/local/bin/ffmpeg -i {$url} -y -acodec libmp3lame -ab 128k song.mp3"); echo "<br><br><a href='song.php' target=_new style=' color:#969696;font-size:14px'><b>Свали!</b></a><br />"; break; } }}?>
-
Ok,It works pefectly.But on chrome when i click on the link,the song starts to play on the chrome's integrated audio player.So is there some way i can force the download ? *edit I figured it out myself
-
It doesn't work,because the code that gives a link from youtube is not recent.Can you hook this code with mine that gives a link from vbox7 ?
-
It's already installed ,the exact path is /usr/local/bin/ffmpeg.And can you please tell me the exact functions needed to be permitted,because they ask me to number them...The exec() is already permitted.Thanks!
-
Warning: passthru() has been disabled for security reasons . Should i contact my hosting provider ?
-
I've checked.All functions are available.So can anyone edit this code ?
-
YouTubeToMp3Converter.class.php <?php [/color][/size][/font][/left][font="monospace"][size="2"][color="#0000bb"] // Conversion Class class YouTubeToMp3Converter { // Private Fields private $_songFileName = ''; private $_flvUrl = ''; private $_audioQualities = array(64, 128, 320); private $_tempVidFileName; private $_vidSrcTypes = array('source_code', 'url'); [/color][/size][/font][font="monospace"][size="2"][color="#0000bb"] // Constants const _TEMPVIDDIR = 'videos/'; const _SONGFILEDIR = 'mp3/'; const _FFMPEG = 'ffmpeg.exe'; #region Public Methods function __construct() { } function DownloadVideo($youTubeUrl) { $file_contents = file_get_contents($youTubeUrl); if ($file_contents !== false) { $this->SetSongFileName($file_contents); $this->SetFlvUrl($file_contents); if ($this->GetSongFileName() != '' && $this->GetFlvUrl() != '') { return $this->SaveVideo($this->GetFlvUrl()); } } return false; } function GenerateMP3($audioQuality) { $qualities = $this->GetAudioQualities(); $quality = (in_array($audioQuality, $qualities)) ? $audioQuality : $qualities[1]; $exec_string = self::_FFMPEG.' -i '.$this->GetTempVidFileName().' -y -acodec libmp3lame -ab '.$quality.'k '.$this->GetSongFileName(); exec($exec_string); $this->DeleteTempVid(); return is_file($this->GetSongFileName()); } function ExtractSongTrackName($vidSrc, $srcType) { $name = ''; $vidSrcTypes = $this->GetVidSrcTypes(); if (in_array($srcType, $vidSrcTypes)) { $vidSrc = ($srcType == $vidSrcTypes[1]) ? file_get_contents($vidSrc) : $vidSrc; if ($vidSrc !== false && eregi('eow-title',$vidSrc)) { $name = end(explode('eow-title',$vidSrc)); $name = current(explode('">',$name)); $name = ereg_replace('[^-_a-zA-Z,"\' :0-9]',"",end(explode('title="',$name))); } } return $name; } #endregion [/color][/size][/font][font="monospace"][size="2"][color="#0000bb"] #region Private "Helper" Methods private function SaveVideo($url) { $this->SetTempVidFileName(time()); $file = fopen($this->GetTempVidFileName(), 'w'); $ch = curl_init(); curl_setopt($ch, CURLOPT_FILE, $file); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIE); curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIE); curl_exec($ch); curl_close($ch); fclose($file); return is_file($this->GetTempVidFileName()); } private function DeleteTempVid() { if (is_file($this->GetTempVidFileName())) { unlink($this->GetTempVidFileName()); } } #endregion #region Properties public function GetSongFileName() { return $this->_songFileName; } private function SetSongFileName($file_contents) { $vidSrcTypes = $this->GetVidSrcTypes(); $trackName = $this->ExtractSongTrackName($file_contents, $vidSrcTypes[0]); $this->_songFileName = (!empty($trackName)) ? self::_SONGFILEDIR . preg_replace('/_{2,}/','_',preg_replace('/ /','_',preg_replace('/[^A-Za-z0-9 _-]/','',$trackName))) . '.mp3' : ''; } [/color][/size][/font][font="monospace"][size="2"][color="#0000bb"] public function GetFlvUrl() { return $this->_flvUrl; } private function SetFlvUrl($file_contents) { $vidUrl = ''; if (eregi('fmt_url_map',$file_contents)) { $vidUrl = end(explode('&fmt_url_map=',$file_contents)); $vidUrl = current(explode('&',$vidUrl)); $vidUrl = current(explode('%2C',$vidUrl)); $vidUrl = urldecode(end(explode('%7C',$vidUrl))); } $this->_flvUrl = $vidUrl; } public function GetAudioQualities() { return $this->_audioQualities; } private function GetTempVidFileName() { return $this->_tempVidFileName; } private function SetTempVidFileName($timestamp) { $this->_tempVidFileName = self::_TEMPVIDDIR . $timestamp .'.flv'; index.php <?php // Execution settings ini_set('max_execution_time',0); ini_set('display_errors',0); // On form submission... if ($_POST['submit']) { // Instantiate converter class include 'YouTubeToMp3Converter.class.php'; $converter = new YouTubeToMp3Converter(); // Print "please wait" message and preview image $vidID = $vidTitle = ''; $urlQueryStr = parse_url(trim($_POST['youtubeURL']), PHP_URL_QUERY); if ($urlQueryStr !== false && !empty($urlQueryStr)) { $kvPairs = explode('&', $urlQueryStr); foreach ($kvPairs as $v) { $kvPair = explode('=', $v); if ($kvPair[0] == 'v') { $vidID = $kvPair[1]; break; } }[/left] echo '<div id="preview" style="display:block"><p>...Please wait while I try to convert:</p>'; echo '<p><img src="http://img.youtube.com/vi/'.$vidID.'/1.jpg" alt="preview image" /></p>'; echo '<p>'.$converter->ExtractSongTrackName(trim($_POST['youtubeURL']), 'url').'</p></div>'; flush(); } // Main Program Execution if ($converter->DownloadVideo(trim($_POST['youtubeURL']))) { echo ($converter->GenerateMP3($_POST['quality'])) ? '<p>Success!</p>' : '<p>Error generating MP3 file!</p>'; } else { echo '<p>Error downloading video!</p>'; } } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <p>Enter a valid YouTube.com video URL:</p> <p><input type="text" name="youtubeURL" /></p> <p><i>(i.e., "<span style="color:red">http://www.youtube.com/watch?v=HMpmI2F2cMs</span>")</i></p> <p style="margin-top:20px">Choose the audio quality (better quality results in larger files):</p> <p style="margin-bottom:25px"><input type="radio" value="64" name="quality" />Low <input type="radio" value="128" name="quality" checked="checked" />Medium <input type="radio" value="320" name="quality" />High</p> <p><input type="submit" name="submit" value="Create MP3 File" /></p> </form> <script type="text/javascript"> window.onload = function() { if (document.getElementById('preview')) { document.getElementById('preview').style.display = 'none'; } }; </script> and my code: <?phpfunction send_load_post($Host, $Uri, $SendVars){ $Result = array(); $ContentLength = strlen($SendVars); $ReqHeader = "POST $Uri HTTP/1.1\n" . "Host: $Host\n" . "Content-Type: application/x-www-form-urlencoded\n" . "Content-Length: $ContentLength\n\n" . "$SendVars\n"; $socket = fsockopen($Host, 80, &$errno, &$errstr); if (!$socket) { $Result["errno"] = $errno; $Result["errstr"] = $errstr; return false; } $idx = 0; fputs($socket, $ReqHeader); while (!feof($socket)) { $Result[$idx++] = fgets($socket, 128); } return $Result;}if ($_POST['url']){ $url2 = $_POST['url']; $pr=preg_match_all('/http:\/\/vbox7.com\/play:(.*)/', $url2, $match); $Post = send_load_post('www.vbox7.com', 'http://www.vbox7.com/play/magare.do', 'vid='.$match[1][0]); foreach ($Post as $Row) { if (preg_match('/&videoFile=(.*)&/i', $Row, $found)) { $url = $found[1];$url = explode("&", $url);$url = $url[0]; echo "<br><br><a href=".$url." target=_new style=' color:#969696;font-size:14px'><b>Свали!</b></a><br />"; echo "Линк: <a href=".$url." target=_new style=' color:#969696;font-size:14px' >".$url."</a><br />"; echo "За да гледаш клипчетата ти е нужен <a href='http://search.data.bg/ready/3217b93884c69fb7c9b3a5f19490979e/FLV%20player%20setup.exe' target=_new style=' color: #969696; text-decoration: none;'>FLV player</a>"; echo "</font>"; break; } }}else{ }?> I'm using a paid hosting server using Linux.
-
It doesn't work,because it's an old code and youtube changed their video locations,but it was tested before and the transfer .flv to mp3 works.