<?xml version="1.0" encoding="utf-8"?>
<parser delay="500" speed="1024k" crpj="true" aria2c="true" date="2021.03.23">
    <url><![CDATA[douyin\.com/(?:(?<id>\w{6})|share/video/(?<id>\d+))]]></url>
    <title><![CDATA[title="([^"]+)"]]></title>
    <thumbnail><![CDATA[thumbnail=([^,]+)]]></thumbnail>
    <duration><![CDATA[duration=([^,]+)]]></duration>
    <mediaUrl><![CDATA[<video[^>]+\bsrc="([^"]+)"]]></mediaUrl>
    <headers><![CDATA[User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1]]></headers>
    <jsCode><![CDATA[
        try {
            //http://v.douyin.com/5vmsLk/
            if (document.getElementsByClassName('play-btn').length != 0)
                document.getElementsByClassName('play-btn')[0].click();

            var title = (document.getElementsByClassName('desc').length != 0) ? document.getElementsByClassName('desc')[0].innerText : document.title;
            var duration = 0;
            var m = document.body.innerHTML.match(/background-image:\s+url\(\"([^\"]+)/);
            var thumbnail = m ? m[1] : '';
            var video_url = '';
            var url = window.external.url || window.location.href;
            try {
                var item_id = window.location.href.match(/video\/([^\/?]+)/)[1];
                var api_url = 'https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=' + item_id + '&dytk=';
                var data = window.external.getHtmlCode(api_url, url);
                var jo = JSON.parse(data);
                if (jo.item_list.length != 0) {
                    title = jo.item_list[0].desc;
                    thumbnail = jo.item_list[0].video.cover.url_list[0];
                    duration = jo.item_list[0].duration / 1000;
                    if (jo.item_list[0].video.play_addr.url_list.length != 0) {
                        video_url = jo.item_list[0].video.play_addr.url_list[0];
                        if (video_url.indexOf('playwm') != -1)
                            video_url = video_url.replace('playwm', 'play');
                        var r = window.external.getRedirectedUrl(video_url, url, 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1');
                        video_url = (r && r != video_url) ? r : '';
                    }
                }
            }
            catch (ex) {
            }
            if (typeof(fv) != 'undefined' && (fv == '1.5.7.3' || fv == '1.5.5.3') && (!an || an.indexOf('CRTubeGet') != -1))
                video_url = '_';
            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.body.innerHTML = 'title=\"' + title + '\",thumbnail=' + thumbnail + ',duration=' + duration + ',<video src=\"' + video_url + '\"$' + document.body.innerHTML;
        }
        catch (ex) {
        }
    ]]></jsCode>
</parser>