Exemplo n.º 1
0
        public void Start(string uri)
        {
            //初始化
            _nextCheck = 300000;

            _wc = new WebClient();
            _wc.Headers.Add("Accept: */*");
            _wc.Headers.Add("User-Agent: " + Ver.UA);
            _wc.Headers.Add("Accept-Language: zh-CN,zh;q=0.8,en;q=0.6,ja;q=0.4");
            _wc.DownloadFileCompleted   += StopDownload;
            _wc.DownloadProgressChanged += ShowProgress;

            _compiledPath = CompilePath(_savePath, _roomid);
            IsDownloading = true;

            //如果目录不存在,那么先创建目录。
            // ReSharper disable AssignNullToNotNullAttribute
            if (!System.IO.Directory.Exists(GetDirectoryName(_compiledPath)))
            {
                System.IO.Directory.CreateDirectory(GetDirectoryName(_compiledPath));
            }
            // ReSharper restore AssignNullToNotNullAttribute
            var startTimestamp = Convert.ToInt64((DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalMilliseconds);

            _wc.DownloadFileAsync(new Uri(uri), _compiledPath);
            //如果勾选了“同时保存弹幕”,则开始下载弹幕
            if (!_saveComment)
            {
                return;
            }
            var xmlPath = ChangeExtension(_compiledPath, "xml");

            _xmlBuilder = new CommentBuilder(xmlPath, startTimestamp, _cmtProvider);
            _xmlBuilder.Start();
        }
Exemplo n.º 2
0
        public void Start(string uri)
        {
            //初始化
            _nextCheck = 300000;

            _wc = new WebClient();
            _wc.Headers.Add("Accept: */*");
            _wc.Headers.Add("User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36");
            _wc.Headers.Add("Accept-Language: zh-CN,zh;q=0.8,en;q=0.6,ja;q=0.4");
            _wc.Headers.Add("Origin: https://live.bilibili.com");
            _wc.Headers.Add($"Referer: https://live.bilibili.com/blanc/{_roomid}?liteVersion=true");
            _wc.Headers.Add("Sec-Fetch-Site: cross-site");
            _wc.Headers.Add("Sec-Fetch-Mode: cors");
            _wc.DownloadFileCompleted   += StopDownload;
            _wc.DownloadProgressChanged += ShowProgress;

            _downloaddur = 0;
            _timer       = new Timer(new TimerCallback((e) => { _downloaddur += 100; }), null, 0, 100);

            IsDownloading = true;

            //如果目录不存在,那么先创建目录。
            // ReSharper disable AssignNullToNotNullAttribute
            if (!System.IO.Directory.Exists(GetDirectoryName(_savePath)))
            {
                System.IO.Directory.CreateDirectory(GetDirectoryName(_savePath));
            }
            // ReSharper restore AssignNullToNotNullAttribute
            var startTimestamp = Convert.ToInt64((DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalMilliseconds);

            _wc.DownloadFileAsync(new Uri(uri), _savePath);
            //如果勾选了“同时保存弹幕”,则开始下载弹幕
            if (!_saveComment)
            {
                return;
            }
            var xmlPath = ChangeExtension(_savePath, "xml");

            _xmlBuilder = new CommentBuilder(xmlPath, startTimestamp, _cmtProvider);
            try
            {
                _xmlBuilder.Start();
            }
            catch
            {
                throw;
            }
        }