Web Analytics Made Easy -
StatCounter YouTube-to-MP3 conversion - PHP class and script - CodingForum

Announcement

Collapse
No announcement yet.

YouTube-to-MP3 conversion - PHP class and script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ffmpeg

    hello,

    i use ffmpeg and ffmpeg-php , to convert i use normaly ffmpeg without php support.

    I have linux can you say me a way in your script that works with linux and not with an .exe (windows). I have debian (linux).

    thank you

    Comment


    • I have not tried to run this application in anything other than XAMPP for Windows (because I only use it for my own personal use). The script is provided as is. If you need the script to run on a Linux server, there are ways to install FFmpeg on Linux / Debian. Once installed, you may also have to modify the relevant script code (as I indicated earlier).
      Last edited by chump2877; Sep 17th, 2011, 01:46 PM.
      Regards, R.J.

      ---------------------------------------------------------

      Help spread the word! Like our YouTube-to-Mp3 Conversion Script on Facebook !! :-)
      [Instructional videos and tutorials are also available on YouTube, Dailymotion, and Vimeo]
      Explore all products and services, view demos, review documentation, check prices, and more!
      ♪♪ …Need Web Hosting For Our YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

      Comment


      • Hi chump2877,

        Is your script still working. I have tried debugging your code and it seems to be failing at;

        eregi('fmt_url_map',$file_contents);

        fmt_url_map does not even exist in the page.

        Any suggestions?

        Comment


        • Originally posted by missenlinx View Post
          Hi chump2877,

          Is your script still working. I have tried debugging your code and it seems to be failing at;

          eregi('fmt_url_map',$file_contents);

          fmt_url_map does not even exist in the page.

          Any suggestions?
          Please use the latest version of the code. You are using an older version.
          Regards, R.J.

          ---------------------------------------------------------

          Help spread the word! Like our YouTube-to-Mp3 Conversion Script on Facebook !! :-)
          [Instructional videos and tutorials are also available on YouTube, Dailymotion, and Vimeo]
          Explore all products and services, view demos, review documentation, check prices, and more!
          ♪♪ …Need Web Hosting For Our YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

          Comment


          • @chump2877: First of all thanks for the code, it works like a charm. You really are the PHP master =D

            I have one question about youtube video size. Can you get/read flv size before you download the video on your computer? Is there any way to do that?

            Thank you,
            Tony

            Comment


            • YouTube recently changed the front end of their site again. The following fix to my code is required:

              PHP Code:
                      private function SetFlvUrl($file_contents)
                      {
                          
              $vidUrl '';
                          if (
              eregi('"url_encoded_fmt_stream_map": "url=',$file_contents))
                          {
                              
              $vidUrl end(explode('"url_encoded_fmt_stream_map": "url=',$file_contents));
                              
              $vidUrl urldecode(urldecode(current(explode('\u0026',$vidUrl))));
                          }
                          
              $this->_flvUrl $vidUrl;
                      } 
              Download the revised YouTubeToMp3Converter.class.php below! ...And please let me know if you experience any issues with the code....
              Attached Files
              Regards, R.J.

              ---------------------------------------------------------

              Help spread the word! Like our YouTube-to-Mp3 Conversion Script on Facebook !! :-)
              [Instructional videos and tutorials are also available on YouTube, Dailymotion, and Vimeo]
              Explore all products and services, view demos, review documentation, check prices, and more!
              ♪♪ …Need Web Hosting For Our YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

              Comment


              • Originally posted by itsmeanthony View Post
                @chump2877: First of all thanks for the code, it works like a charm. You really are the PHP master =D

                I have one question about youtube video size. Can you get/read flv size before you download the video on your computer? Is there any way to do that?

                Thank you,
                Tony
                Hi Tony,

                My first inclination would be to try and acquire that kind of information via the YouTube API. For example, here is the API-way to grab a variety of data pertaining to a particular video. Further exploration reveals all of the possible data that can be retrieved for a given video "entry" object. Unfortunately, the API does not appear to provide individual video file size information (I think that's what you are after?). But you might try digging around a little more and see if I missed something.

                Apart from the API you might try the following link. This solution looks promising because it involves cURL (which my script already uses to download videos), so you might incorporate this technique into the SaveVideo method, just prior to actually downloading the video. There you could institute a check for file size, and if the size was either too big (or too small?), then you could cancel the video save operation and make the method return false.
                Regards, R.J.

                ---------------------------------------------------------

                Help spread the word! Like our YouTube-to-Mp3 Conversion Script on Facebook !! :-)
                [Instructional videos and tutorials are also available on YouTube, Dailymotion, and Vimeo]
                Explore all products and services, view demos, review documentation, check prices, and more!
                ♪♪ …Need Web Hosting For Our YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

                Comment


                • didnt work.

                  it didnt work.help me.

                  Comment


                  • it didnt work.help me.
                    Just tried it here again, and it works fine.

                    And please: If you are going to request help, kindly describe the specific issue(s) that you are having. I almost didn't bother replying to your post because of the lack of effort that went into it. Thanks!
                    Last edited by chump2877; Dec 10th, 2011, 03:23 AM.
                    Regards, R.J.

                    ---------------------------------------------------------

                    Help spread the word! Like our YouTube-to-Mp3 Conversion Script on Facebook !! :-)
                    [Instructional videos and tutorials are also available on YouTube, Dailymotion, and Vimeo]
                    Explore all products and services, view demos, review documentation, check prices, and more!
                    ♪♪ …Need Web Hosting For Our YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

                    Comment


                    • Hey chump, This is a great script but i'm having a problem, i'm not amazing at php and the conversion works perfectly its just i can't seem to get it to make a download.
                      I saw some posts about making a link to it, and then you replyed with a link to some php forum and how to do it but i just don't understand it.

                      Basicly i need a link after the conversion finished like "DOWNLOAD NOW" that is linked to the mp3 that they just converted, If this helps i'm hosting the website on a shared host.

                      Please help as soon as possible Thankyou

                      Comment


                      • Originally posted by jibreel View Post
                        Basicly i need a link after the conversion finished like "DOWNLOAD NOW" that is linked to the mp3 that they just converted, If this helps i'm hosting the website on a shared host.
                        I've gotten several requests for this feature, so I have modified the code as follows:

                        1) Added download link after successful conversion
                        2) Added conversion process progress bar
                        3) Some general refactoring of code

                        Download the revised files below. ...And please let me know if you experience any issues with the code....

                        Happy Holidays!

                        Edit: The progress bar feature will only work for PHP versions 5.3 and above. To disable the progress bar, you need only comment out the following lines of code in YouTubeToMp3Converter.class.php:

                        PHP Code:
                                private function SaveVideo($url)
                                {
                                    
                        $this->_percentVidDownloaded 0;
                                    
                        $this->SetTempVidFileName(time());
                                    
                        $file fopen($this->GetTempVidFileName(), 'w');
                                    
                        $ch curl_init();
                                    
                        curl_setopt($chCURLOPT_FILE$file);
                                    
                        curl_setopt($chCURLOPT_HEADER0);
                                    
                        curl_setopt($chCURLOPT_URL$url);
                                    
                        curl_setopt($chCURLOPT_FOLLOWLOCATION1);
                                    
                        //curl_setopt($ch, CURLOPT_NOPROGRESS, false);
                                    //curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, array($this, 'UpdateVideoDownloadProgress'));
                                    //curl_setopt($ch, CURLOPT_BUFFERSIZE, 4096000);
                                    
                        curl_exec($ch);
                                    
                        curl_close($ch);
                                    
                        fclose($file);
                                    return 
                        is_file($this->GetTempVidFileName());
                                } 
                        ...and change the following line of code in index.php:
                        PHP Code:
                        echo '<div id="progress-bar"><div id="progress">0%</div></div></div>'
                        ...to:
                        PHP Code:
                        echo '</div>'
                        Attached Files
                        Last edited by chump2877; Dec 26th, 2011, 01:05 AM.
                        Regards, R.J.

                        ---------------------------------------------------------

                        Help spread the word! Like our YouTube-to-Mp3 Conversion Script on Facebook !! :-)
                        [Instructional videos and tutorials are also available on YouTube, Dailymotion, and Vimeo]
                        Explore all products and services, view demos, review documentation, check prices, and more!
                        ♪♪ …Need Web Hosting For Our YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

                        Comment


                        • Thankyou chump, But im afraid that has not fixed my problem.
                          My website is www.free-youtube-mp3.org

                          My website folder consists of the index.php and the youtubetomp3converter.class.php that you sent me, aswell as Mp3 and videos folder that have full writes.

                          When i press convert it takes time, then a page full of codes comes up :/ please help


                          - After attempting to convert the video and apart from what i said up above an error log appeared in my files on my shared server and i saw this when i was using filezilla. I'm giving the mp3 file full permission (777) but i don't think it saves the permission?.
                          Error Log-
                          [25-Dec-2011 06:29:13] PHP Warning: fopen(videos/1324816153.flv) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: No such file or directory in /home/freeyou1/public_html/YouTubeToMp3Converter.class.php on line 101
                          [25-Dec-2011 06:29:13] PHP Warning: curl_setopt(): supplied argument is not a valid File-Handle resource in /home/freeyou1/public_html/YouTubeToMp3Converter.class.php on line 103
                          [25-Dec-2011 06:29:16] PHP Warning: fclose(): supplied argument is not a valid stream resource in /home/freeyou1/public_html/YouTubeToMp3Converter.class.php on line 111
                          Last edited by jibreel; Dec 25th, 2011, 07:37 AM. Reason: more information.

                          Comment


                          • It looks like something is going wrong with cURL when the FLV file is being downloaded from YouTube. The likely offending code is in the SaveVideo() method:

                            PHP Code:
                                        $file fopen($this->GetTempVidFileName(), 'w');
                                        
                            $ch curl_init();
                                        
                            curl_setopt($chCURLOPT_FILE$file);
                                        
                            curl_setopt($chCURLOPT_HEADER0);
                                        
                            curl_setopt($chCURLOPT_URL$url);
                                        
                            curl_setopt($chCURLOPT_FOLLOWLOCATION1);
                                        
                            curl_setopt($chCURLOPT_NOPROGRESSfalse);
                                        
                            curl_setopt($chCURLOPT_PROGRESSFUNCTION, array($this'UpdateVideoDownloadProgress'));
                                        
                            curl_setopt($chCURLOPT_BUFFERSIZE256);
                                        
                            curl_exec($ch); 
                            Are you sure you have cURL enabled, or running correctly, for your server's PHP installation?

                            Can you use cURL to read from and write to any other files?

                            Can you use fopen() to open and create other files?

                            That's all I have off the top of my head. I run the code here with no issues.
                            Regards, R.J.

                            ---------------------------------------------------------

                            Help spread the word! Like our YouTube-to-Mp3 Conversion Script on Facebook !! :-)
                            [Instructional videos and tutorials are also available on YouTube, Dailymotion, and Vimeo]
                            Explore all products and services, view demos, review documentation, check prices, and more!
                            ♪♪ …Need Web Hosting For Our YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

                            Comment


                            • Sorry for making you waste your time by assisting me but i'm not good at these type of things, And yes Curl is enabled.

                              I think i'v just mixed the wrong files up, Sorry for asking but would it be tomuch to ask if you uploaded the full website folder with all the files in it needed to work, Please

                              If not it's fine i'll just keep trying :/

                              Comment


                              • Are your 'videos' and 'mp3' folders directly in '/home/freeyou1/public_html/' (your web root)? They should be. Your errors indicate that perhaps these directories are elsewhere...

                                The required directory structure for all files/directories involved is outlined in the the first post of this thread.

                                BTW - I just added a progress bar to 12-25-11.zip distribution, so you may want to download the zip again to get the updated files with progress bar included.
                                Regards, R.J.

                                ---------------------------------------------------------

                                Help spread the word! Like our YouTube-to-Mp3 Conversion Script on Facebook !! :-)
                                [Instructional videos and tutorials are also available on YouTube, Dailymotion, and Vimeo]
                                Explore all products and services, view demos, review documentation, check prices, and more!
                                ♪♪ …Need Web Hosting For Our YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

                                Comment

                                Working...
                                X