<?xml version="1.0" encoding="utf-8"?>
<parser delay="2500" crpj="true" date="2021.02.07">
    <url><![CDATA[(?:https?://(?:\w+\.)?(?:weibo|krcom)|https?://t)\.(?:com|cn)/(?:(?<id>[^&?/]+)/|show\?fid=(?<id>[^&?/]+)|(?<id>[^&?/]+))]]></url>
    <title><![CDATA[title="([^"]+)"]]></title>
    <thumbnail><![CDATA[thumbnail=([^,]+)]]></thumbnail>
    <duration><![CDATA[duration=([^,]+)]]></duration>
    <mediaUrl><![CDATA[cr_video_url=([^\$]+)]]></mediaUrl>
    <audioUrl><![CDATA[cr_audio_url=([^\$]+)]]></audioUrl>
    <ckSign><![CDATA[SUB]]></ckSign>
    <jsCode><![CDATA[
        try {
            //http://t.cn/A6PtC2qR?m=4464958576478425&u=2474085613
            var title = document.title;
            var thumbnail = '';
            var duration = 0;
            var video_url = '', audio_url = '';
            var vq = parseInt((window.external.vq && window.external.vq.match(/\d+/) ? window.external.vq : '1080').match(/\d+/)[0]);
            var href = window.external.url.indexOf('show/') != -1 ? window.external.url : window.location.href;
            //https://weibo.com/tv/show/1034:4513581274955800?from=old_pc_videoshow
            //https://video.weibo.com/show?fid=1034:4602047505563739
            if (href.indexOf('tv/show/') != -1 || href.indexOf('fid') != -1) {
                var oid = href.indexOf('tv/show/') != -1 ? href.match(/show\/([^?]+)/)[1] : href.match(/fid=([^?]+)/)[1];
                var args = 'data={\"Component_Play_Playinfo\":{\"oid\":\"' + oid + '\"}}';
                var cookie = window.external.getCookie(window.location.href) || document.cookie;
                var headers = 'User-Agent: ' + navigator.userAgent + '\r\nContent-Type: application/x-www-form-urlencoded\r\nReferer: ' + href + '\r\nCookie: ' + cookie;
                var api_url = 'https://weibo.com/tv/api/component?page=' + encodeURIComponent('/tv/show/' + oid);
                var data = window.external.getPostResultEx(api_url, args, headers);
                //IE...
                if (data.indexOf('100000') == -1) {
                    cookie = window.external.getCookie(window.location.href, true);
                    headers = 'User-Agent: ' + navigator.userAgent + '\r\nContent-Type: application/x-www-form-urlencoded\r\nReferer: ' + href + '\r\nCookie: ' + cookie;
                    data = window.external.getPostResultEx(api_url, args, headers);
                }
                if (data.indexOf('100000') != -1) {
                    var jo = JSON.parse(data);
                    var pi = jo.data.Component_Play_Playinfo;
                    if (pi) {
                        title = pi.title;
                        thumbnail = pi.cover_image;
                        duration = pi.duration_time;
                        var urls = pi.urls;
                        video_url = pi.urls['1080p'] || pi.urls['高清 1080P'] || pi.urls['720p'] || pi.urls['高清 720P'] || pi.urls['480p'] || pi.urls['标清 480P'];
                        for (var v in pi.urls) {
                            if (v.indexOf(vq + 'P') != -1) {
                                video_url = pi.urls[v];
                                break;
                            }
                        }
                    }
                }
            }
            //https://weibo.com/l/wblive/p/show/1022:2321324586515949814139
            else if (href.indexOf('wblive/p/show/') != -1) {
                var live_id = href.match(/show\/([^?]+)/)[1];
                var api_url = 'https://weibo.com/l/pc/anchor/live?live_id=' + live_id + '&traceId=' + Date.now() + Math.floor(9e5 * Math.random() + 1e5);
                var data = window.external.getHtmlCode(api_url, href);
                if (data.indexOf('100000') != -1) {
                    var jo = JSON.parse(data);
                    title = jo.data.item.desc + '-' + jo.data.user_info.name;
                    thumbnail = jo.data.item.cover;
                    var si = jo.data.item.stream_info;
                    video_url = si.replay_url.origin || si.replay_url.hd || si.replay_url.sd || si.pull.live_origin_hls_url || si.pull.live_origin_flv_url;
                    for (var v in si.replay_url) {
                        if (v == 'origin' && vq == 1080 || v == 'hd' && vq == 720) {
                            video_url = si.replay_url[v];
                            break;
                        }
                    }
                }
            }
            //https://weibo.com/1809745371/J5HlWyJI5?refer_flag=1001030103_
            //https://weibo.com/3925308009/K0Er1viyC?type=comment 音视频分离支
            else if (document.body.innerHTML.match(/objectid=(\d+[^&]+)/)) {
                var mid = document.body.innerHTML.match(/objectid=(\d+[^&]+)/)[1];
                var api_url = 'https://weibo.com/aj/video/getdashinfo?media_ids=' + mid;
                var cookie = window.external.getCookie(window.location.href) || document.cookie;
                headers = 'Referer: ' + href + '\r\nCookie: ' + cookie;
                var data = window.external.getHtmlCodeEx(api_url, headers);
                if (data.indexOf('\"code\":\"100000\"') != -1 && data.indexOf('\"list\"') != -1) {
                    if (vq <= 8)
                        vq = 1080;
                    var jo = JSON.parse(data);
                    var videos = jo.data.list[0].details;
                    for (var i in videos) {
                        var video = videos[i];
                        if (!video.play_info)
                            continue;
                        if (video.play_info.height == vq) {
                            video_url = video.play_info.url;
                            duration = video.play_info.duration;
                        }
                        //audio
                        if (video.play_info.label == 'dash_audio')
                            audio_url = video.play_info.url;
                    }
                }
                else if (document.getElementsByTagName('video').length != 0)
                    video_url = document.getElementsByTagName('video')[0].src;

                title = title.replace(' - 微博', '');
                if (this.FM && this.FM.view) {
                    if (document.body.innerHTML.match(/cover_img=/))
                        thumbnail = unescape(document.body.innerHTML.match(/cover_img=([^&]+)/)[1]);
                    if (document.body.innerHTML.match(/duration=/))
                        duration = document.body.innerHTML.match(/duration=([^&]+)/)[1]
                }
            }

            //...
            if (!video_url && typeof(gvd) != 'undefined') {
                var data = gvd(window.external.url);
                data = data.replace(/\n/g, '');
                var jo = JSON.parse(data);
                if (jo.body && jo.body.video_url) {
                    title = jo.body.title;
                    thumbnail = jo.body.cover_url;
                    video_url = jo.body.video_url;
                }
            }
            if (!video_url)
                video_url = window.location.href;
            document.body.innerHTML = 'title=\"' + title + '\",thumbnail=' + thumbnail + ',duration=' + duration + ',cr_video_url=' + video_url + '$cr_audio_url=' + audio_url + '$';
        }
        catch (ex) {
        }
    ]]></jsCode>
</parser>