<?xml version="1.0" encoding="utf-8"?>
<parser delay="4500" crpj="true" date="2020.11.21">
    <url><![CDATA[https?://(?:\w+\.)?mgtv\.com/(?:\w/(?:[^/]+/)*(?<id>\d+)\.html|share/video/(?<id>[^/?]+))]]></url>
    <title><![CDATA[title="([^"]+)"]]></title>
    <thumbnail><![CDATA[thumbnail=([^,]+)]]></thumbnail>
    <duration><![CDATA[duration=([^,]+)]]></duration>
    <mediaUrl><![CDATA[cr_video_url=([^\$]+)]]></mediaUrl>
    <ckSign><![CDATA[loginAccount]]></ckSign>
    <jsCode><![CDATA[
        try {
            var href = window.location.href
            var title = document.getElementsByClassName('title e-txthide2').length != 0 ? document.getElementsByClassName('title e-txthide2')[0].innerText : document.title;
            var thumbnail = window.__NUXT__ ? window.__NUXT__.data[0].mediaData.video.imgurl1 || window.__NUXT__.data[0].mediaData.video.imgurl2 : '';
            var duration = window.__NUXT__ ? window.__NUXT__.data[0].mediaData.video.duration : 0;
            var video_url = '';

            if (href.indexOf('share/video') != -1 && href.indexOf('vid=') != -1 && href.indexOf('did=') != -1) {
                var vid = href.match(/vid=([^&]+)/)[1];
                var did = href.match(/did=([^&]+)/)[1];
                var api_url = 'https://tiny.api.mgtv.com/tiny/v1/video/feed?vid=' + vid + '&did=' + did;
                var data = window.external.getHtmlCode(api_url);
                var jo = JSON.parse(data);
                if (jo.data && jo.data.videos.length != 0) {
                    var video = jo.data.videos[0];
                    title = video.title;
                    thumbnail = video.cover;
                    duration = video.duration;
                    api_url = 'https://disp.titan.mgtv.com' + video.url;
                    data = window.external.getHtmlCode(api_url);
                    jo = JSON.parse(data);
                    video_url = jo.info;
                }
            }
            if (!video_url) {
                var entries = window.performance.getEntriesByType('resource');
                var api_url = '';
                var pv_url = '';
                //取api_url，delay须长
                for (let i = 0; i <= entries.length - 1; i++) {
                    var e = entries[i];
                    if (e.name.indexOf('/player/video?') != -1)
                        pv_url = e.name;
                    if (e.name.indexOf('/player/getSource?') != -1) {
                        api_url = e.name;
                        break;
                    }
                }
                if (!api_url && pv_url) {
                    pv_url = pv_url.substr(0, pv_url.indexOf('jsonp_'));
                    var vid = pv_url.match(/video_id=([^&]+)/)[1];
                    var data = window.external.getHtmlCode(pv_url);
                    var jo = JSON.parse(data);
                    if (jo.data && jo.data.atc) {
                        var atc = jo.data.atc;
                        api_url = 'https://pcweb.api.mgtv.com/player/getSource?_support=10000000&tk2=' + atc.tk2 + '&pm2=' + atc.pm2 + '&video_id=' + vid + '&type=pch5&callback=';
                    }
                }
                if (api_url) {
                    if (api_url.indexOf('jsonp_') != -1)
                        api_url = api_url.substr(0, api_url.indexOf('jsonp_'));
                    var data = window.external.getHtmlCode(api_url);
                    var jo = JSON.parse(data);
                    if (jo.data && jo.data.stream && jo.data.stream.length != 0) {
                        for (let i = jo.data.stream.length - 1; i >= 0; i--) {
                            var video = jo.data.stream[i];
                            if (!video.url)
                                continue;

                            api_url = 'https://disp.titan.mgtv.com' + video.url;
                            data = window.external.getHtmlCode(api_url);
                            if (data) {
                                jo = JSON.parse(data);
                                video_url = jo.info;
                            }
                            break;
                        }
                    }
                }
            }
            if (!video_url) {
                var api_url = 'https://v.jhys.top/jhjiexi/jianghu.php?v=' + window.location.href;
                var html = window.external.getHtmlCode(api_url);
                if (html.indexOf('\"url\"') != -1)
                    video_url = html.match(/url\":\s+\"([^\"]+)/)[1];
            }

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