|
今天测试GeJI大佬写的用不了,就根据他的接口,思路叫ai重写。
修修改改几十次,修到最后没错误提示,服务器也没错误日志,没法修改了。
不知是我服务器的问题还没源码有错误,发出来大家交流。走服务器流量的哦!
注意,内地服务器不用试!
http://网址/script.php?id=2mCSYvcfhtc&qn=720p
- <?php
- $ch = array(
- '2mCSYvcfhtc' => array(
- 'id' => '2mCSYvcfhtc',
- 'qn' => '720p',
- 'files' => 10
- ),
- 'videoId2' => array(
- 'id' => 'youtubeVideoId2',
- 'qn' => 'quality2',
- 'files' => 5
- ),
- // 添加更多视频通道信息...
- );
- if (isset($_GET['id']) && isset($_GET['qn'])) {
- $videoId = $_GET['id'];
- $quality =['qn'];
- if (isset($ch[$videoId])) {
- $id = $ch[$videoId]['id'];
- $qn = $ch[$videoId]['qn'];
- $delfiles = $ch[$videoId]['files'];
- // 下载和缓存视频的代码逻辑...
- $data = file_get_contents('https://youtube.com/watch?v='.$id);
- preg_match('/hlsManifestUrl":"(.*?)"/', $data, $m3u8url);
- $data = file_get_contents($m3u8url[1]);
- preg_match_all('/http(.*?)\n/', $data, $m3u8url);
- $m3u8data = file_get_contents($m3u8url[0][array_search($qn, array_column($m3u8url[0], '0'))]);
- if (empty($_GET['ts'])) {
- header('Content-Type: application/x-mpegURL');
- $r = urldecode(preg_replace('/http(.*?)sq\//', 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?id='.$videoId.'&qn='.$qn.'&ts='.date('Ymd_'), $m3u8data));
- $r = str_replace('/file/seg.ts', '', $r);
- echo $r;
- } else {
- $ts = $_GET['ts'];
- $cacheDir = 'cache/'.$videoId;
- @mkdir($cacheDir, 0777, true);
- preg_match_all('/clen=(.*?);|lmt=(.*?)\/|dur\/(.*?)$|(.*?)\//', $ts, $ids);
- $tsFileName = $ids[4][0].'.ts';
- if (file_exists($cacheDir.'/'.$tsFileName)) {
- header('Location: '.$cacheDir.'/'.$tsFileName);
- } else {
- preg_match_all('/http(.*?)sq\//', $m3u8data, $urlhead);
- $url = $urlhead[0][0].preg_replace('/(.*?)_/', '', $ids[4][0]).'/goap/clen%3D'.$ids[1][2].'%3Blmt%3D'.$ids[2][3].'/govp/clen%3D'.$ids[1][5].'%3Blmt%3D'.$ids[2][6].'/dur/'.$ids[3][7].'/file/seg.ts';
- // 添加请求头
- $opts = array(
- 'http' => array(
- 'header' => "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36\r\n"
- )
- );
- $context = stream_context_create($opts);
- $data = file_get_contents($url, false, $context);
- // 调试输出
- error_log("URL: ".$url);
- error_log("Data: ".$data);
- file_put_contents($cacheDir.'/'.$tsFileName, $data);
- header('Location: '.$cacheDir.'/'.$tsFileName);
- }
- }
- $list = @scandir($cacheDir.'/'.$videoId);
- if (is_array($list) && count($list) - 2 >= $delfiles) {
- for ($i = 2; $i < count($list); $i++) {
- unlink($cacheDir.'/'.$videoId.'/'.$list[$i]);
- }
- header('Location: '.basename(__FILE__));
- }
- } else {
- echo 'Invalid video ID';
- }
- } else {
- echo 'Video ID and quality are required';
- }
- ?>
复制代码
发帖注意事项
请勿胡乱发帖:https://www.right.com.cn/forum/thread-8307840-1-1.html
账户手机验证:https://www.right.com.cn/forum/home.php?mod=spacecp&ac=plugin&id=jzsjiale_sms:home
|
|