Skip to content
This repository was archived by the owner on Jan 20, 2023. It is now read-only.

Commit 51a35c8

Browse files
authored
Add files via upload
1 parent 8f8fd6c commit 51a35c8

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed

BiliBiliVideo/index.php

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* By SkiMkino
4+
* GitHub: https://github.com/XMSMApi
5+
* License: GPLv3
6+
* Original: AiMuC
7+
*/
8+
include '../lib/func.php';
9+
10+
require('system/init.php');
11+
$id = $_GET['id'];
12+
if ($id != null) {
13+
$Url = GetVideoSrc($id);
14+
if (!empty($Url)) {
15+
echo json_code($Url, 200);
16+
} else {
17+
echo json_code('', 404, 'No found');
18+
}
19+
} else {
20+
echo json_code('', 500, 'No set id');
21+
}
22+
?>

BiliBiliVideo/system/config.php

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
$data=array(
3+
'cookie'=>"_uuid=86514C16-F3106-A68C-FD5E-7E35842D872E77767infoc; buvid3=83F86E47-B8B8-453A-A15D-A2D46FE0FC28148826infoc; b_nut=1641691879; buvid_fp_plain=undefined; SESSDATA=ee4fc98b%2C1658299487%2C49f9b%2A11; bili_jct=1371a2f7f10e3b8a5947db8b4cbfb37c; DedeUserID=372657168; DedeUserID__ckMd5=3f0f99b051a75a48; sid=9b0n8pba; CURRENT_BLACKGAP=0; blackside_state=0; rpdid=|(um~Rm~~|)u0J'uYRk~R~YJ); LIVE_BUVID=AUTO9716427478340661; Hm_lvt_8a6e55dbd2870f0f5bc9194cddf32a02=1642747837; i-wanna-go-back=-1; b_ut=5; CURRENT_FNVAL=2000; bp_video_offset_372657168=618426508392816000; fingerprint3=66b4ed0150cc76af814a50905f13be7b; fingerprint=b710415a76d246df7e9d1113addf58ef; PVID=1; buvid4=8DD1A18E-8793-EC66-A5D0-2818CB35758F85357-022012415-3suQnVxxxAU31bcuMW1u1Q%3D%3D; buvid_fp=b710415a76d246df7e9d1113addf58ef; innersign=0; b_lsid=BCEDCE8B_17E9063576E"
4+
);
5+
?>

BiliBiliVideo/system/function.php

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/* File Info
3+
* Author: AiMuC
4+
* CreateTime: 2021/2/12 下午2:50:15
5+
* LastEditor: AiMuC
6+
* ModifyTime: 2021/2/26 下午4:17:32
7+
* Description:
8+
*/
9+
10+
11+
/*
12+
* @Description: 获取视频真实地址
13+
* @param: 视频AV号或BV号
14+
* @return: url
15+
*/
16+
function GetVideoSrc($videoid)
17+
{
18+
include(DIR . '/system/config.php');
19+
$cid = GetCid($videoid);
20+
$header = "cookie:" . $data['cookie'] . "\r\n";
21+
$Response = MyRequest("https://api.bilibili.com/x/player/playurl?cid=$cid&bvid=$videoid&qn=112", $header, "", "", "");
22+
$Response = json_decode($Response['body'], true);
23+
return stripslashes($Response['data']['durl'][0]['url']);
24+
}
25+
26+
/*
27+
* @Description: 获取B站视频CID
28+
* @param: 视频id 如bv号或av号
29+
* @return: int/$cid
30+
*/
31+
function GetCid($videoid)
32+
{
33+
$Response = MyRequest("https://api.bilibili.com/x/player/pagelist?bvid=$videoid", "", "", "", "");
34+
$Response = json_decode($Response['body'], true);
35+
return $Response['data'][0]['cid'];
36+
}
37+
38+
/*
39+
* @Description: Web请求函数
40+
* @param: url 必填
41+
* @param: header 请求头 为空时使用默认值
42+
* @param: type 请求类型
43+
* @param: data 请求数据
44+
* @param: DataType 数据类型 分为1,2 1为数据拼接传参 2为json传参
45+
* @param: HeaderType 请求头类型 默认为PC请求头 值为PE时请求头为手机
46+
* @return: result
47+
*/
48+
function MyRequest($url, $header, $type, $data, $DataType, $HeaderType = "PC")
49+
{
50+
//常用header
51+
//$header = "user-agent:" . 1 . "\r\n" . "referer:" . 1 . "\r\n" . "AccessToken:" . 1 . "\r\n" . "cookie:" . 1 . "\r\n";
52+
if (empty($header)) {
53+
if ($HeaderType == "PC") {
54+
$header = "user-agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36 Edg/88.0.705.63\r\n";
55+
} else if ($HeaderType == "PE") {
56+
$header = "user-agent:Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1 Edg/88.0.4324.150\r\n";
57+
}
58+
}
59+
if (!empty($data)) {
60+
if ($DataType == 1) {
61+
$data = http_build_query($data); //数据拼接
62+
} else if ($DataType == 2) {
63+
$data = json_encode($data, JSON_UNESCAPED_UNICODE); //数据格式转换
64+
}
65+
}
66+
$options = array(
67+
'http' => array(
68+
'method' => $type,
69+
"header" => $header,
70+
'content' => $data,
71+
'timeout' => 15 * 60, // 超时时间(单位:s)
72+
)
73+
);
74+
$context = stream_context_create($options);
75+
$result = file_get_contents($url, false, $context);
76+
$headers = get_headers($url, true); //获取请求返回的header
77+
$ReturnArr = array(
78+
'headers' => $headers,
79+
'body' => $result
80+
);
81+
return $ReturnArr;
82+
}
83+
?>

BiliBiliVideo/system/init.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
/* File Info
3+
* Author: AiMuC
4+
* CreateTime: 2021/2/12 下午2:15:41
5+
* LastEditor: AiMuC
6+
* ModifyTime: 2021/2/12 下午3:26:32
7+
* Description:
8+
*/
9+
//error_reporting(0);
10+
date_default_timezone_set('PRC');
11+
header('Content-type:text/html;charset=utf8');
12+
define('DIR', dirname(__DIR__));
13+
include_once(DIR . '/system/function.php');
14+
?>

0 commit comments

Comments
 (0)