【WordPress 插件】Begin视频播放插件Smartideo支持B站BV号


B站(bilibili)近期调整视频链接ID为BV开头,B站说是为了保护稿件信息安全,容纳更多投稿,维护UP主的权益。但升级后的链接造成WordPres视频播放插件Smartideo中的正则无法获取由数字和大小写字母组成的字符串,原来直接复制粘贴视频地址到文章中调用视频的方法失效,用户已在插件作者网站反映,作者并没有回应。

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

下面添加:

[a-z0-9_=-]+)/(?:index_|#page=)(?<video_id2>[a-z0-9_=-]+)|(?<video_id>[a-z0-9_=-]+))#i', array($this, 'smartvideo_embed_handler_bilibili_bv') );

接下来在大约195行找到:

在其下面“}”大括号下面添加:

 1) ? $matches['video_id2'] : 1; $cid = ''; $embed = $this->get_iframe("//player.bilibili.com/player.html?bvid={$matches['video_id']}&cid={$cid}&page={$page}", $url); return apply_filters( 'embed_bilibili', $embed, $matches, $attr, $url, $rawattr );}

之后直接在文章中添加B站视频地址:

 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']; $data = (array)$request->request($url, array('timeout' => 3)); $json = json_decode($data['body'], true); $cid = $json['cid']; }catch(Exception $e){} */ if(wp_is_mobile() || $this->bilibili_pc_player == 1){ $embed = $this->get_iframe("//player.bilibili.com/player.html?aid={$matches['video_id']}&cid={$cid}&page={$page}", $url); }else{ $embed = $this->get_link($url); } return apply_filters( 'embed_bilibili', $embed, $matches, $attr, $url, $rawattr );}

直接改为:

 1) ? $matches['video_id2'] : 1; $cid = ''; $embed = $this->get_iframe("//player.bilibili.com/player.html?aid={$matches['video_id']}&cid={$cid}&page={$page}", $url); return apply_filters( 'embed_bilibili', $embed, $matches, $attr, $url, $rawattr );}

补充:防止选择清晰度或者点击图标时跳转到B站。

打开Smartideo插件smartideo.php文件找到:

</iframe>

修改为:

</iframe>

修改后会影响其它视频正常加载,修改后同时兼容av和BV号,演示效果:

https://www.bilibili.com/video/BV1F7411o7Hg
https://www.bilibili.com/video/BV1TW411d74L
https://v.youku.com/v_show/id_XNDc0MDcwMjI1Mg==.html?spm=a2hcb.12675304.m_2592_c_9118.d_1&scm=20140719.rcmd.2592.video_XNDc0MDcwMjI1Mg%3D%3D