gpt4 book ai didi

php - 如何从PHP中的任何Youtube视频生成下载链接?

转载 作者:行者123 更新时间:2023-12-03 05:46:51 29 4
gpt4 key购买 nike

目前,我正在开发一个Web应用程序,该应用程序允许用户将任何Youtube视频发布到他们管理的个人资料或页面上。这是我用来将YouTube视频发布到我的个人资料的代码

 $videoUpload = $fb->post('/me/videos', ['description' => 'example description', 'file_url' => 'https://r2---sn-npoeene7.googlevideo.com/videoplayback?pl=24&lmt=1513082002389285&id=o-AIPnl4v8svvYBTFPYwJOsRanE_5O8YSK0F3bMkTqN6QR&itag=22&signature=8051FCC4C243296224CD1D7ADB4E5C0A90125C57.66FF9FF2063C3A8F00F143FB51BB3E98F7AEBB7B&requiressl=yes&ip=203.189.156.104&sparams=dur,ei,expire,id,initcwndbps,ip,ipbits,itag,lmt,mime,mm,mn,ms,mv,pl,ratebypass,requiressl,source&key=cms1&mime=video%2Fmp4&dur=301.952&fvip=2&ipbits=0&c=WEB&expire=1519648901&ratebypass=yes&ei=JayTWtSaDcWqoQORionoCg&source=youtube&redirect_counter=1&cm2rm=sn-jvbxuxavoapox-2oil7e&fexp=23712580&req_id=21384f45d53ba3ee&cms_redirect=yes&mm=29&mn=sn-npoeene7&ms=rdu&mt=1519627218&mv=m'], $access_token);
$videoUpload = $videoUpload->getGraphNode()->asArray();

问题是Facebook不允许直接发布Youtube链接,因此我需要从该视频中生成可下载的链接才能发布到Facebook。
这是用于从Youtube视频生成下载链接的PHP代码
   <?php

$id = 'RllJtOw0USI';

if (isset($_GET["id"]))
$id = $_GET["id"];

parse_str(file_get_contents('http://www.youtube.com/get_video_info?video_id='.$id), $video_data);

$streams = $video_data['url_encoded_fmt_stream_map'];
$streams = explode(',',$streams);
$counter = 1;

foreach ($streams as $streamdata) {
printf("Stream %d:<br/>----------------<br/><br/>", $counter);

parse_str($streamdata,$streamdata);

foreach ($streamdata as $key => $value) {
if ($key == "url") {
$value = urldecode($value);
printf("<strong>%s:</strong> <a href='%s'>video link</a><br/>", $key, $value);
} else {
printf("<strong>%s:</strong> %s<br/>", $key, $value);
}
}

$counter = $counter+1;
printf("<br/><br/>");
}

?>

如果我将 $ id 更改为 dMK_npDG12Q ,则它仅适用于 RllJtOw0USI ,它不再起作用,并且出现以下错误:
status=fail&errorcode=150&errordetail=0&reason=This+video+contains+content+from+Vevo.+It+is+restricted+from+playback+on+certain+sites+or+applications.%0A%3Ca+href%3D%27http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DdMK_npDG12Q%26feature%3Dplayer_embedded%27+target%3D%27_blank%27%3EWatch+on+YouTube%3C%2Fa%3E

如何从此类视频中获取链接?
先谢谢了。

最佳答案

如果您在json中查看原因,您会看到

This video contains content from Vevo. It is restricted from playback on certain sites or applications

因此,您应该遵守他们的限制,或者找到其他尚未受到限制的链接。

关于php - 如何从PHP中的任何Youtube视频生成下载链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49005512/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com