<?xml version="1.0" encoding="utf-8"?>
<parser delay="2500" crpj="true" date="2021.03.29">
    <url><![CDATA[https?://(?:haokan|sv|baijiahao|mr)\.(?:baidu|hao123)\.com/\w.*?(?:id=(?<id>\d+)|u=(?<id>[^/]+))]]></url>
    <title><![CDATA[title="([^"]+)"]]></title>
    <thumbnail><![CDATA[thumbnail="([^"]+)"]]></thumbnail>
    <duration><![CDATA[duration=([^,]+)]]></duration>
    <mediaUrl><![CDATA[cr_video_url=([^\$]+)]]></mediaUrl>
    <jsCode><![CDATA[
        try {
            //https://sv.baidu.com/v?vid=10763543484108659445
            //http://baijiahao.baidu.com/s?id=1670185034546982240
            //其thumbnail中有,，因此加以引号
            var title = '', thumbnail = '', duration = 0, video_url = '';
            if (document.getElementsByTagName('video').length != 0) {
                title = (document.getElementsByTagName('h1').length != 0) ? document.getElementsByTagName('h1')[0].innerText : document.title;
                if (document.head.innerHTML.indexOf('property=\"og:image\"') != -1)
                    thumbnail = document.head.innerHTML.match(/<meta\s+content=\"([^\"]+)\"\s+property=\"og:image\">/)[1];
                if (document.getElementsByClassName('hkplayer-time').length != 0)
                    duration = document.getElementsByClassName('hkplayer-time')[0].innerHTML.match(/<span>([^<]+)/)[1];
                video_url = document.getElementsByTagName('video')[0].src;
                if (document.getElementsByClassName('hkplayer-definition-list').length != 0) {
                    var html = document.getElementsByClassName('hkplayer-definition-list')[0].innerHTML;
                    if (html.indexOf('蓝光') != -1 && html.match(/蓝光\"\s+url=\"([^\"]+)/))
                        video_url = html.match(/蓝光\"\s+url=\"([^\"]+)/)[1];
                }
            }
            else if (window.__PRELOADED_STATE) {
                var cvm = window.__PRELOADED_STATE__.curVideoMeta;
                title = cvm.title;
                thumbnail = cvm.poster;
                duration = cvm.duration;
                var urls = cvm.clarityUrl;
                video_url = urls[urls.length - 1].url;
                //分辨率
                var vq = parseInt((window.external.vq && window.external.vq.match(/\d+/) ? window.external.vq : '1080').match(/\d+/)[0]);
                for (var v in urls) {
                    if (urls[v].vodVideoHW.indexOf(vq) == 0) {
                        video_url = urls[v].url;
                        break;
                    }
                }
            }
            //https://mr.baidu.com/r/f7SAJBCrW8?f=cp&u=fa3dee25e47b69c3
            else if (window.external.url.indexOf('mr.baidu.com') != -1 && window.location.href.indexOf('nid=') != -1) {
                title = document.title;
                var vid = window.location.href.match(/nid=([^&]+)/)[1];
                video_url = 'https://haokan.baidu.com/v?vid=' + vid + '#ra';
            }
            //last...
            if ((!video_url || video_url.indexOf('#ra') == -1) && typeof(gvd) != 'undefined') {
                var url = window.location.href;
                //验证情况，取其跳转地址
                //https://wappass.baidu.com/static/captcha/tuxing.html?
                if (url.indexOf('wappass.baidu.com') != -1)
                    url =  window.external.getRedirectedUrl(window.external.url, '', '_');
                var data = gvd(url);
                if (!video_url || data.indexOf('_original') != -1 || data.indexOf('nowatermark') != -1) {
                    var jo = JSON.parse(data);
                    title = jo.body.title;
                    thumbnail = jo.body.cover_url;
                    video_url = jo.body.video_url;
                    video_url = video_url.replace('#_s=videoparse.cn', '');
                }
            }

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