[PHP] 纯文本查看 复制代码
<?php
if ((isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && strtolower($_SERVER["HTTP_X_REQUESTED_WITH"]) == "xmlhttprequest") || isset($_GET['jump'])) {
$starttime = microtime(1);
$result['run_time'] = number_format((microtime(1) - $starttime) * 1000, 1);
$ListApi = 'https://gitee.com/au_2023/codes/nxe5yoirc9l8s70dzvawh50/raw?blob_name=JoyfulList'; // 自己进行收集整理
$video_id = get_video_id($ListApi);
$result = array();
$result['play_addr'] = getRedirect('https://aweme.snssdk.com/aweme/v1/play/?video_id=' . $video_id);
$result['video_id'] = $video_id;
$result['run_time'] = number_format((microtime(1) - $starttime) * 1000, 1);
if (isset($_GET['jump'])) {
header('Location: ' . $result['play_addr']);
}
header("Content-Type: application/json");
echo json_encode($result);
exit('');
}
function get_video_id($Api)
{
$cache = __DIR__ . '/Joyful.txt';
if (is_file($cache)) {
$Data = unserialize(file_get_contents($cache));
if (count($Data) == 0) {
$Data = json_decode(file_get_contents($cache), true);
}
} else {
$Data = json_decode(file_get_contents($Api), true);
}
$key = rand(0, count($Data) - 1);
$video_id = $Data[$key];
unset($Data[$key]);
file_put_contents($cache, serialize(array_values($Data)));
return $video_id;
}
function getRedirect($Url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: */*',
'Accept-Encoding: gzip',
'Connection: Keep-Alive',
'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'
));
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ret = curl_exec($ch);
curl_close($ch);
preg_match("/Location: (.*?)\r\n/iU", $ret, $location);
if (isset($location[1])) {
return $location[1];
}
return false;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>心情愉悦</title>
<meta name="renderer" content="webkit">
<meta name="referrer" content="never">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/js-cookie/3.0.1/js.cookie.js"></script>
</head>
<body>
<div class="container" id="player" style="display: none;">
<video id="video" controls autoplay style="width: 100%;"></video>
</div>
<button id="start">开始运行</button>
</body>
<script>
load();
function start() {
var result = JSON.parse(Cookies.get('next'));
$('#player').show();
$('#start').hide();
$('#video').attr('src', result.play_addr);
load();
}
let video = document.getElementById('video');
video.onended = function() {
var result = JSON.parse(Cookies.get('next'));
$('#video').attr('src', result.new_play_addr);
load();
}
function load() {
$.ajax({
type: 'get',
url: 'Joyful.php',
async: false,
success: function(result) {
data = result;
downloadBlobFile('GET', result.play_addr).onreadystatechange = res => {
if (res.currentTarget.readyState == 4 && res.currentTarget.status == 200) {
result.new_play_addr = window.URL.createObjectURL(res.currentTarget.response);
result = JSON.stringify(result);
Cookies.set('next', result, 60);
}
}
},
error: function() {
//layer.msg('加载失败,等待下一次加载...');
}
});
return data;
}
function downloadBlobFile(_method, _url) {
const request = new XMLHttpRequest();
request.open(_method, _url);
request.send();
request.responseType = 'blob';
return request;
}
</script>
</html>