<?xml version="1.0" encoding="utf-8"?>
<parser delay="500" crpj="true" date="2021.04.09">
    <url><![CDATA[zhihu\.com/(?:\w?video/(?<id>\d+)|question/(?<id>\d+))]]></url>
    <title><![CDATA[title="([^"]+)"]]></title>
    <thumbnail><![CDATA[thumbnail="([^"]+)"]]></thumbnail>
    <duration><![CDATA[duration=([^,]+)]]></duration>
    <mediaUrl><![CDATA[cr_video_url=([^\$]+)]]></mediaUrl>
    <jsCode><![CDATA[
        try {
            //https://www.zhihu.com/question/313340115/answer/982383152
            //https://video.zhihu.com/video/1326100412617728000
            //https://www.zhihu.com/zvideo/1260399509286469632
            var title = '', thumbnail = '', duration = 0, video_url = '';
            var url = window.external.url || window.location.href;
            var vid = url.indexOf('video') != -1 ? url.match(/video\/(\d+)/)[1] : '';
            if (url.indexOf('/zvideo/') != -1 && document.getElementsByTagName('iframe').length != 0) {
                if (document.getElementsByTagName('h1').length != 0)
                    title = document.getElementsByTagName('h1')[0].innerText;
                video_url = document.getElementsByTagName('iframe')[0].src + '#ra';
            }
            else if (url.indexOf('/question/') != -1 && document.body.innerHTML.indexOf('data-lens-id=') != -1) {
                title = document.body.innerHTML.match(/data-name=\"([^\"]+)/)[1];
                vid = document.body.innerHTML.match(/data-lens-id=\"(\d+)/)[1];
            }
            if (!video_url && vid) {
                var api_url = 'https://lens.zhihu.com/api/v4/videos/' + vid;
                var data = window.external.getHtmlCode(api_url);
                if (data) {
                    if (!title)
                        title = document.title + '_' + vid;
                    var jo = JSON.parse(data);
                    thumbnail = jo.cover_url;
                    var pl = jo.playlist;
                    if (pl.FHD) {
                        duration = pl.FHD.duration;
                        video_url = pl.FHD.play_url;
                    }
                    else if (pl.HD) {
                        duration = pl.HD.duration;
                        video_url = pl.HD.play_url;
                    }
                    else if (pl.SD) {
                        duration = pl.SD.duration;
                        video_url = pl.SD.play_url;
                    }
                    else if (pl.LD) {
                        duration = pl.LD.duration;
                        video_url = pl.LD.play_url;
                    }
                }
            }
            if (!video_url)
                video_url = url;
            document.head.innerHTML = '';
            document.body.innerHTML = 'title=\"' + title + '\",thumbnail=\"' + thumbnail + '\",duration=' + duration + ',cr_video_url=' + video_url + '$';
        }
        catch (ex) {
        }
    ]]></jsCode>
</parser>