PHP YouTube FLV #95

Closed
opened 2026-02-20 22:25:21 -05:00 by deekerman · 3 comments
Owner

Originally created by @Conquest-zz on GitHub (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

Originally created by @Conquest-zz on GitHub (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
deekerman 2026-02-20 22:25:21 -05:00
  • closed this issue
  • added the
    php
    label
Author
Owner

@phihag commented on GitHub (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!

@phihag commented on GitHub (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!
Author
Owner

@Conquest-zz commented on GitHub (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?

@Conquest-zz commented on GitHub (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?
Author
Owner

@phihag commented on GitHub (Aug 16, 2011):

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

@phihag commented on GitHub (Aug 16, 2011): This belongs in a [stackoverflow](http://stackoverflow.com) question, not a youtube-dl bug report.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/youtube-dl-ytdl-org#95
No description provided.