<?xml version="1.0" encoding="utf-8"?>
<parser delay="1500" referer="true" date="2020.12.01">
    <url><![CDATA[https?://ke\.qq\.com/(?:course/\d+\?taid=(?<id>\d+)|webcourse.*?taid=(?<id>\d+))]]></url>
    <title><![CDATA[(?is)<li\s+class="[^"]+selected.*?<h5[^>]+>([^<]+)</h5>]]></title>
    <thumbnail><![CDATA[<meta\s+content="([^"]+)"\s+itemprop="image"]]></thumbnail>
    <duration><![CDATA[]]></duration>
    <mediaUrl><![CDATA[cr_video_url=([^\$]+)]]></mediaUrl>
    <jsCode><![CDATA[
        try {
            //https://ke.qq.com/course/406898?taid=3309955201774962
            //https://ke.qq.com/webcourse/3267274/103396673#taid=37450743&lite=1&vid=5285890815521696642
            //master_url...
            var taid = window.location.href.match(/taid=(\d+)/)[1];
            var cid = '';
            var term_id = '';
            var fileId = '';
            var re = new RegExp('data-vid=\"(\\d+)\"\\s+data-taid=\"' + taid + '\"\\s+data-tid=\"(\\d+)\"');
            var m = document.body.innerHTML.match(re);
            if (m) {
                cid = window.location.href.match(/course\/(\d+)/)[1];
                term_id = m[2];
                fileId = m[1];
            }
            else {
                re = new RegExp('data-taid=\"' + taid + '\"\\s+data-tid=\"(\\d+)\"\\s+data-vid=\"(\\d+)\"');
                m = document.body.innerHTML.match(re);
                if (m) {
                    cid = window.location.href.match(/course\/(\d+)/)[1];
                    term_id = m[1];
                    fileId = m[2];
                }
                else if (window.location.href.indexOf('term_id') != -1) {
                    cid = window.location.href.match(/cid=(\d+)/)[1];
                    term_id = window.location.href.match(/term_id=(\d+)/)[1];
                    fileId = window.location.href.match(/vid=(\d+)/)[1];
                }
                else {
                    var sub_infos = metaData.terms[0].chapter_info[0].sub_info;
                    for (var idx in sub_infos) {
                        for (var ti in sub_infos[idx].task_info) {
                            if (sub_infos[idx].task_info[ti].taid == taid) {
                                term_id = sub_infos[idx].task_info[ti].term_id;
                                var o = sub_infos[idx].task_info[ti].resid_list;
                                if (typeof(o) == 'string')
                                    fileId = o;
                                else {
                                    for (var ri in o) {
                                        if (o[ri].length == 19) {
                                            fileId = o[ri];
                                            break;
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            }

            if (typeof Object.assign != 'function') {
                Object.assign = function(target) {
                    target = Object(target);
                    for (var index = 1; index < arguments.length; index++) {
                        var source = arguments[index];
                        if (source != null) {
                            for (var key in source) {
                                if (Object.prototype.hasOwnProperty.call(source, key))
                                    target[key] = source[key];
                            }
                        }
                    }
                    return target;
                }
            };

            var t = Math.random().toFixed(4);
            var url = 'https://ke.qq.com/cgi-bin/qcloud/get_token?term_id=' + term_id + '&fileId=' + fileId + '&bkn=&t=' + t;
            var data = window.external.getHtmlCode(url);
            var jo = JSON.parse(data);
            var jr = jo.result;
            url = 'https://playvideo.qcloud.com/getplayinfo/v2/1258712167/' + fileId + '?exper=' + jr.exper + '&sign=' + jr.sign + '&t='+ jr.t + '&us=' + jr.us;
            data = window.external.getHtmlCode(url);
            jo = JSON.parse(data);
            if (jo.videoInfo.masterPlayList) {
                var master_url = jo.videoInfo.masterPlayList.url;
                var r = master_url.split('/');
                e = {id: cid, termId: term_id};
                var token = gt(e);
                r[r.length - 1] = 'voddrm.token.' + token + '.' + r[r.length - 1];
                master_url = r.join('/');
                if (master_url)
                    document.body.innerHTML = 'cr_video_url=' + master_url + '$' + document.body.innerHTML;

                //token...
                function gt(e) {
                    var t = e.termId, n = e.cid, r = e.authType, o = void 0 === r ? 0 : r, i = uin() || 0, s = c('p_skey'), l = c('p_lskey'), f = c('uid_a2'), d = !('2' !== c('uid_type') || !f.length), 
                    p = {
                        uin: i,
                        vod_type: o,
                        cid: n,
                        term_id: t
                    };
                    d ? Object.assign(p, {
                        ext: f
                    }) : Object.assign(p, {
                        plskey: l,
                        pskey: s
                    });
                    var h = function(e) {
                        var t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : '&', n = '';
                        return Object.keys(e).forEach(function(r) {
                            if (void 0 !== e[r]) {
                                var o = e[r];
                                n += '' + t + r + '=' + o
                            }
                        }),
                        n ? n.slice(1) : ''
                    }(p, ';');
                    return (m = h,
                        btoa(encodeURIComponent(m).replace(/%([0-9A-F]{2})/g, function(e, t) {
                            var n = parseInt(t, 16);
                            return String.fromCharCode(n)
                        }))
                    );
                    var m
                };

                function c(e) {
                    var t = document.cookie.match(new RegExp('(^| )' + e + '=([^;]*)(;|$)'));
                    return t ? decodeURIComponent(t[2]) : ''
                };

                function uin() {
                    var e;
                    return 2 == c('uid_type') ? c('uid_uin') || null : e = (e = (e = c('p_luin') || c('p_uin') || c('uin') || c('pt2gguin') || c('adid')) ? parseInt(e.substring(1, e.length), 10) : null) || parseInt(c('uin_cookie'), 10) || null;
                };
            }
        }
        catch (ex) {
        }
    ]]></jsCode>
</parser>