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

  • how many i pay you for this..?

    Comment


    • Hello Randall, I have properly installed your script using professional help but now it wont convert video to to audio (mp3). Script downloads the video, but doesnt show anything in output folder as well.

      I would request your help on the issue, my site is www.videotomp3online.org

      Thanks..

      Comment


      • Originally posted by soofi View Post
        Hello Randall, I have properly installed your script using professional help but now it wont convert video to to audio (mp3). Script downloads the video, but doesnt show anything in output folder as well.

        I would request your help on the issue, my site is www.videotomp3online.org

        Thanks..
        There are many reasons for the script to download the video but not convert the video. I suggest that you search this forum thread for possible causes.

        That said, your AJAX requests are returning responses with error codes (in Firebug)...You can troubleshoot ffmpeg_progress.php to pinpoint which condition is returning an error of "1". (For example, temporarily add more descriptive error codes -- "1a", "1b", "1c", etc.) Then you can isolate which condition in ffmpeg_progress.php is returning "false" and target your efforts accordingly.

        Also, you can post a FFmpeg log file here from a failed conversion, and I can see if there is a problem with your FFmpeg installation.
        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


        • first off thanks a ton for making this.. cant wait to get it up and running 100%. I'm getting an error in my error_log. I have exec enabled as well as ffmpeg but now im getting a different error.

          Code:
          [06-Sep-2012 22:34:53 UTC] PHP Warning:  Division by zero in /home/boniggy/public_html/utube/html4/YouTubeToMp3Converter.class.php on line 103
          [06-Sep-2012 22:41:38 UTC] PHP Warning:  Division by zero in /home/boniggy/public_html/utube/html4/YouTubeToMp3Converter.class.php on line 103
          [06-Sep-2012 22:41:38 UTC] PHP Warning:  Division by zero in /home/boniggy/public_html/utube/html4/YouTubeToMp3Converter.class.php on line 103
          [06-Sep-2012 22:46:32 UTC] PHP Warning:  Division by zero in /home/boniggy/public_html/utube/html4/YouTubeToMp3Converter.class.php on line 103
          [06-Sep-2012 22:46:32 UTC] PHP Warning:  Division by zero in /home/boniggy/public_html/utube/html4/YouTubeToMp3Converter.class.php on line 103
          The video's are downloading as 0kb.. is this why it cant "divide by zero" what is causing that? youtube copywrite?

          thanks again mang!

          EDIT: I decided to be smart and read the beginning again once i found the .txt log file was stating it couldnt fine the .exe file. Im not a linux system and needed to put in the absolute path to it. Hells yeah its working!
          EDIT2: Ok so i started getting the 103 error code again.. I changed the mp3 folder back to 755 file permissions and it worked. It had been 777 before. Could be my host... not sure.

          thanks!
          Last edited by boniggy; Sep 7th, 2012, 08:04 PM.

          Comment


          • The video quality is so bad.

            First sorry for my Bad English, i use Google Translator

            I bought the script now, it works perfectly.
            One question I have, but still, where can set the videos are converted to a better quality?
            and I hope it's OK that I have the script translated into German.
            Regards, Andre
            Support for YouTube Media Converter and Server Management.
            Emailt: support [{AT}] mp3youtu [{DOT}] be

            Comment


            • Originally posted by Luckyplaya View Post
              First sorry for my Bad English, i use Google Translator

              I bought the script now, it works perfectly.
              One question I have, but still, where can set the videos are converted to a better quality?
              and I hope it's OK that I have the script translated into German.
              For which file type do you want to improve the converted file quality: flv, mp4, mp3, or 3gp? And what aspect(s) of the file "quality" do you want to improve?

              The easiest way to tweak converted file characteristics is via the Config::_convertedFileTypes field in config.class.php. That field contains the FFmpeg commands for each converted file type.

              And it's fine that you have converted the script to German. You paid for it, so it's yours to do with as you please.

              Edit: I just noticed the title of your post. I am not experiencing bad quality video here. The video quality is high definition as long as the video uploaded to YouTube is also in high definition.

              Again, additional aspects of the video quality can be tweaked via the FFmpeg commands in the config file.

              Also, if you are getting bad quality video, it could mean that you have not installed/configured FFmpeg and/or the corresponding codecs correctly.

              What video are you trying to convert, and to what file format? Can you paste the FFmpeg log file for that particular video?
              Last edited by chump2877; Sep 8th, 2012, 08:24 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


              • For MP4.
                The script has loaded an HD video from Youtube. But the output is poor.

                OK.
                I have change 'ffmpeg' => '%ffmpeg% -i %tempFile% -vol %volume% -y -acodec libmp3lame -ab %quality%k -vcodec libx264 -vpre veryfast -vb %vquality%k %newFile% 2> logs/%id%.txt'

                to

                'ffmpeg' => '%ffmpeg% -i %tempFile% -vol %volume% -y -acodec libmp3lame -ab %quality%k -vcodec libx264 -vpre veryfast -vb 1000k %newFile% 2> logs/%id%.txt'

                and now the quality is perfect.

                Thanks
                Last edited by Luckyplaya; Sep 8th, 2012, 08:46 AM.
                Regards, Andre
                Support for YouTube Media Converter and Server Management.
                Emailt: support [{AT}] mp3youtu [{DOT}] be

                Comment


                • I'm guessing you were having a problem with the FFmpeg command on line 66 of VideoConverter.class.php. The default video bitrate in my code is 200 (which, if I remember correctly, is also FFmpeg's default video bit rate if none is set). So, if this FFmpeg command fails and/or the grep pattern matching fails on the resulting output, then the video bit rate setting never changes to the right value.

                  I'm thinking there might be an issue, in your case, with grep pattern used to find the video bit rate of the downloaded video. If you are able, can you run this FFmpeg command (on line 66) without the grep pattern matching in a command line. So something like this (for example):

                  /usr/bin/ffmpeg -i downloadedVideo.flv 2>&1
                  That should output some video specs to the command line. Then you can copy the specs here, and I can take a look to see why the grep pattern might be failing for you. I'm wondering if different versions of FFmpeg/Libav output different formats for these video specs -- meaning I might need to adjust the grep pattern to work for different FFmpeg versions.

                  (Note: What you have done here is fine, more or less, as well -- by manually setting the video bit rate to 1000k. The only possible downside of this is if a YouTube video was encoded with a bit rate higher than 1000k, in which case the video quality may degrade if it is reset to 1000k by your FFmpeg command. You could sort of fix this by setting the video bit rate very high -- for example, 3000k. But that increases the converted file size, and unnecessarily so if the original YouTube video is encoded at a relatively low bit rate -- for example, 200k. So there are trade-offs here, if you decide to set this manually as you have done.)

                  Thanks.
                  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, the script just stopped working all of the sudden by itself. Whenever we try to convert a video to mp3 it just says error downloading video.

                    Please let me know about this.

                    Thanks!

                    Comment


                    • Originally posted by bbrog View Post
                      Hi, the script just stopped working all of the sudden by itself. Whenever we try to convert a video to mp3 it just says error downloading video.

                      Please let me know about this.

                      Thanks!
                      I can confirm that the script is not currently working. It looks like YouTube changed something in the video page source code. Consequently, I will need to tweak the regular expressions in my code that I use to grab the video file URLs.

                      I've spent the last hour troubleshooting my code. I can isolate the video file URLs ok, but the download links themselves don't appear to be operational.

                      I don't have any more time to spend on this at the moment. In the next few days, I will explore the issue more, and issue a fix at that time.

                      Note: YouTube may also be playing around with their pages right now. So a knee-jerk reaction to the problem may not be a long term solution. Again, when the dust settles, I will issue a fix.

                      Thanks for your patience.
                      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, great thanks!

                        If you can also let us know what lines of code you change from what to what that would be great for those of us who have customized it in ways.

                        Thanks!

                        Comment


                        • I can only confirm Youtube no longer works

                          great it would be if you were to extend the script with more video sites.

                          YouTube, MyVideo, Clipfish, Dailymotion, Sevenload and Vimeo would be nice
                          Regards, Andre
                          Support for YouTube Media Converter and Server Management.
                          Emailt: support [{AT}] mp3youtu [{DOT}] be

                          Comment


                          • I'm working on it, guys...it seems YouTube was a little devious this time in how the video download URLs must be formatted in order to work correctly....the URLs don't work as they appear in the video page source code...they need to be manipulated to some degree to actually prompt a download...

                            The paid-for version of my script does convert DailyMotion videos as well...

                            Once upon a time, I tried grabbing Vimeo videos, but I found that there was no consistently, reliable way to do this for every Vimeo video...so I shelved that idea for the time being...

                            As my time permits, I may revisit Vimeo or explore other video sharing sites and consider them for inclusion in my script...

                            Thanks for your continued patience.
                            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


                            • The new (updated and hopefully stable) distribution of files is located at the bottom of this post.

                              PLEASE SEE THIS POST FOR IMPORTANT INFO REGARDING THE USE AND INSTALLATION OF THIS SCRIPT.

                              DO NOT USE THE ZIP DISTRIBUTION LOCATED AT THE ABOVE LINKED PAGE. USE ONLY THE ZIP FILE ATTACHED TO THE BOTTOM OF THIS POST.
                              New in this release:

                              1) YouTube changed their video pages' source code, requiring some tweaking of my code to get the video file download links working again. (Big, BIG thanks goes to JackDeRips for helping me figure this out!) The only code to change is in YouTubeToMp3Converter::SetFlvUrls() method in YouTubeToMp3Converter.class.php.

                              I will soon be updating the paid-for version of the app as well, and I will email an updated (free) copy to all those who have already purchased the script. (Updates will be sent to your Tradebit email addresses only.)

                              As always, please let me know if you have any questions/concerns regarding the above and/or 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


                              • Hey, glad everything is working out.

                                Can you let me know what part exactly I need to change in the code I will paste it below

                                Code:
                                <?php
                                
                                	// Conversion Class
                                	include 'config.class.php';
                                	class YouTubeToMp3Converter extends Config
                                	{
                                		// Private Fields
                                		private $_songFileName = '';
                                		private $_flvUrl = '';
                                		private $_tempVidFileName;
                                		private $_uniqueID = '';
                                		private $_vidSrcTypes = array('source_code', 'url');
                                		private $_percentVidDownloaded = 0;
                                
                                		#region Public Methods
                                		function __construct()
                                		{
                                			$this->_uniqueID = time() . "_" . uniqid('', true);
                                		}
                                
                                		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];
                                                        $quality = $audioQuality*1024;
                                			$exec_string = parent::_FFMPEG.' -i '.$this->GetTempVidFileName().' -y -acodec libmp3lame -ab '.$quality.' '.$this->GetSongFileName() . ' 2> logs/' . $this->_uniqueID . '.txt';
                                			$ffmpegExecUrl = preg_replace('/(([^\/]+?)(\.php))$/', "exec_ffmpeg.php", "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
                                			$postData = "cmd=".urlencode($exec_string);
                                			$ch = curl_init();
                                			curl_setopt($ch, CURLOPT_URL, $ffmpegExecUrl);
                                			curl_setopt($ch, CURLOPT_POST, TRUE);
                                			curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
                                			curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
                                			curl_setopt($ch, CURLOPT_TIMEOUT, 1);
                                			curl_exec($ch);
                                			curl_close($ch);
                                		}
                                
                                		function DownloadMP3($file)
                                		{
                                			$filepath = parent::_SONGFILEDIR . urldecode($file);
                                			if (is_file($filepath))
                                			{
                                				header('Content-Type: audio/mpeg3');
                                				header('Content-Length: ' . filesize($filepath));
                                				header('Content-Disposition: attachment; filename="'.urldecode($file).'"');
                                				ob_clean();
                                				flush();
                                				readfile($filepath);
                                				die();
                                			}
                                			else
                                			{
                                				$redirect = explode("?", $_SERVER['REQUEST_URI']);
                                				header('Location: ' . $redirect[0]);
                                			}
                                		}
                                
                                		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;
                                		}
                                
                                		function ExtractVideoId($youTubeUrl)
                                		{
                                			$v = '';
                                			$urlQueryStr = parse_url(trim($youTubeUrl), PHP_URL_QUERY);
                                			if ($urlQueryStr !== false && !empty($urlQueryStr))
                                			{
                                				parse_str($urlQueryStr);
                                			}
                                			return $v;
                                		}
                                
                                		function UpdateVideoDownloadProgress($downloadSize, $downloaded, $uploadSize, $uploaded)
                                		{
                                			$percent = round($downloaded/$downloadSize, 2) * 100;
                                			if ($percent > $this->_percentVidDownloaded)
                                			{
                                				$this->_percentVidDownloaded++;
                                				echo '<script type="text/javascript">updateVideoDownloadProgress("'. $percent .'");</script>';
                                				ob_end_flush();
                                				ob_flush();
                                				flush(); 
                                			}
                                		}
                                		#endregion
                                
                                		#region Private "Helper" Methods
                                		private function SaveVideo($url)
                                		{
                                			$this->_percentVidDownloaded = 0;
                                			$this->SetTempVidFileName();
                                			$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_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());
                                		}
                                		#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)) ? parent::_SONGFILEDIR . preg_replace('/_{2,}/','_',preg_replace('/ /','_',preg_replace('/[^A-Za-z0-9 _-]/','',$trackName))) . '[www.sitename.com].mp3' : '';
                                		}
                                
                                		public function GetFlvUrl()
                                		{
                                			return $this->_flvUrl;
                                		}
                                		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))));
                                			}
                                			//die($vidUrl);
                                			$this->_flvUrl = $vidUrl;
                                		}
                                
                                		public function GetAudioQualities()
                                		{
                                			return $this->_audioQualities;
                                		}
                                
                                		private function GetTempVidFileName()
                                		{
                                			return $this->_tempVidFileName;
                                		}
                                		private function SetTempVidFileName()
                                		{
                                			$this->_tempVidFileName = parent::_TEMPVIDDIR . $this->_uniqueID .'.flv';
                                		}
                                
                                		public function GetVidSrcTypes()
                                		{
                                			return $this->_vidSrcTypes;
                                		}
                                
                                		public function GetUniqueID()
                                		{
                                			return $this->_uniqueID;
                                		}
                                		#endregion
                                	}
                                
                                ?>
                                Let me know thanks!

                                Comment

                                Working...
                                X