Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP YouTube FLV #143

Closed
Conquest-zz opened this issue Aug 16, 2011 · 3 comments
Closed

PHP YouTube FLV #143

Conquest-zz opened this issue Aug 16, 2011 · 3 comments
Labels
php

Comments

@Conquest-zz
Copy link

@Conquest-zz Conquest-zz commented Aug 16, 2011

Hello Guys, i hope you can help me, i'm using youtube-dl since 1 year. I wanna try to parse the flv url trow php now.

$yt_video_id = "ID";
$check_status = curl_init('http://www.youtube.com/get_video_info?video_id='.$yt_video_id.'&fmt=18');
curl_setopt($check_status, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($check_status, CURLOPT_RETURNTRANSFER, true);
$get_youtube_src = curl_exec($check_status);
curl_close($check_status);

if (eregi('url_encoded_fmt_stream_map',$get_youtube_src))
{
$vidUrl = end(explode('url_encoded_fmt_stream_map=',$get_youtube_src));
$vidUrl = urldecode(urldecode(current(explode('&',$vidUrl))));
$vidUrl = current(explode(';',$vidUrl));
$vidUrl = urldecode(end(explode('url=',$vidUrl)));
$complete = $vidUrl;

        } 

echo "complete";

The $complete should be the Download Url, but sometimes it isn't working. Can you tell me why? From 10 Videos, 8 isn't working 2 is working?

regards mike

@phihag
Copy link
Contributor

@phihag phihag commented Aug 16, 2011

It looks like you're not using youtube-dl at all, but writing a similar application in php. Therefore, this is not a valid bug report for youtube-dl. However, you're in luck: youtube-dl can print out the download URL you're currently calculating in php, with the -g option:

$ youtube-dl -g http://www.youtube.com/watch?v=uHlDtZ6Oc3s
http://v23.lscache1.c.youtube.com/videoplayback...

From php, you can use this functionality like this:

$complete = exec('youtube-dl ' . escapeshellarg($yturl));
if (!$complete) throw new Exception('Cannot download video');

If this fails for any youtube URLs, please file a new bug report, and include:

  • The URL
  • Your physical location (country or public IP)
  • The precise output of youtube-dl -g $url
  • The output of youtube-dl --version; md5sum $(which youtube-dl)
  • The output of python --version

Thanks!

@Conquest-zz
Copy link
Author

@Conquest-zz Conquest-zz commented Aug 16, 2011

Thanks!

But i wan't to try if this is working so.

$get_youtube_src = file_get_contents('http://www.youtube.com/get_video_info?video_id='.$yt_video_id.'&fmt=18');

if (eregi('url_encoded_fmt_stream_map',$get_youtube_src))
{
$vidUrl = end(explode('url_encoded_fmt_stream_map=',$get_youtube_src));
$vidUrl = urldecode(urldecode(current(explode('&',$vidUrl))));
$vidUrl = current(explode(';',$vidUrl));
$vidUrl = urldecode(end(explode('url=',$vidUrl)));
$complete = $vidUrl;
}

Normaly in $complete should be they right url? Or can you help me an tell me if the code here is correct to CATCH the right url in the get_video_info from youtube?

@phihag
Copy link
Contributor

@phihag phihag commented Aug 16, 2011

This belongs in a stackoverflow question, not a youtube-dl bug report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.