Initial commit
This commit is contained in:
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
/**
|
||||
* B站视频解析
|
||||
*/
|
||||
|
||||
namespace plugin\utility\bili_video;
|
||||
|
||||
use app\Plugin;
|
||||
use app\lib\BilibiliHelper;
|
||||
|
||||
class App extends Plugin
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
return $this->view();
|
||||
}
|
||||
|
||||
public function test(){
|
||||
$bilibili = new BilibiliHelper();
|
||||
$play_info = $bilibili->pgc_video_parse_tv('7419870', '12131254', '97499');
|
||||
return json($play_info);
|
||||
}
|
||||
|
||||
public function query(){
|
||||
$video_url = input('post.video_url', null, 'trim');
|
||||
if(!$video_url) return msg('error','视频链接不能为空');
|
||||
|
||||
$vid = $video_url;
|
||||
$type = 'ugc';
|
||||
$page = 1;
|
||||
if(strpos($video_url,'http://')!==false || strpos($video_url,'https://')!==false){
|
||||
if(preg_match('!/BV(\w+)!i',$video_url,$match)){
|
||||
$vid = 'BV'.$match[1];
|
||||
$querystring = 'bvid='.$vid;
|
||||
}elseif(preg_match('!/av(\d{1,})!',$video_url,$match)){
|
||||
$vid = $match[1];
|
||||
$querystring = 'aid='.$vid;
|
||||
}elseif(preg_match('!/ep(\d{1,})!',$video_url,$match)){
|
||||
$vid = $match[1];
|
||||
$type = 'pgc';
|
||||
if(strpos($video_url,'/cheese/')!==false){
|
||||
$type = 'pugv';
|
||||
}
|
||||
}elseif(preg_match('!/ss(\d{1,})!',$video_url,$match)){
|
||||
$vid = $match[1];
|
||||
$type = 'pgc_ss';
|
||||
}elseif(preg_match('!/au(\d{1,})!',$video_url,$match)){
|
||||
$vid = $match[1];
|
||||
$type = 'audio';
|
||||
}else{
|
||||
return msg('error','视频链接输入格式错误');
|
||||
}
|
||||
if($type == 'ugc' && preg_match('!p=(\d{1,})!',$video_url,$match)){
|
||||
$page = $match[1];
|
||||
}
|
||||
}else{
|
||||
if(substr($vid,0,2) == 'av' && is_numeric(substr($vid,2))){
|
||||
$querystring = 'aid='.substr($vid,2);
|
||||
}elseif(substr($vid,0,2) == 'ep' && is_numeric(substr($vid,2))){
|
||||
$vid = substr($vid,2);
|
||||
$type = 'pgc';
|
||||
}elseif(substr($vid,0,2) == 'ss' && is_numeric(substr($vid,2))){
|
||||
$vid = substr($vid,2);
|
||||
$type = 'pgc_ss';
|
||||
}elseif(substr($vid,0,2) == 'BV' && preg_match('/^[a-zA-Z0-9]+$/',$vid)){
|
||||
$querystring = 'bvid='.$vid;
|
||||
}elseif(substr($vid,0,2) == 'au' && is_numeric(substr($vid,2))){
|
||||
$vid = substr($vid,2);
|
||||
$type = 'audio';
|
||||
}else{
|
||||
return msg('error','视频链接输入格式错误');
|
||||
}
|
||||
}
|
||||
|
||||
$bilibili = new BilibiliHelper();
|
||||
try{
|
||||
if($type == 'ugc'){
|
||||
$video_info = $bilibili->ugc_video_info($querystring);
|
||||
$link = 'https://www.bilibili.com/video/'.$video_info['bvid'];
|
||||
if(count($video_info['pages']) > 1){
|
||||
foreach($video_info['pages'] as $pagerow){
|
||||
if($page == $pagerow['page']){
|
||||
$video_info['cid'] = $pagerow['cid'];
|
||||
$video_info['duration'] = $pagerow['duration'];
|
||||
$video_info['title'] .= ' - '.$pagerow['part'];
|
||||
$link .= '?p='.$page;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
$play_info = $bilibili->get_video_url($video_info['aid'], $video_info['cid']);
|
||||
|
||||
$result = [
|
||||
'type' => 0,
|
||||
'aid' => $video_info['aid'],
|
||||
'cid' => $video_info['cid'],
|
||||
'bvid' => $video_info['bvid'],
|
||||
'link' => $link,
|
||||
'danmu' => 'https://comment.bilibili.com/'.$video_info['cid'].'.xml',
|
||||
'title' => $video_info['title'],
|
||||
'desc' => $video_info['desc'],
|
||||
'pic' => $video_info['pic'],
|
||||
'duration' => $video_info['duration'],
|
||||
'owner' => isset($video_info['owner'])?$video_info['owner']:null,
|
||||
'video' => $play_info,
|
||||
];
|
||||
}elseif($type == 'pgc' || $type == 'pgc_ss'){
|
||||
$video_info = $type == 'pgc_ss' ? $bilibili->pgc_video_info_by_ssid($vid) : $bilibili->pgc_video_info($vid);
|
||||
|
||||
$result = [
|
||||
'type' => 0,
|
||||
'aid' => $video_info['aid'],
|
||||
'cid' => $video_info['cid'],
|
||||
'bvid' => $video_info['bvid'],
|
||||
'link' => $video_info['link'],
|
||||
'danmu' => 'https://comment.bilibili.com/'.$video_info['cid'].'.xml',
|
||||
'title' => $video_info['share_copy'],
|
||||
'desc' => null,
|
||||
'pic' => $video_info['cover'],
|
||||
'duration' => $video_info['duration'],
|
||||
'owner' => false,
|
||||
'video' => false,
|
||||
];
|
||||
}elseif($type == 'audio'){
|
||||
$audio_info = $bilibili->get_audio_info($vid);
|
||||
$link = 'https://www.bilibili.com/audio/au'.$audio_info['id'];
|
||||
$play_info = $bilibili->get_audio_url($audio_info['id']);
|
||||
|
||||
$result = [
|
||||
'type' => 1,
|
||||
'aid' => $audio_info['id'],
|
||||
'link' => $link,
|
||||
'lyric' => $audio_info['lyric'],
|
||||
'title' => $audio_info['title'],
|
||||
'desc' => $audio_info['intro'],
|
||||
'pic' => $audio_info['cover'],
|
||||
'duration' => $audio_info['duration'],
|
||||
'owner' => ['mid'=>$audio_info['uid'], 'name'=>$audio_info['uname']],
|
||||
'video' => $play_info,
|
||||
];
|
||||
}else{
|
||||
return msg('error','该视频类型不支持在线解析');
|
||||
}
|
||||
|
||||
return msg('ok', 'success', $result);
|
||||
|
||||
}catch(\Exception $e){
|
||||
return msg('error',$e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
{extend name="common/plugin_layout" /}
|
||||
{block name="title"}{$plugin.title} - {:config_get('title')}{/block}
|
||||
{block name="main"}
|
||||
<div class="container-xl" id="app">
|
||||
<div class="col-sm-12 col-md-10 col-xl-8 center-block">
|
||||
<div class="card card-preview">
|
||||
<div class="card-inner mt-3">
|
||||
<div class="nya-title nk-ibx-action-item progress-rating">
|
||||
<span class="nk-menu-text font-weight-bold">B站视频解析</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="input-group input-group-lg">
|
||||
<div class="input-group-prepend"><span class="input-group-text">视频链接</span></div>
|
||||
<input type="text" v-model="input" class="form-control" value="" placeholder="请输入B站视频链接或BV/av" @keyup.enter="query" ref="input" autocomplete="off">
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn btn-dim btn-outline-primary btn-block btn-lg mb-3" @click="query" :disabled="query_disabled">
|
||||
提交
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card card-preview" v-show="showresult" style="display:none">
|
||||
<div class="card-inner mt-3">
|
||||
<div class="nya-title nk-ibx-action-item progress-rating">
|
||||
<span class="nk-menu-text font-weight-bold">视频信息</span>
|
||||
</div>
|
||||
<table class="table table-hover table-bordered">
|
||||
<tbody>
|
||||
<tr><td class="query-title">视频标题</td><td class="query-result"><a :href="result_info.link" target="_blank" rel="noreferrer">{{result_info.title}}</td></tr>
|
||||
<tr v-show="result_info.desc"><td class="query-title">视频描述</td><td class="query-result">{{result_info.desc}}</td></tr>
|
||||
<tr v-show="result_info.owner"><td class="query-title">视频作者</td><td class="query-result"><a :href="'https://space.bilibili.com/'+result_info.owner.mid" target="_blank" rel="noreferrer">{{result_info.owner.name}}</td></tr>
|
||||
<tr><td class="query-title">视频封面</td><td class="query-result"><a :href="result_info.pic" target="_blank" rel="noreferrer">{{result_info.pic}}</td></tr>
|
||||
<tr v-show="result_info.video"><td class="query-title">下载链接</td><td class="query-result"><a :href="result_info.video.url" class="btn btn-sm btn-outline-info" target="_blank" rel="noreferrer">点击下载</a> <a @click="copy(result_info.video.url)" class="btn btn-sm btn-outline-warning" href="JavaScript:;">点此复制</a></td></tr>
|
||||
<tr v-show="result_info.video"><td class="query-title">视频格式</td><td class="query-result"><span class="text-info">{{result_info.video.quality}}({{result_info.video.codec}})</span> 大小:<span class="text-info">{{formatFileSize(result_info.video.size)}}</span> 时长:<span class="text-info">{{formatSeconds(result_info.duration)}}</span></td></tr>
|
||||
<tr v-show="!result_info.video"><td class="query-title">下载链接</td><td class="query-result">该视频类型不支持在线解析,请使用<a href="https://blog.cccyun.cn/post-436.html" target="_blank">电脑版软件</a>下载视频</td></tr>
|
||||
<tr><td class="query-title">弹幕文件</td><td class="query-result"><a :href="result_info.danmu" target="_blank" rel="noreferrer">{{result_info.danmu}}</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card card-preview" v-show="showresult2" style="display:none">
|
||||
<div class="card-inner mt-3">
|
||||
<div class="nya-title nk-ibx-action-item progress-rating">
|
||||
<span class="nk-menu-text font-weight-bold">音乐信息</span>
|
||||
</div>
|
||||
<table class="table table-hover table-bordered">
|
||||
<tbody>
|
||||
<tr><td class="query-title">音乐标题</td><td class="query-result"><a :href="result_info.link" target="_blank" rel="noreferrer">{{result_info.title}}</td></tr>
|
||||
<tr><td class="query-title">音乐描述</td><td class="query-result">{{result_info.desc}}</td></tr>
|
||||
<tr><td class="query-title">音乐作者</td><td class="query-result"><a :href="'https://space.bilibili.com/'+result_info.owner.mid" target="_blank" rel="noreferrer">{{result_info.owner.name}}</td></tr>
|
||||
<tr><td class="query-title">专辑封面</td><td class="query-result"><a :href="result_info.pic" target="_blank" rel="noreferrer">{{result_info.pic}}</td></tr>
|
||||
<tr><td class="query-title">下载链接</td><td class="query-result"><a :href="result_info.video.url" class="btn btn-sm btn-outline-info" target="_blank" rel="noreferrer">点击下载</a> <a @click="copy(result_info.video.url)" class="btn btn-sm btn-outline-warning" href="JavaScript:;">点此复制</a>(需模拟来源url)</td></tr>
|
||||
<tr><td class="query-title">音频格式</td><td class="query-result"><span class="text-info">{{result_info.video.quality}}</span> 大小:<span class="text-info">{{formatFileSize(result_info.video.size)}}</span> 时长:<span class="text-info">{{formatSeconds(result_info.duration)}}</span></td></tr>
|
||||
<tr><td class="query-title">歌词文件</td><td class="query-result"><a :href="result_info.lyric" target="_blank" rel="noreferrer">{{result_info.lyric}}</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/block}
|
||||
{block name="script"}
|
||||
<script src="{$cdn_cdnjs}vue/2.6.14/vue.min.js"></script>
|
||||
<script src="https://static.geetest.com/v4/gt4.js"></script>
|
||||
<script>
|
||||
function formatSeconds(second) {
|
||||
var sec = parseInt(second);
|
||||
var min = 0;
|
||||
var hour = 0;
|
||||
var result = "";
|
||||
if(sec >= 60) {
|
||||
min = parseInt(sec/60);
|
||||
sec = parseInt(sec%60);
|
||||
if(min > 60) {
|
||||
hour = parseInt(min/60);
|
||||
min = parseInt(min%60);
|
||||
}
|
||||
}
|
||||
if(hour) result = hour+":"+f(min)+":"+f(sec);
|
||||
else result = f(min)+":"+f(sec);
|
||||
return result;
|
||||
}
|
||||
function f(s) {
|
||||
return s < 10 ? '0' + s: s;
|
||||
}
|
||||
new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
query_disabled: true,
|
||||
input: '',
|
||||
longurl: '',
|
||||
showresult: false,
|
||||
showresult2: false,
|
||||
result_info: {
|
||||
aid: '',
|
||||
cid: '',
|
||||
bvid: '',
|
||||
link: '',
|
||||
danmu: '',
|
||||
title: '',
|
||||
desc: '',
|
||||
pic: '',
|
||||
duration: '',
|
||||
lyric: '',
|
||||
owner: {
|
||||
mid: '',
|
||||
name: '',
|
||||
},
|
||||
video: {
|
||||
url: '',
|
||||
size: 0,
|
||||
quality: '',
|
||||
format: '',
|
||||
codec: '',
|
||||
},
|
||||
},
|
||||
captcha: null
|
||||
},
|
||||
mounted() {
|
||||
this.$refs.input.focus();
|
||||
var that=this;
|
||||
initGeetest4({
|
||||
captchaId: "99b142aaece96330d0f3ffb565ffb3ef",
|
||||
product: 'bind',
|
||||
protocol: 'https://',
|
||||
riskType: 'ai',
|
||||
},function (captcha) {
|
||||
captcha.onReady(function(){
|
||||
that.query_disabled=false;
|
||||
that.captcha = captcha;
|
||||
}).onSuccess(function(){
|
||||
var result = captcha.getValidate();
|
||||
if (!result) {
|
||||
layer.closeAll();
|
||||
return alert('请先完成验证');
|
||||
}
|
||||
var data = { video_url: that.input};
|
||||
$.ajax({
|
||||
url: '/api/{$plugin.alias}/query',
|
||||
type: 'post',
|
||||
dataType: 'json',
|
||||
data: Object.assign(data, result),
|
||||
cache: false,
|
||||
success: function (data) {
|
||||
layer.closeAll();
|
||||
if(data.status=='ok'){
|
||||
that.result_info = data.data;
|
||||
if(data.data.type == 1){
|
||||
that.showresult2 = true;
|
||||
that.showresult = false;
|
||||
}else{
|
||||
that.showresult = true;
|
||||
that.showresult2 = false;
|
||||
}
|
||||
captcha.reset();
|
||||
}else{
|
||||
layer.alert(data.message, {icon: 5});
|
||||
captcha.reset();
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
layer.closeAll();
|
||||
layer.msg('服务器错误', {icon: 5});
|
||||
captcha.reset();
|
||||
}
|
||||
});
|
||||
}).onError(function(){
|
||||
alert('验证码加载失败,请刷新页面重试');
|
||||
})
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
query() {
|
||||
if(this.input.trim() == ''){
|
||||
layer.alert('视频链接不能为空');return;
|
||||
}
|
||||
this.showresult = false;
|
||||
layer.load(0, {shade:0.1});
|
||||
this.captcha.showCaptcha();
|
||||
},
|
||||
copy(text) {
|
||||
copy(text);
|
||||
layer.msg('复制成功', {icon:1, time:600})
|
||||
},
|
||||
formatFileSize(fileSize) {
|
||||
if (fileSize < 1024) {
|
||||
return fileSize + 'B';
|
||||
} else if (fileSize < (1024*1024)) {
|
||||
var temp = fileSize / 1024;
|
||||
temp = temp.toFixed(2);
|
||||
return temp + 'KB';
|
||||
} else if (fileSize < (1024*1024*1024)) {
|
||||
var temp = fileSize / (1024*1024);
|
||||
temp = temp.toFixed(2);
|
||||
return temp + 'MB';
|
||||
} else {
|
||||
var temp = fileSize / (1024*1024*1024);
|
||||
temp = temp.toFixed(2);
|
||||
return temp + 'GB';
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
</script>
|
||||
{/block}
|
||||
Reference in New Issue
Block a user