stefaniv Posted April 23, 2012 Share Posted April 23, 2012 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 ? Link to comment Share on other sites More sharing options...
Ingolme Posted April 23, 2012 Share Posted April 23, 2012 Probably not. Link to comment Share on other sites More sharing options...
stefaniv Posted April 24, 2012 Author Share Posted April 24, 2012 Awww...You're so helpful,no wonder You're a Moderator. Link to comment Share on other sites More sharing options...
thescientist Posted April 24, 2012 Share Posted April 24, 2012 (edited) what did you expect? Most of would say the same thing. People are here to help you with the work (when you have specific questions about specific problems), not do it for you. Edited April 24, 2012 by thescientist Link to comment Share on other sites More sharing options...
boen_robot Posted April 24, 2012 Share Posted April 24, 2012 Sarcasm aside... what Ingolme meant to say is that you're asking for too much. This is a process that involves dealing with file uploads, encoders, converters, and actually chaining all those somehow, which is next to impossible unless you fully control the computer your script will run.Once you have a computer that you control as your server (some hosts offer a "dedicated server", which is essentially the same thing), find an encoding application that can take FLV as input and produce MP3 as output from the command line or another automatable fashion, and hook it up to the script.If you get the encoder, we can help with the "hook it up" part. Link to comment Share on other sites More sharing options...
divinedesigns1 Posted April 24, 2012 Share Posted April 24, 2012 Sarcasm aside... what Ingolme meant to say is that you're asking for too much. This is a process that involves dealing with file uploads, encoders, converters, and actually chaining all those somehow, which is next to impossible unless you fully control the computer your script will run. Once you have a computer that you control as your server (some hosts offer a "dedicated server", which is essentially the same thing), find an encoding application that can take FLV as input and produce MP3 as output from the command line or another automatable fashion, and hook it up to the script. If you get the encoder, we can help with the "hook it up" part. curiousity strikes again - so what would i have to look for, so i can actually sit and see how it is done? or what do i have to learn to actually try and make this possible? wait wasnt this what that guy should of ask? anyway back to my curiousity, so what do i need to learn or what do i need to look up to fine a tutorial on this ? i dont mind sitting here and looking up what every function does at all so Link to comment Share on other sites More sharing options...
boen_robot Posted April 24, 2012 Share Posted April 24, 2012 The heart of it is the proc_open() function, which can execute an arbitrary program from the command line (also sometimes erroneously being called "DOS" by non-developers - and yes, by that I mean otherwise computer literate people).If you don't know how this looks and/or how to deal with it, go to "Start > All Programs > Accessories > Command Prompt", type "help" and hit enter to see the available commands. In addition to those, if you know the path to a program, you can type it out (surrounded with quotes... just in case) and once you hit enter, the program will be executed.Some programs, instead of opening a window, remain in the command prompt... maybe they'll output something on screen, but the point is they'll eventually close down without requiring you to hit a button or whatever, thus allowing you to execute further commands. "help" is actually such a program.So whenever you need to do something as fancy as converting an FLV to MP3... if you have a program that runs on the command line, you can make PHP execute it. Most hosts disable the proc_open() function, and the rest of the similar functions, as you can execute any program, including ones that might potentially affect the whole server. Link to comment Share on other sites More sharing options...
stefaniv Posted April 24, 2012 Author Share Posted April 24, 2012 (edited) 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 ! Edited April 24, 2012 by stefaniv Link to comment Share on other sites More sharing options...
boen_robot Posted April 24, 2012 Share Posted April 24, 2012 Argh... my eyes!!! Remove those bolds from the code!!!Also, have you actually tested if this code works for YouTube? I mean if it works at the "live" server (where the vobx7 script will end up)? Link to comment Share on other sites More sharing options...
stefaniv Posted April 24, 2012 Author Share Posted April 24, 2012 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. Link to comment Share on other sites More sharing options...
justsomeguy Posted April 24, 2012 Share Posted April 24, 2012 The key to that code is the reference to the ffmpeg.exe program, which does the majority of the work. That means that you need to have ffmpeg installed on your server if it's not already there, which you can download here: http://ffmpeg.org/download.html That also specifically references "ffmpeg.exe", so it looks like it expects to be run on a Windows server. If your server is a Linux server then you'll need to change the path to reflect the location and name of where you installed ffmpeg. That code uses exec rather than proc_open to run ffmpeg. So the first step is to make sure that ffmpeg is installed and working on your server, and that you are allowed to use the exec function in PHP. If you can't install ffmpeg or you're not allowed to use exec then you need to move to a new server that will allow you to do those things. Other than that, the code you posted really is difficult to read because of all the BBcode bold tags, you'll need to re-post the code without that in order for us to be able to really help with it. Link to comment Share on other sites More sharing options...
stefaniv Posted April 24, 2012 Author Share Posted April 24, 2012 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. Link to comment Share on other sites More sharing options...
divinedesigns1 Posted April 25, 2012 Share Posted April 25, 2012 thank you for the explaination boen Link to comment Share on other sites More sharing options...
boen_robot Posted April 25, 2012 Share Posted April 25, 2012 I'm using a paid hosting server using Linux.Then contact your host to make sure they have "ffmpeg" available, and ask them to make it available if it's not. Also make sure they allow you to use exec() and related functions. Link to comment Share on other sites More sharing options...
stefaniv Posted April 25, 2012 Author Share Posted April 25, 2012 I've checked.All functions are available.So can anyone edit this code ? Link to comment Share on other sites More sharing options...
boen_robot Posted April 25, 2012 Share Posted April 25, 2012 The executable is what's more important.To put this in another way, make a separate file, and do <?phppassthru('ffmpeg');?> And see if this produces a summary of FFMPEG's help. Link to comment Share on other sites More sharing options...
stefaniv Posted April 25, 2012 Author Share Posted April 25, 2012 Warning: passthru() has been disabled for security reasons . Should i contact my hosting provider ? Link to comment Share on other sites More sharing options...
boen_robot Posted April 25, 2012 Share Posted April 25, 2012 Yes. That's exactly what we've been trying to say in the last few posts.Contact your hosting provider, ask them about these functions AND ask them to provide a linux binary of ffmpeg.The PHP script is completely useless without these things... useless not just for vbox7, but for YouTube as well. Link to comment Share on other sites More sharing options...
stefaniv Posted April 26, 2012 Author Share Posted April 26, 2012 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! Link to comment Share on other sites More sharing options...
boen_robot Posted April 26, 2012 Share Posted April 26, 2012 If exec() is already permitted, that's enough... although I have to wonder why are they permitting exec(), and not the rest... it's not like exec() can do any less damage than proc_open(), system() or passthru()... nevermind.First, change const _FFMPEG = 'ffmpeg.exe'; to const _FFMPEG = '/usr/local/bin/ffmpeg'; And see if YouTube works.The point is that if YouTube works, all you really need to do is adjust the URLs to match vbox's URLs instead of YouTube's. If it doesn't work even for YouTube, there might be more to it. Link to comment Share on other sites More sharing options...
stefaniv Posted April 26, 2012 Author Share Posted April 26, 2012 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 ? Link to comment Share on other sites More sharing options...
boen_robot Posted April 26, 2012 Share Posted April 26, 2012 Does the $url in your part of code have the correct URL for the FLV file? Assuming it does, the following line should do it: exec("/usr/local/bin/ffmpeg -i {$url} -y -acodec libmp3lame -ab 128k song.mp3"); (adjust song.mp3 to the name you want the MP3 to have; if you want another quality, replace 128k with that quality) Link to comment Share on other sites More sharing options...
stefaniv Posted April 27, 2012 Author Share Posted April 27, 2012 (edited) 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 Edited April 27, 2012 by stefaniv Link to comment Share on other sites More sharing options...
stefaniv Posted April 27, 2012 Author Share Posted April 27, 2012 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; } }}?> Link to comment Share on other sites More sharing options...
justsomeguy Posted April 27, 2012 Share Posted April 27, 2012 What should the button do? There's no Javascript code attached to it, and the form is set up so that it will not submit. So, it's doing what the code is telling it to do. What should it be doing? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now