<?xml version="1.0" encoding="utf-8"?>
<parser delay="4500" date="2021.02.07">
    <url><![CDATA[weixin\.qq\.com/\w+]]></url>
    <title><![CDATA[(?:<meta\s+content="(?<title>[^"]+)"\s+property="og:title">|v_title=(?<title>[^,]+))]]></title>
    <thumbnail><![CDATA[<meta\s+content="([^"]+)"\s+property="og:image">]]></thumbnail>
    <duration><![CDATA[(?:<span\s+class="num">(?<duration>[^<]+)</span>|duration=(?<duration>[^,]+))]]></duration>
    <mediaUrl><![CDATA[cr_video_url=([^\$]+)]]></mediaUrl>
    <jsCode><![CDATA[
        try {
            //https://mp.weixin.qq.com/mp/readtemplate?t=pages/video_player_tmpl&action=mpvideo&auto=0&vid=wxv_1226641377421819906
            var video_url = '';
            var duration = 0;
            var vid = (window.location.href.indexOf('vid=') != -1) ? window.location.href.match(/vid=([^&]+)/)[1] : '';
            if (!vid && document.getElementsByTagName('iframe').length != 0) {
                var m = document.getElementsByTagName('iframe')[0].src.match(/vid=([^&]+)/);
                vid = m ? m[1] : vid;
            }
            if (vid) {
                if (vid.length <= 12) {
                    video_url = 'https://v.qq.com/x/page/' + m[1] + '.html#ra';
                    document.body.innerHTML = window.external.getHtmlCode(video_url);
                }
                else {
                    var api_url = 'https://mp.weixin.qq.com/mp/videoplayer?action=get_mp_video_play_url&vid=' + vid;
                    var data = window.external.getHtmlCode(api_url);
                    if (data) {
                        var jo = JSON.parse(data);
                        video_url = jo.url_info[0].url;
                        duration = jo.url_info[0].duration_ms / 1000;
                    }
                }
            }
            if (!video_url && document.getElementsByTagName('iframe').length != 0) {
                var videos = document.getElementsByTagName('iframe')[0].contentDocument.getElementsByTagName('video');
                if (videos.length != 0) {
                    m = videos[0].outerHTML.match(/src=\"([^\"]+)/);
                    if (m)
                        video_url = m[1];
                }
            }

            if (!video_url) {
                if (window.cgiData && window.cgiData.voiceid) {
                    var mid = window.cgiData.voiceid;
                    video_url = 'https://res.wx.qq.com/voice/getvoice?mediaid=' + mid;
                    duration = window.cgiData.duration;
                }
                else if (document.getElementsByTagName('mpvoice').length != 0 && document.getElementsByTagName('mpvoice')[0].outerHTML.indexOf('voice_encode_fileid=') != -1) {
                    var mid = document.getElementsByTagName('mpvoice')[0].outerHTML.match(/voice_encode_fileid=\"([^\"]+)/)[1];
                    video_url = 'https://res.wx.qq.com/voice/getvoice?mediaid=' + mid;
                    duration = parseInt(document.body.innerHTML.match(/play_length=\"([^\"]+)/)[1]) / 1000;
                }
                else if (document.getElementsByClassName('mid_play_box js_btn_play').length != 0) {
                    document.getElementsByClassName('mid_play_box js_btn_play')[0].click();
                    if (document.getElementsByTagName('video').length != 0) {
                        video_url = document.getElementsByTagName('video')[0].src;
                        if (document.getElementsByClassName('js_video_length video_length').length != 0)
                            duration = document.getElementsByClassName('js_video_length video_length')[0].innerText;
                    }
                }
                else if (document.body.innerHTML.match(/url:\s+'[^']+\.mp4.*?'/)) {
                    video_url = document.body.innerHTML.match(/url:\s+'([^']+\.mp4.*?)'/)[1];
                    video_url = video_url.replace(/\\x26amp;/g, '&');
                    if (document.body.innerHTML.match(/duration_ms:\s+'[^']+'/))
                        duration = parseInt(document.body.innerHTML.match(/duration_ms:\s+'([^']+)'/)[1]) / 1000;
                }
            }
            if (!video_url)
                video_url = window.location.href;

            document.body.innerHTML = 'duration=' + duration + ',cr_video_url=' + video_url + '$' + document.body.innerHTML;
        }
        catch (ex) {
        }
    ]]></jsCode>
</parser>