<?xml version="1.0" encoding="utf-8"?>
<parser delay="1500" date="2021.03.04">
    <url><![CDATA[https?://(?:(?:www\.|bangumi\.)?bilibili\.(?:tv|com)/(?:\w+/)?(?:video/(?:av|BV)|anime/(?<id>\d+)/play#|watchlater/#/)(?<id>[^/?#&]+)|b\d+\.tv/(?<id>[^&]+))]]></url>
    <title><![CDATA[title="([^"]+)"]]></title>
    <thumbnail><![CDATA[<meta\s+content="([^"]+)[^>]+property="og:image">]]></thumbnail>
    <duration><![CDATA[duration":(\d+)]]></duration>
    <mediaUrl><![CDATA[cr_video_url=([^\$]+)]]></mediaUrl>
    <ckSign><![CDATA[DedeUserID]]></ckSign>
    <jsCode><![CDATA[
        try {
            //https://b23.tv/PBVqm6
            //不用SESSDATA做cookie标记，虽然点击观看后才会有SESSDATA
            var video_url = window.external.url;
            if (video_url.indexOf('watchlater') != -1) {
                var bvid = video_url.match(/#\/([^\/]+)/)[1];
                video_url = 'https://www.bilibili.com/video/' + bvid;
            }
            //b23.tv->bilibili.com
            if (video_url.indexOf('.tv') != -1)
                video_url = window.location.href;

            var title = '';
            if (document.getElementsByTagName('h1').length != 0)
                title = document.getElementsByTagName('h1')[0].innerText;
            //online...
            if (window.external.url.indexOf('/video/') != -1) {
                var id = window.external.url.match(/video\/([^\/?]+)/)[1];
                var api_url = 'https://xbeibeix.com/api/bilibili/biliplayer/?url=' + id;
                var html = window.external.getHtmlCodecrpj(api_url, 500, '', 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36');
                if (html.indexOf('id=\"player\"') != -1) {
                    video_url = html.match(/id=\"player\"[^>]+url=([^\"]+)/)[1];
                    video_url = decodeURIComponent(video_url).replace(/\\/g, '');
                    if (!title)
                        title = html.match(/<title>(.*?)\s+-/)[1];
                }
            }
            document.body.innerHTML = 'title=\"' + title + '\",cr_video_url=' + video_url + '$' + document.body.innerHTML;
        }
        catch (ex) {
        }
    ]]></jsCode>
</parser>