WordPress 视频插件Smartideo支持B站BV号和AV号

WordPress 视频插件Smartideo支持B站BV号和AV号_第1张图片
2020年3月23日 B站调整视频链接ID AV开头升级为BV开头,B站说是为了保护稿件信息安全,容纳更多投稿,维护UP主的权益。但升级后的链接造成WordPres视频播放插件Smartideo中的正则无法获取由数字和大小写字母组成的字符串,原来直接复制粘贴视频地址到文章中调用视频的方法失效,有用户已在插件作者网站反映,作者并没有回应,可能因各视频站更新升级频繁,Smartideo插件很多视频站点都已不支持,估计作者已放弃更新了,所以一下教大家AV和BV号共存播放视频!

支持播放:优酷、bilibili、ACfun、音悦台、网易视频、芒果TV、搜狐视频、土豆、56、腾讯视频、新浪视频、酷6、华数、乐视、YouTube 等网站。

1.首先打开Smartideo插件smartideo.php文件,在大约87行:

array($this, ‘smartideo_embed_handler_bilibili’) );

下面添加:

class=“prettyprint”>wp_embed_register_handler( ‘smartvideo_bilibili_bv’,

‘#https?/www.bilibili.com/video/BV(??[a-z0-9_=-]+)/(?:index_|#page=)(?[a-z0-9_=-]+)|(?[a-z0-9_=-]+))#i’,

array($this, ‘smartvideo_embed_handler_bilibili_bv’) );

2.在大约195行代码:

return apply_filters( ‘embed_bilibili’, $embed, $matches, $attr, $url, $rawattr );

下面添加:

public function smartvideo_embed_handler_bilibili_bv( $matches, $attr, $url, $rawattr ) {

m a t c h e s [ ′ v i d e o i d ′ ] = ( matches['video_id'] = ( matches[videoid]=(matches[‘video_id1’] == ‘’) ? $matches[‘video_id’] : $matches[‘video_id1’];

p a g e = ( page = ( page=(matches[‘video_id2’] > 1) ? $matches[‘video_id2’] : 1;

$cid = ‘’;

$embed = KaTeX parse error: Expected '}', got 'EOF' at end of input: …yer.html?bvid={matches[‘video_id’]}&cid={KaTeX parse error: Expected 'EOF', got '}' at position 4: cid}̲&page={page}", $url);

return apply_filters( ‘embed_bilibili’, $embed, $matches, $attr, $url, $rawattr );

}

这样可以加载播放视频了!(不过发现插件貌似也不支原来的av地址我们还需在修改一下!)

3.再接着修改一下吧,将代码:

public function smartideo_embed_handler_bilibili( $matches, $attr, $url, $rawattr ) {

m a t c h e s [ ′ v i d e o i d ′ ] = ( matches['video_id'] = ( matches[videoid]=(matches[‘video_id1’] == ‘’) ? $matches[‘video_id’] : $matches[‘video_id1’];

p a g e = ( page = ( page=(matches[‘video_id2’] > 1) ? $matches[‘video_id2’] : 1;

$cid = ‘’;

/*

try{

$request = new WP_Http();

$url = “https://api.bilibili.com/view?type=jsonp&appkey=8e9fc618fbd41e28&id=” . $matches[‘video_id’];

d a t a = ( a r r a y ) data = (array) data=(array)request->request($url, array(‘timeout’ => 3));

j s o n = j s o n d e c o d e ( json = json_decode( json=jsondecode(data[‘body’], true);

$cid = $json[‘cid’];

}catch(Exception $e){}

*/

if(wp_is_mobile() || $this->bilibili_pc_player == 1){

$embed = KaTeX parse error: Expected '}', got 'EOF' at end of input: …ayer.html?aid={matches[‘video_id’]}&cid={KaTeX parse error: Expected 'EOF', got '}' at position 4: cid}̲&page={page}", $url);

}else{

$embed = t h i s − > g e t l i n k ( this->get_link( this>getlink(url);

}

return apply_filters( ‘embed_bilibili’, $embed, $matches, $attr, $url, $rawattr );

}

替换成:

public function smartideo_embed_handler_bilibili( $matches, $attr, $url, $rawattr ) {

m a t c h e s [ ′ v i d e o i d ′ ] = ( matches['video_id'] = ( matches[videoid]=(matches[‘video_id1’] == ‘’) ? $matches[‘video_id’] : $matches[‘video_id1’];

p a g e = ( page = ( page=(matches[‘video_id2’] > 1) ? $matches[‘video_id2’] : 1;

$cid = ‘’;

$embed = KaTeX parse error: Expected '}', got 'EOF' at end of input: …ayer.html?aid={matches[‘video_id’]}&cid={KaTeX parse error: Expected 'EOF', got '}' at position 4: cid}̲&page={page}", $url);

return apply_filters( ‘embed_bilibili’, $embed, $matches, $attr, $url, $rawattr );

}

即可替换成BV号和BV号共存了!

AV和BV号视频播放演示:http://记事本.移动/59.html

如果大家觉得麻烦,我已经为大家打包插件了,回复-刷新 即可下载!

插件下载:https://wuzuhua.cn/797.html

你可能感兴趣的:(资源)