<?xml version="1.0" encoding="utf-8"?>
<parser delay="2500" crpj="true" referer="true" aria2c="true" speed="500k" date="2021.01.06">
    <url><![CDATA[(?:kuaishou|gifshow|yxixy|chenzhongtech)\.com/(?:u/[^/]+/(?<id>[^\?/]+)|(?:\w/(?<id>[^/]+)|\w+/photo/(?<id>[^/]+))|(?<id>\w{5,})$|(?:short-)?video/(?<id>[^?]+))]]></url>
    <title><![CDATA[title="([^"]+)"]]></title>
    <thumbnail><![CDATA[thumbnail=([^,]+)]]></thumbnail>
    <duration><![CDATA[duration=([^,]+)]]></duration>
    <mediaUrl><![CDATA[cr_video_url=([^\$]+)]]></mediaUrl>
    <ckSign><![CDATA[userId]]></ckSign>
    <headers><![CDATA[User-Agent: Mozilla/5.0 (iPad; CPU OS 12_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1]]></headers>
    <jsCode><![CDATA[
        try {
            //https://live.kuaishou.com/u/3xq6q95i9b5rzdu/3x3uaii9unqgmkk?did=web_7b7921360f68374d283a9ef100261e3b
            //https://video.kuaishou.com/video/3xqfe27brp3zjqa?authorId=3xqvcaurub8ph9k
            //https://video.kuaishou.com/short-video/3xcixxpfkw8avzw?authorId=3xdsmkx5qh3iiw9&streamSource=find
            //以window.location.href求，某些用户电脑上，会跑到快手错误页，因此以Url处之
            var href = window.external.url || window.location.href;
            var title = (document.getElementsByClassName('profile-user-desc').length != 0) ? document.getElementsByClassName('profile-user-desc')[0].innerText : document.title;
            var thumbnail = (document.getElementsByClassName('poster-container-main').length != 0) ? document.getElementsByClassName('poster-container-main')[0].src : '';
            var duration = (document.getElementsByClassName('progress-time-total').length != 0) ? document.getElementsByClassName('progress-time-total')[0].innerText : '0';
            var video_url = '';
            //网页版快手，无水印...https://video.kuaishou.com/
            if (window.pageData) {
                var jo = window.pageData;
                if (jo.video) {
                    title = jo.video.caption;
                    thumbnail = jo.video.poster;
                    //type == 'image'即为图片
                    video_url = (jo.video.type == 'video') ? jo.video.srcNoMark || jo.video.src : thumbnail;
                }
            }

            //...
            var userAgents = [
                'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A403 Safari/8536.25',
                'Mozilla/5.0 (iPhone; CPU iPhone OS 7_0_4 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B554a Safari/9537.53',
                'Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_5 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/6.0 MQQBrowser/6.7 Mobile/13G36 Safari/8536.25 MttCustomUA/2',
                'Mozilla/5.0 (iPhone; CPU iPhone OS 12_4_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/7.0.10(0x17000a21) NetType/4G Language/zh_CN',
                'Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X; zh-CN) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/17D50 UCBrowser/12.8.2.1268 Mobile AliApp(TUnionSDK/0.1.20.3)',
                'Mozilla/5.0 (iPad; U; CPU OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5',
                'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1',
                'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Mobile Safari/537.36',
                'Mozilla/5.0 (Linux; U; Android 7.1.1_r58; zh-cn; MI 6 Build/XPG) AppleWebKit/537.36 (KHTML, like Gecko)Version/4.0 MQQBrowser/9.9 Mobile Safari/537.36',
                'Mozilla/5.0 (Linux; U; Android 7.1.1_r58; zh-cn; R7Plusm Build/hcc) AppleWebKit/537.36 (KHTML, like Gecko)Version/4.0 MQQBrowser/9.9 Mobile Safari/537.36',
                'Mozilla/5.0 (linux; android 9; bla-al00 build/huaweibla-al00; wv) AppleWebKit/537.36 (khtml, like gecko) version/4.0 chrome/74.0.3729.136 mobile safari/537.36',
                'Mozilla/5.0 (Linux; Android 9; YAL-AL10 Build/HUAWEIYAL-AL10; wv) AppleWebKit/537.36 (KHTML, like Gecko)Version/4.0 MQQBrowser/9.9 Mobile Safari/537.36',
                'Mozilla/5.0 (Linux; Android 8.1.0; SM-J727T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.90 Mobile Safari/537.36',
                'Mozilla/5.0 (Linux; U; Android 8.1.0; zh-cn; BLA-AL00 Build/HUAWEIBLA-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/8.9 Mobile Safari/537.36',
                'Mozilla/5.0 (Linux; U; Android 7.1.2; zh-cn; Redmi 5 Plus Build/N2G47H) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.141 Mobile Safari/537.36 XiaoMi/MiuiBrowser/11.7.34',
                'Mozilla/5.0 (Linux; U; Android 10; zh-CN; ONEPLUS A6000 Build/QKQ1.190716.003) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.108 UCBrowser/12.6.8.1048 Mobile Safari/537.36',
            ];
            var dids = [
                'ANDROID_3cb0c2c5e3138b8b',
                'ANDROID_78a2d0549413c568',
                'ANDROID_f6306f0d284efea7',
                'ANDROID_75e6435c2e004e03',
                'ANDROID_2df20b908b4fb6c5',
                'ANDROID_98fd97ba74c79beb',
                'ANDROID_777a69fb8c8e3217',
                'ANDROID_1bf426a578e66446',
                'ANDROID_61c89cad6eb5f695',
                'ANDROID_6db4f21f08ee8ae1',
                'ANDROID_e1576d8a11b727d7',
                'ANDROID_d472c38780351dfd',
                'ANDROID_b1f04806f07029e1',
                'ANDROID_eb5a14cdb1aeaba5',
                'ANDROID_e0344f3488f5ad91',
                'ANDROID_9bdb36aea67f6f0f',
                'ANDROID_9c247dce5ada62a9',
                'ANDROID_aa506e6febe37fa1',
                'ANDROID_09b997298ce2dcee',
                'ANDROID_8a87cd01319f97c4',
                'ANDROID_77deaa2067f50bb1',
                'ANDROID_17688b232126afac',
                'ANDROID_512862d4382dcf37',
                'ANDROID_0110c1baf4042568',
                'ANDROID_78d30f15ede84f68',
                'ANDROID_fa0939f17e8a57f2',
                'ANDROID_fbe51657a7040011',
                'ANDROID_c315216b1e12103c',
                'ANDROID_f98c61cdfaa8ead3',
                'ANDROID_9aeb700e41ff4b62',
                'ANDROID_31a3e40f099f252c',
                'ANDROID_924cff36b2d35e16',
                'ANDROID_4bde6835d9f634a0',
                'ANDROID_f2de1ede8cd3e842',
                'ANDROID_f49cd99b2d1f4052',
                'ANDROID_20e6e8d9c5cee918',
                'ANDROID_2b475235b571d36f',
                'ANDROID_d2e5fe4155c32d78',
            ];
            if (!video_url) {
                var index = Math.floor((Math.random() * userAgents.length));
                var userAgent = userAgents[index];
                if (href.indexOf('/photo/') == -1)
                    href = window.external.getRedirectedUrl(href, href, userAgent);
                if (href.indexOf('/photo/') == -1) {
                    var m = window.external.url.match(/live\.kuaishou\.com\/u\/\w+\/(\w+)/) || window.location.href.match(/live\.kuaishou\.com\/u\/\w+\/(\w+)/);
                    if (m) {
                        var pid = m[1];
                        href = 'https://m.gifshow.com/fw/photo/' + pid;
                    }
                }
                if (href.indexOf('/photo/') != -1) {
                    if (href.indexOf('/') == 0)
                        href = 'https://m.gifshow.com' + href;
                    var cookie = window.external.getCookie(window.location.href) || document.cookie;
                    var headers = 'User-Agent: ' + userAgent + '\r\nContent-Type: application/x-www-form-urlencoded\r\nCookie: ' + cookie;
                    var api_url = href;
                    if (api_url.indexOf('did') == -1 && cookie.indexOf('did') != -1) {
                        var did = cookie.match(/did=([^;]+)/)[1];
                        api_url = api_url + '?did=' + did;
                    }
                    var html = window.external.getHtmlCodeEx(api_url, headers);
                    var data = '';
                    if (html.indexOf('data-pagedata=') != -1)
                        data = htmlDecode(html.match(/data-pagedata=\"([^\"]+)/)[1]);
                    //https://m.yxixy.com/f/X-1w7sqE2tIAF1T3_A
                    if (!data && html.indexOf('window.pageData=') != -1)
                        data = html.match(/window\.pageData=(.*?)<\/script>/)[1];
                    //try again...
                    if (!data) {
                        index = Math.floor((Math.random() * userAgents.length));
                        userAgent = userAgents[index];
                        index = Math.floor((Math.random() * dids.length));
                        var did = dids[index];
                        if (api_url.indexOf('did') == -1)
                            api_url = api_url + '?did=' + did;
                        else
                            api_url = api_url.replace(/did=[^&]+/, 'did=' + did);
                        headers = 'User-Agent: ' + userAgent + '\r\nContent-Type: application/x-www-form-urlencoded\r\nCookie: ' + cookie;
                        html = window.external.getHtmlCodeEx(api_url, headers);
                        if (html.indexOf('data-pagedata=') != -1)
                            data = htmlDecode(html.match(/data-pagedata=\"([^\"]+)/)[1]);
                        if (!data && html.indexOf('window.pageData=') != -1)
                            data = html.match(/window\.pageData=(.*?)<\/script>/)[1];
                    }
                    if (data) {
                        var jo = JSON.parse(data);
                        if (jo.video) {
                            title = jo.video.caption;
                            thumbnail = jo.video.poster;
                            //type == 'image'即为图片
                            video_url = (jo.video.type == 'video') ? jo.video.srcNoMark || jo.video.src : thumbnail;
                        }
                    }
                }
            }

            if (!video_url && typeof(gvd) != 'undefined') {
                var data = gvd(window.external.url);
                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 && document.getElementsByTagName('video').length != 0)
                video_url = document.getElementsByTagName('video')[0].src;

            document.head.innerHTML = '';
            if (!title || title == '...')
                title = '未命名';
            document.body.innerHTML = 'title=\"' + title + '\",thumbnail=' + thumbnail + ',duration=' + duration + ',cr_video_url=' + video_url + '$' + document.body.innerHTML;

            function htmlDecode(s) {
                var span = document.createElement('span');
                span.innerHTML = s;
                return span.innerText || span.textContent;
            }
        }
        catch (ex) {
        }
    ]]></jsCode>
</parser>