<?xml version="1.0" encoding="utf-8"?>
<parser delay="1500" crpj="true" date="2021.03.24">
    <url><![CDATA[(?:iqiyi\.com|pps\.tv)/(?<id>.+)\.html?]]></url>
    <title><![CDATA[<meta\s+content="([^"]+)"\s+property="og:title">]]></title>
    <thumbnail><![CDATA[thumbnail=([^,]+)]]></thumbnail>
    <duration><![CDATA[duration":(\d+)]]></duration>
    <mediaUrl><![CDATA[cr_video_url=([^\$]+)]]></mediaUrl>
    <ckSign><![CDATA[ignore]]></ckSign>
    <exjs><![CDATA[https://static.iqiyi.com/js/common/f6a3054843de4645b34d205a9f377d25.js]]></exjs>
    <jsCode><![CDATA[
        try {
            //https://www.iqiyi.com/v_23kj7qxfgww.html
            //http://m.iqiyi.com/v_23kj7qxfgww.html?key=b398b8ccbaeacca840073a7ee9b7e7e6
            //不让它用cookie，cookie+annie会致下载失败...只匹配大陆网站，不匹配其它地区比如台湾的
            var thumbnail = document.head.innerHTML.match(/<meta\s+content=\"([^\"]+)\"\s+property=\"og:image\">/)[1];
            if (thumbnail.indexOf('//') == 0)
                thumbnail = 'https:' + thumbnail;
            thumbnail = thumbnail.replace('.jpg', '_1920_1080.jpg');
            var data = window.external.urlExists(thumbnail);
            if (!data) {
                thumbnail = thumbnail.replace('_1920_1080.jpg', '_1280_720.jpg');
                data = window.external.urlExists(thumbnail);
                if (!data) {
                    thumbnail = thumbnail.replace('_1280_720.jpg', '_480_270.jpg');
                    data = window.external.urlExists(thumbnail);
                    if (!data)
                        thumbnail = document.head.innerHTML.match(/<meta\s+content=\"([^\"]+)\"\s+property=\"og:image\">/)[1];
                }
            }
            if (thumbnail.indexOf('//') == 0)
                thumbnail = 'https:' + thumbnail;

            //vip...tvId，能下载的12位，16位的，亦走此解析，比如：http://www.iqiyi.com/v_2ffkws1q3x0.html...2020.09.04发现其又影响正常的1080下载，屏其。比如：https://www.iqiyi.com/v_1xx9yr6ug7w.html
            //比如：https://www.iqiyi.com/v_19rroewhlg.html，payMark为1，但没显示vip，所以再加payMarkUrl判断
            var video_url = '';
            var ppi = Q.PageInfo.playPageInfo;
            var os = (window.external.os != undefined) ? window.external.os : true;
            //vip类
            if (ppi.payMark != 0 && ppi.payMarkUrl) {
                video_url = extract_video(ppi);
                if (!video_url && os)
                    video_url = getol(window.location.href);
            }
            //让路给annie
            //if (!video_url && (!ppi.categoryName || '电影|电视剧|综艺|纪录片'.indexOf(ppi.categoryName) != -1))
            //    video_url = extract_video(ppi);
            if (!video_url)
                video_url = window.location.href;

            document.body.innerHTML = 'thumbnail=' + thumbnail + ',cr_video_url=' + video_url + '$' + document.body.innerHTML;

            //...
            function extract_video(ppi) {
                //...ok，如你所愿！
                if (typeof(window.external.gcv) != 'undefined' && window.external.gcv('Download', 'iQiyiIv') != '')
                    return '';
                if (typeof(cmd5x) != 'function' || !ppi.tvId || !ppi.vid || typeof(window.external.saveData) == 'undefined' || typeof(window.external.getCookieEx) == 'undefined')
                    return '';
                var cookie = window.external.getCookieEx(window.location.href, 'P00001', 2500);
                if (!cookie)
                    return '';

                var vq = parseInt((window.external.vq && window.external.vq.match(/\d+/) ? window.external.vq : '1080').match(/\d+/)[0]);
                var src = window.location.href.indexOf('tw.iqiyi.com') != -1 ? '03020031010010000000' : '03020031010000000000';
                var uid = cookie.match(/P00003=[^;]+/) ? cookie.match(/P00003=([^;]+)/)[1] : '';
                var kuid = cookie.match(/QC005=[^;]+/) ? cookie.match(/QC005=([^;]+)/)[1] : '';
                var dfp = cookie.match(/__dfp=[^;]+/) ? cookie.match(/__dfp=([^;]+)/)[1] : '';
                //2k->1080
                var bid = (vq == 4 || vq == 8) ? 800 : 620;
                //为版权风险及下载稳定性考虑，去除其4k支持
                bid = 620;
                if (vq == 720)
                    bid = 500;
                else if (vq == 480)
                    bid = 300;
                else if (vq == 360)
                    bid = 200;
                var args = '/jp/dash?tvid=' + ppi.tvId + '&bid=' + bid + '&vid=' + ppi.vid + '&src=' + src + '&uid=' + uid + '&k_uid=' + kuid + '&pt=0&lid=&cf=&ct=&dfp=' + dfp + '&qd_v=2&tm=' + Date.now() + '&k_ft2=8191';
                var api_url = 'https://cache.video.iqiyi.com' + args + '&vf=' + cmd5x(args);
                var headers = 'Referer: ' + window.location.href + '\r\nCookie: ' + cookie;
                var data = window.external.getHtmlCodeEx(api_url, headers);
                if (data.indexOf('#EXTM3U') != -1) {
                    data = data.replace('var tvInfoJs=', '');
                    var jo = JSON.parse(data);
                    for (var i = 0; i <= jo.data.program.video.length - 1; i++) {
                        var video = jo.data.program.video[i];
                        if (video._selected)
                            return window.external.saveData(video.m3u8);
                    }
                }
                return '';
            }

            function getol(url) {
                var result = '';
                var os = (window.external.os != undefined) ? window.external.os : true;
                if (!os)
                    return result;

                var api_url = '';
                var data = '';
                var sites = ['https://jx.000180.top/180', 'https://api.927jx.com/wab', 'https://8090.winzoo.cn/jiexi', 'https://1717.ntryjd.net/0526', 'http://api.drgxj.com/jiexi', 'https://vip.bljiex.com'];
                var args = 'url=' + encodeURIComponent(url) + '&time=' + Date.now();
                for (var i = 0; i <= sites.length - 1; i++) {
                    api_url = sites[i] + '/api.php';
                    data = window.external.getPostResult(api_url, args, 'application/x-www-form-urlencoded; charset=UTF-8', api_url);
                    if (!data || data == 'null')
                        continue;
                    //bljiex
                    if (data.indexOf('(') != -1)
                        data = data.match(/\(([^\)]+)/)[1];
                    var jo = JSON.parse(data);
                    if (!jo.url || !window.external.urlExists(jo.url))
                        continue;

                    //m3u8...可能它没有title
                    if (jo.url.match(/php\?\w+=/) && typeof(window.external.saveData) != 'undefined') {
                        var m3u8 = window.external.getHtmlCode(jo.url);
                        if (m3u8 && m3u8.indexOf('#EXTM3U') != -1) {
                            if (m3u8.indexOf('url=') != -1) {
                                var f = function($1, $2) {
                                    return atob($2) + '\n';
                                }
                                m3u8 = m3u8.replace(/http.*?url=([^&]+).*?\s/g, f);
                            }
                            result = window.external.saveData(m3u8);
                            break;
                        }
                    }
                    if (jo.title && jo.title != '视频不存在' && jo.title != '解析系统' && jo.url.indexOf('http') != -1 &&
                        (jo.url.indexOf('m3u8') != -1 || jo.url.indexOf('.mp4') != -1)) {
                        result = jo.url;
                        break;
                    }
                }
                if (!result && typeof(CryptoJS) != 'undefined') {
                    api_url = 'https://dm.voooe.cn/m3u8.m3u8?url=' + url;
                    data = window.external.getHtmlCode(api_url);
                    if (data.indexOf('bt_token') != -1 && data.indexOf('\"url\"') != -1) {
                        var bt_token = data.match(/bt_token\s+=\s+\"([^\"]+)/)[1];
                        var url = data.match(/url\":\"([^\"]+)/)[1];
                        var token_key = CryptoJS.enc.Utf8.parse('dvyYRQlnPRCMdQSe');
                        var token_iv =  CryptoJS.enc.Utf8.parse(bt_token);
                        result = CryptoJS.AES.decrypt(url, token_key, {'iv': token_iv}).toString(CryptoJS.enc.Utf8);
                    }
                }
                if (!result) {
                    data = window.external.getHtmlCode('https://api.126c.cn/?url=' + encodeURIComponent(url), 'https://api.sigujx.com/');
                    if (data.indexOf('sigu_url') != -1) {
                        var su = data.match(/sigu_url\"\s+value=\"([^\"]+)/)[1];
                        args = 'url=' + su;
                        api_url = 'https://zl.126c.cn/zl_api.php';
                        data = window.external.getPostResult(api_url, args, 'application/x-www-form-urlencoded; charset=UTF-8', api_url);
                        if (data) {
                            var jo = JSON.parse(data);
                            if (jo.url)
                                result = jo.url;
                        }
                    }
                }
                if (!result) {
                    api_url = 'https://v.jhys.top/jhjiexi/jianghu.php?v=' + url;
                    data = window.external.getHtmlCode(api_url);
                    if (data.indexOf('\"url\"') != -1)
                        result = data.match(/url\":\s+\"([^\"]+)/)[1];
                }
                if (!result) {
                    api_url = 'https://yi29f.cn/vip01/api.php?url=' + encodeURIComponent(url);
                    data = window.external.getHtmlCode(api_url);
                    if (data && data != 'null') {
                        var jo = JSON.parse(data);
                        if (jo.url)
                            result = jo.url;
                    }
                }
                return result;
            }
        }
        catch (ex) {
        }
    ]]></jsCode>
</parser>