<?xml version="1.0" encoding="utf-8"?>
<parser delay="500" crpj="true" referer="true" date="2021.04.09">
    <url><![CDATA[tiktok\.com/(?:.*?/video/(?<id>\d+)|(?<id>[^/]+))]]></url>
    <title><![CDATA[title="([^"]+)"]]></title>
    <thumbnail><![CDATA[thumbnail=([^,]+)]]></thumbnail>
    <duration><![CDATA[duration=([^,]+)]]></duration>
    <mediaUrl><![CDATA[cr_video_url=([^\$]+)]]></mediaUrl>
    <delegate><![CDATA[about:blank]]></delegate>
    <ckSign><![CDATA[tt_webid]]></ckSign>
    <jsCode><![CDATA[
        try {
            //https://www.tiktok.com/@aries_8248/video/6941615126386674945
            var cookie = window.external.getCookie(window.external.url) || 'tt_webid=6944547150386955778';
            var data =  window.external.getHtmlCodeEx(window.external.url, 'Cookie: ' + cookie);
            var title = (data.indexOf('\"desc\"') != -1) ? data.match(/\"desc\":\"([^\"]+)/)[1] : document.title;
            var thumbnail = (data.indexOf('\"cover\"') != -1) ? data.match(/\"cover\":\"([^\"]+)/)[1] : '';
            var duration = (data.indexOf('\"duration\"') != -1) ? data.match(/\"duration\":(\d*)/)[1] : '';
            var video_url = '';
            var play_url = (data.indexOf('\"urls\"') != -1) ? data.match(/\"urls\":\[\"([^\"]+)/)[1] : '';
            if (play_url) {
                data = window.external.getHtmlCode(play_url, window.external.url);
                if (data.indexOf('vid:') != -1) {
                    var vid = data.match(/vid:(\w+)/)[1];
                    video_url = 'https://api2.musical.ly/aweme/v1/play/?video_id=' + vid + '&vr_type=0&is_play_url=1&source=PackSourceEnum_PUBLISH&media_type=4';
                    video_url = window.external.getRedirectedUrl(video_url, '', 'okhttp');
                }
            }
            if (!video_url && typeof(gvd) != 'undefined') {
                data = gvd(window.external.url);
                //try again
                if (data.indexOf('"body":[]') != -1) {
                    delay(1500);
                    data = gvd(window.external.url);
                }
                var jo = JSON.parse(data);
                if (jo.body && jo.body.video_url) {
                    title = jo.body.title || title;
                    thumbnail = thumbnail || jo.body.cover_url;
                    video_url = jo.body.video_url;
                }
            }
            if (!video_url)
                video_url = play_url || window.external.url;
            document.body.innerHTML = 'title=\"' + title + '\",thumbnail=' + thumbnail + ',duration=' + duration + ',cr_video_url=' + video_url + '$';
        }
        catch (ex) {
        }
    ]]></jsCode>
</parser>