腾讯视频推荐的外部引用往往带有广告:底部条广告、暂停悬浮广告、有时甚至片头几十秒的广告,这就很烦。有什么办法可以去掉呢?此文介绍的就是通过代码法插入腾讯视频(免广告)。

不介意广告的朋友,可以使用官方推荐的办法:

复制通用代码,然后加入宽高控制width="780" height="442"

效果如下:

如果你安装了Smartideo 插件,可以直接插入腾讯视频链接,插件将自动解析视频,效果如下:

很明显,此法依赖flash,而谷歌浏览器将在2020年12月停止对flash的支持。

详情>>曾经的霸主,即将消逝的Flash

下面采用代码法实现插入腾讯视频(免广告)(此方法已失效,建议使用Smartideo插件)

一、修改functions文件

在主题functions.php文件中加入

function v_qq_video($atts, $content=null) {
    extract(shortcode_atts(array("vids" => ''), $atts));
    $url = 'https://vv.video.qq.com/getinfo?vids='.$vids.'&platform=101001&charge=0&otype=json';
    $json = file_get_contents($url);
    preg_match('/^QZOutputJson=(.*?);$/',$json,$json2);
    $tempStr = json_decode($json2[1],true);
    $vurl = 'https://ugcws.video.gtimg.com/'.$tempStr['vl']['vi'][0]['fn']."?vkey=".$tempStr['vl']['vi'][0]['fvkey'];
    $video = '<video style="width: 100%;" controls src="'.$vurl.'" poster="https://puui.qpic.cn/qqvideo_ori/0/'.$vids.'_496_280/0"></video>';
    return $video;
}
add_shortcode('tx-video', 'v_qq_video');

二、插入腾讯视频

通过短代码 【tx-video vids=xxx】实现插入视频(【】变[ ])

比如视频:https://v.qq.com/x/page/f0197na7r2i.html

则须使用短代码【tx-video vids=f0197na7r2i】

效果预览:

比如视频:https://v.qq.com/x/cover/x6y6l2e5a2ich2q/b0032o45e5j.html

使用【tx-video vids=b0032o45e5j】

缺点:1、无法调节清晰度;2、视频质量会下降(变模糊)。

三、后期优化步骤

1、添加快捷标签

同样在主题functions.php文件中加入

//编辑器添加腾讯视频简码按钮 注意:下面【】改为[ ]
function wpsites_add_tx_quicktags() {
    if (wp_script_is('quicktags')){
?>
    <script type="text/javascript">
    QTags.addButton( 'txvideo', '腾讯视频', '【tx-video vids=】', "" );
</script>
<?php
    }
}
add_action( 'admin_print_footer_scripts', 'wpsites_add_tx_quicktags' );

切换到文本编辑模式,可通过腾讯视频标签快速插入【tx-video vids=】

2、优化视频质量

直接下载腾讯视频到本地,上传到服务器,插入本地视频。缺点:耗费流量,占服务器资源。

一般,主题支持插入本地视频,如果没有此功能,可以安装一个插件:Elite Video Player。

Invitation
QQ Group
1095632335

created:04/01/2020

Welcome to the Group

Use this card to join us and participate in a pleasant discussion together .

Welcome to JISHUSONGSHU Group,wish you a nice day .