Go Back   CodingForums.com > :: Server side development > PHP > Post a PHP snippet

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 7 votes, 5.00 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-25-2012, 05:40 AM   PM User | #436
blacktiger786
New Coder

 
Join Date: May 2012
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
blacktiger786 is an unknown quantity at this point
how many i pay you for this..?
blacktiger786 is offline   Reply With Quote
Old 09-03-2012, 09:54 AM   PM User | #437
soofi
New to the CF scene

 
Join Date: Jul 2012
Posts: 6
Thanks: 2
Thanked 0 Times in 0 Posts
soofi is an unknown quantity at this point
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..
soofi is offline   Reply With Quote
Old 09-03-2012, 12:34 PM   PM User | #438
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
Quote:
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.
chump2877 is offline   Reply With Quote
Old 09-06-2012, 11:50 PM   PM User | #439
boniggy
New to the CF scene

 
Join Date: Apr 2009
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
boniggy is an unknown quantity at this point
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; 09-08-2012 at 01:04 AM..
boniggy is offline   Reply With Quote
Old 09-08-2012, 12:42 PM   PM User | #440
Luckyplaya
New Coder

 
Join Date: Sep 2012
Location: Germany
Posts: 32
Thanks: 8
Thanked 1 Time in 1 Post
Luckyplaya is an unknown quantity at this point
Question 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.
Luckyplaya is offline   Reply With Quote
Old 09-08-2012, 01:07 PM   PM User | #441
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
Quote:
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.

Quote:
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?
__________________
Regards, R.J.

Last edited by chump2877; 09-08-2012 at 01:24 PM..
chump2877 is offline   Reply With Quote
Users who have thanked chump2877 for this post:
Luckyplaya (09-08-2012)
Old 09-08-2012, 01:35 PM   PM User | #442
Luckyplaya
New Coder

 
Join Date: Sep 2012
Location: Germany
Posts: 32
Thanks: 8
Thanked 1 Time in 1 Post
Luckyplaya is an unknown quantity at this point
For MP4.
The script has loaded an HD video from Youtube. But the output is poor.

Quote:
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; 09-08-2012 at 01:46 PM..
Luckyplaya is offline   Reply With Quote
Old 09-08-2012, 03:22 PM   PM User | #443
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
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):

Quote:
/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.
chump2877 is offline   Reply With Quote
Old 09-14-2012, 07:19 AM   PM User | #444
bbrog
New Coder

 
Join Date: Jun 2012
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
bbrog is an unknown quantity at this point
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!
bbrog is offline   Reply With Quote
Old 09-14-2012, 08:51 AM   PM User | #445
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
Quote:
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.
chump2877 is offline   Reply With Quote
Old 09-14-2012, 08:18 PM   PM User | #446
bbrog
New Coder

 
Join Date: Jun 2012
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
bbrog is an unknown quantity at this point
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!
bbrog is offline   Reply With Quote
Old 09-14-2012, 11:06 PM   PM User | #447
Luckyplaya
New Coder

 
Join Date: Sep 2012
Location: Germany
Posts: 32
Thanks: 8
Thanked 1 Time in 1 Post
Luckyplaya is an unknown quantity at this point
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
Luckyplaya is offline   Reply With Quote
Old 09-14-2012, 11:27 PM   PM User | #448
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
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.
chump2877 is offline   Reply With Quote
Old 09-15-2012, 01:52 AM   PM User | #449
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
The new (updated and hopefully stable) distribution of files is located at the bottom of this post.

Quote:
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
File Type: zip 9-14-12.zip (6.7 KB, 138 views)
__________________
Regards, R.J.
chump2877 is offline   Reply With Quote
Old 09-15-2012, 02:45 AM   PM User | #450
bbrog
New Coder

 
Join Date: Jun 2012
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
bbrog is an unknown quantity at this point
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!
bbrog is offline   Reply With Quote
Reply

Bookmarks

Tags
audio, class, conversion, dailymotion, ffmpeg, mp3, php, script, video, youtube

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:02 AM.


Advertisement
Log in to turn off these ads.