加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 服务器端的Youtube下载程序脚本

发布时间:2020-12-13 22:49:54 所属栏目:PHP教程 来源:网络整理
导读:我正在尝试生成一个可以在服务器上下载youtube视频的脚本,我希望用户提供视频网址. 我已经搜索了很多但是,无法使它工作.这是我的代码. ?php// Check download tokenif (empty($_GET['mime']) OR empty($_GET['token'])){exit('Invalid download token 8{');}
我正在尝试生成一个可以在服务器上下载youtube视频的脚本,我希望用户提供视频网址.

我已经搜索了很多但是,无法使它工作.这是我的代码.

<?php
// Check download token
if (empty($_GET['mime']) OR empty($_GET['token']))
{
exit('Invalid download token 8{');
}
// Set operation params
$mime = filter_var($_GET['mime']);
$ext  = str_replace(array('/','x-'),'',strstr($mime,'/'));
$url  = base64_decode(filter_var($_GET['token']));
$name = urldecode($_GET['title']). '.' .$ext; 
// Fetch and serve
if ($url)
{
// Generate the server headers
if (strpos($_SERVER['HTTP_USER_AGENT'],'MSIE') !== FALSE)
{/*
    header('Content-Type: "' . $mime . '"');
    header('Content-Disposition: attachment; filename="' . $name . '"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate,post-check=0,pre-check=0');
    header("Content-Transfer-Encoding: binary");
    header('Pragma: public');
*/}
else
{/*
    header('Content-Type: "' . $mime . '"');
    header('Content-Disposition: attachment; filename="' . $name . '"');
    header("Content-Transfer-Encoding: binary");
    header('Expires: 0');
    header('Pragma: no-cache');
*/}
$download_video_file = file_put_contents($file_path,fopen($url,'r'));
exit;
}
// Not found
exit('File not found 8{');
?>

但是我仍然坚持这个,请帮助我.

解决方法

您将从此处获取代码

参考:https://code.google.com/p/php-youtube-downloader/

<?php
require_once('youtube.lib.php');
$download_link = get_youtube('http://www.youtube.com/watch?v=SAQZ0BDXn48'); 

// we will have array here,index 0 is the video ID and index 1 is the download link.
echo $download_link[1];
?>

http://php-youtube-downloader.googlecode.com/files/youtube_downloader.zip

GitHub:https://github.com/jeckman/YouTube-Downloader

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读