![](http://content.invisioncic.com/r49260/set_resources_1/84c1e40ea0e759e3f1505eb1788ddf3c_pattern.png)
stefaniv
-
Posts
18 -
Joined
-
Last visited
Content Type
Profiles
Forums
Events
Posts posted by stefaniv
-
-
flv to mp3
in PHP
How ?
-
flv to mp3
in PHP
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>";?>
-
Grab title
in PHP
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 ?
-
flv to mp3
in PHP
*edit I fixed it myself.Thanks for the help guys,I really appreciate it.
-
flv to mp3
in PHP
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 !
-
flv to mp3
in PHP
The function after elseif in the php file.Can you fix it for me ?
-
flv to mp3
in PHP
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; } }}?>
-
flv to mp3
in PHP
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
-
flv to mp3
in PHP
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 ?
-
flv to mp3
in PHP
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!
-
flv to mp3
in PHP
Warning: passthru() has been disabled for security reasons . Should i contact my hosting provider ?
-
flv to mp3
in PHP
I've checked.All functions are available.So can anyone edit this code ?
-
flv to mp3
in PHP
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.
-
flv to mp3
in PHP
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.
-
flv to mp3
in PHP
Ok,Sorry.I have another script,but it gets a link from youtube,and not from the site my code gets a link,i'll give it all to you + my download code that i wish to hook up with the previous.Hope you can help doing it,I'll really appreciate it. YouTubeToMp3Converter.class.php
[/b][/b][b][b]<?php [/b][/b][/b][b][b][b] // Conversion Class[/b][/b][b][b] class YouTubeToMp3Converter[/b][/b][b][b] {[/b][/b][b][b] // Private Fields[/b][/b][b][b] private $_songFileName = '';[/b][/b][b][b] private $_flvUrl = '';[/b][/b][b][b] private $_audioQualities = array(64, 128, 320);[/b][/b][b][b] private $_tempVidFileName;[/b][/b][b][b] private $_vidSrcTypes = array('source_code', 'url'); [/b][/b][/b][b][b][b] // Constants[/b][/b][b][b] const _TEMPVIDDIR = 'videos/';[/b][/b][b][b] const _SONGFILEDIR = 'mp3/';[/b][/b][b][b] const _FFMPEG = 'ffmpeg.exe';[/b][/b][b][b] [/b][/b][b][b] #region Public Methods[/b][/b][b][b] function __construct()[/b][/b][b][b] {[/b][/b][b][b] }[/b][/b][b][b] [/b][/b][b][b] function DownloadVideo($youTubeUrl)[/b][/b][b][b] {[/b][/b][b][b] $file_contents = file_get_contents($youTubeUrl);[/b][/b][b][b] if ($file_contents !== false)[/b][/b][b][b] {[/b][/b][b][b] $this->SetSongFileName($file_contents);[/b][/b][b][b] $this->SetFlvUrl($file_contents);[/b][/b][b][b] if ($this->GetSongFileName() != '' && $this->GetFlvUrl() != '')[/b][/b][b][b] {[/b][/b][b][b] return $this->SaveVideo($this->GetFlvUrl());[/b][/b][b][b] }[/b][/b][b][b] }[/b][/b][b][b] return false;[/b][/b][b][b] } [/b][/b][b][b] [/b][/b][b][b] function GenerateMP3($audioQuality)[/b][/b][b][b] {[/b][/b][b][b] $qualities = $this->GetAudioQualities();[/b][/b][b][b] $quality = (in_array($audioQuality, $qualities)) ? $audioQuality : $qualities[1]; [/b][/b][b][b] $exec_string = self::_FFMPEG.' -i '.$this->GetTempVidFileName().' -y -acodec libmp3lame -ab '.$quality.'k '.$this->GetSongFileName();[/b][/b][b][b] exec($exec_string);[/b][/b][b][b] $this->DeleteTempVid();[/b][/b][b][b] return is_file($this->GetSongFileName());[/b][/b][b][b] }[/b][/b][b][b] [/b][/b][b][b] function ExtractSongTrackName($vidSrc, $srcType)[/b][/b][b][b] {[/b][/b][b][b] $name = '';[/b][/b][b][b] $vidSrcTypes = $this->GetVidSrcTypes();[/b][/b][b][b] if (in_array($srcType, $vidSrcTypes))[/b][/b][b][b] {[/b][/b][b][b] $vidSrc = ($srcType == $vidSrcTypes[1]) ? file_get_contents($vidSrc) : $vidSrc;[/b][/b][b][b] if ($vidSrc !== false && eregi('eow-title',$vidSrc))[/b][/b][b][b] {[/b][/b][b][b] $name = end(explode('eow-title',$vidSrc));[/b][/b][b][b] $name = current(explode('">',$name));[/b][/b][b][b] $name = ereg_replace('[^-_a-zA-Z,"\' :0-9]',"",end(explode('title="',$name)));[/b][/b][b][b] }[/b][/b][b][b] }[/b][/b][b][b] return $name;[/b][/b][b][b] } [/b][/b][b][b] #endregion [/b][/b][/b][b][b][b] #region Private "Helper" Methods[/b][/b][b][b] private function SaveVideo($url)[/b][/b][b][b] {[/b][/b][b][b] $this->SetTempVidFileName(time());[/b][/b][b][b] $file = fopen($this->GetTempVidFileName(), 'w');[/b][/b][b][b] $ch = curl_init();[/b][/b][b][b] curl_setopt($ch, CURLOPT_FILE, $file);[/b][/b][b][b] curl_setopt($ch, CURLOPT_HEADER, 0);[/b][/b][b][b] curl_setopt($ch, CURLOPT_URL, $url);[/b][/b][b][b] curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);[/b][/b][b][b] curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIE);[/b][/b][b][b] curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIE);[/b][/b][b][b] curl_exec($ch);[/b][/b][b][b] curl_close($ch);[/b][/b][b][b] fclose($file);[/b][/b][b][b] return is_file($this->GetTempVidFileName());[/b][/b][b][b] }[/b][/b][b][b] [/b][/b][b][b] private function DeleteTempVid()[/b][/b][b][b] {[/b][/b][b][b] if (is_file($this->GetTempVidFileName())) [/b][/b][b][b] {[/b][/b][b][b] unlink($this->GetTempVidFileName());[/b][/b][b][b] } [/b][/b][b][b] }[/b][/b][b][b] #endregion[/b][/b][b][b] [/b][/b][b][b] #region Properties[/b][/b][b][b] public function GetSongFileName()[/b][/b][b][b] {[/b][/b][b][b] return $this->_songFileName;[/b][/b][b][b] } [/b][/b][b][b] private function SetSongFileName($file_contents)[/b][/b][b][b] {[/b][/b][b][b] $vidSrcTypes = $this->GetVidSrcTypes();[/b][/b][b][b] $trackName = $this->ExtractSongTrackName($file_contents, $vidSrcTypes[0]);[/b][/b][b][b] $this->_songFileName = (!empty($trackName)) ? self::_SONGFILEDIR . preg_replace('/_{2,}/','_',preg_replace('/ /','_',preg_replace('/[^A-Za-z0-9 _-]/','',$trackName))) . '.mp3' : '';[/b][/b][b][b] } [/b][/b][/b][b][b][b] public function GetFlvUrl()[/b][/b][b][b] {[/b][/b][b][b] return $this->_flvUrl;[/b][/b][b][b] } [/b][/b][b][b] private function SetFlvUrl($file_contents)[/b][/b][b][b] { [/b][/b][b][b] $vidUrl = '';[/b][/b][b][b] if (eregi('fmt_url_map',$file_contents))[/b][/b][b][b] {[/b][/b][b][b] $vidUrl = end(explode('&fmt_url_map=',$file_contents));[/b][/b][b][b] $vidUrl = current(explode('&',$vidUrl));[/b][/b][b][b] $vidUrl = current(explode('%2C',$vidUrl));[/b][/b][b][b] $vidUrl = urldecode(end(explode('%7C',$vidUrl)));[/b][/b][b][b] }[/b][/b][b][b] $this->_flvUrl = $vidUrl;[/b][/b][b][b] }[/b][/b][b][b] [/b][/b][b][b] public function GetAudioQualities()[/b][/b][b][b] {[/b][/b][b][b] return $this->_audioQualities;[/b][/b][b][b] } [/b][/b][b][b] [/b][/b][b][b] private function GetTempVidFileName()[/b][/b][b][b] {[/b][/b][b][b] return $this->_tempVidFileName;[/b][/b][b][b] }[/b][/b][b][b] private function SetTempVidFileName($timestamp)[/b][/b][b][b] {[/b][/b][b][b] $this->_tempVidFileName = self::_TEMPVIDDIR . $timestamp .'.flv';[/b][/b][b][b] }[/b][/b][b][b] [/b][/b][b][b] public function GetVidSrcTypes()[/b][/b][b][b] {[/b][/b][b][b] return $this->_vidSrcTypes;[/b][/b][b][b] }[/b][/b][b][b] #endregion[/b][/b][b][b] }[/b][/b][b][b] [/b][/b][b][b]?>[/b][/b][b][b]
index.php
[/b][/b][b][b] <?php[/b][/b][b][b] // Execution settings[/b][/b][b][b] ini_set('max_execution_time',0);[/b][/b][b][b] ini_set('display_errors',0); [/b][/b][b][b] [/b][/b][b][b] // On form submission...[/b][/b][b][b] if ($_POST['submit'])[/b][/b][b][b] {[/b][/b][b][b] // Instantiate converter class[/b][/b][b][b] include 'YouTubeToMp3Converter.class.php';[/b][/b][b][b] $converter = new YouTubeToMp3Converter(); [/b][/b][b][b] [/b][/b][b][b] // Print "please wait" message and preview image[/b][/b][b][b] $vidID = $vidTitle = '';[/b][/b][b][b] $urlQueryStr = parse_url(trim($_POST['youtubeURL']), PHP_URL_QUERY);[/b][/b][b][b] if ($urlQueryStr !== false && !empty($urlQueryStr))[/b][/b][b][b] {[/b][/b][b][b] $kvPairs = explode('&', $urlQueryStr);[/b][/b][b][b] foreach ($kvPairs as $v)[/b][/b][b][b] {[/b][/b][b][b] $kvPair = explode('=', $v);[/b][/b][b][b] if ($kvPair[0] == 'v')[/b][/b][b][b] {[/b][/b][b][b] $vidID = $kvPair[1];[/b][/b][b][b] break;[/b][/b][b][b] }[/b][/b][b][b] } [/b][/b][/b][b][b][b] echo '<div id="preview" style="display:block"><p>...Please wait while I try to convert:</p>';[/b][/b][b][b] echo '<p><img src="http://img.youtube.com/vi/'.$vidID.'/1.jpg" alt="preview image" /></p>';[/b][/b][b][b] echo '<p>'.$converter->ExtractSongTrackName(trim($_POST['youtubeURL']), 'url').'</p></div>';[/b][/b][b][b] flush();[/b][/b][b][b] }[/b][/b][b][b] [/b][/b][b][b] // Main Program Execution[/b][/b][b][b] if ($converter->DownloadVideo(trim($_POST['youtubeURL'])))[/b][/b][b][b] {[/b][/b][b][b] echo ($converter->GenerateMP3($_POST['quality'])) ? '<p>Success!</p>' : '<p>Error generating MP3 file!</p>';[/b][/b][b][b] }[/b][/b][b][b] else[/b][/b][b][b] {[/b][/b][b][b] echo '<p>Error downloading video!</p>';[/b][/b][b][b] }[/b][/b][b][b] }[/b][/b][b][b] ?>[/b][/b][b][b] <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">[/b][/b][b][b] <p>Enter a valid YouTube.com video URL:</p>[/b][/b][b][b] <p><input type="text" name="youtubeURL" /></p>[/b][/b][b][b] <p><i>(i.e., "<span style="color:red">http://www.youtube.com/watch?v=HMpmI2F2cMs</span>")</i></p>[/b][/b][b][b] <p style="margin-top:20px">Choose the audio quality (better quality results in larger files):</p>[/b][/b][b][b] <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>[/b][/b][b][b] <p><input type="submit" name="submit" value="Create MP3 File" /></p>[/b][/b][b][b] </form>[/b][/b][b][b] <script type="text/javascript">[/b][/b][b][b] window.onload = function()[/b][/b][b][b] {[/b][/b][b][b] if (document.getElementById('preview'))[/b][/b][b][b] {[/b][/b][b][b] document.getElementById('preview').style.display = 'none';[/b][/b][b][b] }[/b][/b][b][b] };[/b][/b][b][b] </script>[/b][/b][b][b]
I want it all to work with my simple code,that gives a link to the .flv file:
[/b][/b][b][b]<?php[/b][/b][b][b]function send_load_post($Host, $Uri, $SendVars)[/b][/b][b][b]{[/b][/b][b][b] $Result = array();[/b][/b][b][b] $ContentLength = strlen($SendVars);[/b][/b][b][b] $ReqHeader = "POST $Uri HTTP/1.1\n" . "Host: $Host\n" .[/b][/b][b][b] "Content-Type: application/x-www-form-urlencoded\n" . "Content-Length: $ContentLength\n\n" .[/b][/b][b][b] "$SendVars\n";[/b][/b][b][b] $socket = fsockopen($Host, 80, &$errno, &$errstr);[/b][/b][b][b] if (!$socket)[/b][/b][b][b] {[/b][/b][b][b] $Result["errno"] = $errno;[/b][/b][b][b] $Result["errstr"] = $errstr;[/b][/b][b][b] return false;[/b][/b][b][b] }[/b][/b][b][b] $idx = 0;[/b][/b][b][b] fputs($socket, $ReqHeader);[/b][/b][b][b] while (!feof($socket))[/b][/b][b][b] {[/b][/b][b][b] $Result[$idx++] = fgets($socket, 128);[/b][/b][b][b] }[/b][/b][b][b] return $Result;[/b][/b][b][b]}[/b][/b][/b] [b][b][b]if ($_POST['url'])[/b][/b][b][b]{[/b][/b][b][b] $url2 = $_POST['url'];[/b][/b][b][b] $pr=preg_match_all('/http:\/\/vbox7.com\/play:(.*)/', $url2, $match);[/b][/b][b][b] $Post = send_load_post('www.vbox7.com', 'http://www.vbox7.com/play/magare.do',[/b][/b][b][b] 'vid='.$match[1][0]);[/b][/b][b][b] foreach ($Post as $Row)[/b][/b][b][b] {[/b][/b][b][b] if (preg_match('/&videoFile=(.*)&/i', $Row, $found))[/b][/b][b][b] {[/b][/b][b][b] $url = $found[1];[/b][/b][b][b]$url = explode("&", $url);[/b][/b][b][b]$url = $url[0];[/b][/b][b][b] echo "<br><br><a href=".$url." target=_new style=' color:#969696;font-size:14px'><b>Свали!</b></a><br />";[/b][/b][b][b] echo "Линк: <a href=".$url." target=_new style=' color:#969696;font-size:14px' >".$url."</a><br />";[/b][/b][b][b] echo "За да гледаш клипчетата ти е нужен <a href='http://search.data.bg/ready/3217b93884c69fb7c9b3a5f19490979e/FLV%20player%20setup.exe' target=_new style=' color: #969696; text-decoration: none;'>FLV player</a>";[/b][/b][b][b] echo "</font>";[/b][/b][b][b] break;[/b][/b][b][b] }[/b][/b][b][b] }[/b][/b][b][b]}[/b][/b][b][b]else[/b][/b][/b][b][b][b]{[/b][/b][/b][b][b][b]}[/b][/b][/b][b][b][b]?>[/b][/b][b][b]
Once again,I'll be very grateful if you can help me to do that.I have a small site that helps people to download videos from a popular bulgarian video site,but i've recieved a lot of emails that ask if i can create a service that will help them download the .flv files like .mp3 files.Thank you in advance !
-
flv to mp3
in PHP
Awww...You're so helpful,no wonder You're a Moderator.
-
flv to mp3
in PHP
Can someone give me a code that downloads a flv file from a generated link($url),transfers it to mp3 then deletes the flv file after the operation is finished and gives a link to the mp3 file ?
Grab title
in PHP
Posted
Gives the result "No title"