From 4c26408eff24183aafc1bf03e4a447a63b41db61 Mon Sep 17 00:00:00 2001 From: Ted Zyzsdy Date: Sat, 30 Mar 2019 11:29:12 +0800 Subject: [PATCH] =?UTF-8?q?v2.0.0=E7=89=88=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BiLiRoku/Bililivelib/FlvDownloader.cs | 1 - BiLiRoku/Properties/AssemblyInfo.cs | 4 +- BiLiRoku/RoomList.cs | 75 +++++++++++++++++++++++---- BiLiRoku/Version.cs | 4 +- 4 files changed, 68 insertions(+), 16 deletions(-) diff --git a/BiLiRoku/Bililivelib/FlvDownloader.cs b/BiLiRoku/Bililivelib/FlvDownloader.cs index 21703d6..9dc3cfc 100644 --- a/BiLiRoku/Bililivelib/FlvDownloader.cs +++ b/BiLiRoku/Bililivelib/FlvDownloader.cs @@ -14,7 +14,6 @@ public class FlvDownloader public bool IsDownloading { get; private set; } private readonly string _savePath; - private readonly string _roomid; private readonly bool _saveComment; private WebClient _wc; private readonly CommentProvider _cmtProvider; diff --git a/BiLiRoku/Properties/AssemblyInfo.cs b/BiLiRoku/Properties/AssemblyInfo.cs index dabb459..dd1f9d2 100644 --- a/BiLiRoku/Properties/AssemblyInfo.cs +++ b/BiLiRoku/Properties/AssemblyInfo.cs @@ -51,7 +51,7 @@ //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, // 方法是按如下所示使用“*”: : // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.0.1")] -[assembly: AssemblyFileVersion("2.0.0.1")] +[assembly: AssemblyVersion("2.0.0.2")] +[assembly: AssemblyFileVersion("2.0.0.2")] [assembly: Guid("0e57f63c-b0b9-4430-95de-c066caa9cc1e")] diff --git a/BiLiRoku/RoomList.cs b/BiLiRoku/RoomList.cs index 5c9c91a..6285fee 100644 --- a/BiLiRoku/RoomList.cs +++ b/BiLiRoku/RoomList.cs @@ -18,7 +18,8 @@ public class RoomTask : INotifyPropertyChanged private bool live_status = false; private bool record_status = false; private bool refreshing = false; - private bool mannul_destroying = false; + private bool force_stoping = false; + private bool init_ready = false; private string realRoomid; private Downloader downloader; private CommentProvider commentProvider; @@ -77,6 +78,7 @@ public async void Init() { await RefreshInfo(); commentProvider = ReceiveComment(); + init_ready = true; } public async Task RefreshInfo() @@ -96,6 +98,23 @@ public async Task RefreshInfo() } Title = RoomInfo.title; + if (Config.Instance.IsWaitStreaming) + { + if (RoomInfo.liveStatus == true && live_status == false) + { + //开播了 + if (init_ready == false) + { + WaitForStart(); + } + else if (record_status == false) Start(); + } + else if (RoomInfo.liveStatus == false && live_status == true) + { + //下播了 + if (record_status == true) Stop(); + } + } live_status = RoomInfo.liveStatus; Username = RoomInfo.username; refreshing = false; @@ -108,6 +127,21 @@ public async Task RefreshInfo() } } + public async void WaitForStart() + { + await Task.Run(async () => + { + if(init_ready == false) + { + while (!init_ready) + { + await Task.Delay(1000); + } + } + if (record_status == false) Start(); + }); + } + public void Destroy() { EndProcess(); @@ -116,7 +150,7 @@ public void Destroy() public void EndProcess() { - mannul_destroying = true; + force_stoping = true; downloader?.Stop(); commentProvider?.Disconnect(); } @@ -150,14 +184,35 @@ private void Start() downloader.OnDownloadInfoUpdate += Downloader_OnDownloadInfoUpdate; downloader.OnStop += Downloader_OnStop; - downloader.Start(CompilePath()); record_status = true; + downloader.Start(CompilePath()); PropertyChange("MainButtonText"); } private void Downloader_OnStop(object sender) { Stop(); + + //如果不是用户触发的,检查状态后重试。 + if (force_stoping) + { + force_stoping = false; + return; + } + var config = Config.Instance; + if (config.IsAutoRetry && live_status) + { + //触发重试 + AutoRetry(); + } + } + + private async void AutoRetry() + { + var config = Config.Instance; + InfoLogger.SendInfo(Roomid, "INFO", "等待 " + config.RefreshTime + " 秒后重试。"); + await Task.Delay(int.Parse(config.RefreshTime ?? "30") * 1000); + if(record_status == false) Start(); //保证同时只有一个下载(否则会下坏) } private void Stop() @@ -180,13 +235,11 @@ public void StartButton() { if (record_status) { - InfoLogger.SendInfo(Roomid, "DEBUG", "停止了?"); + force_stoping = true; Stop(); } else { - InfoLogger.SendInfo(Roomid, "DEBUG", "开始了?"); - Start(); } @@ -236,9 +289,9 @@ private void CommentProvider_OnReceivedComment(object sender, ReceivedCommentArg else { InfoLogger.SendInfo(Roomid, "INFO", "[主播开始直播]"); - - if (downloader?.IsRunning ?? false) return; //重新开始下载直播 + force_stoping = true; + Stop(); Start(); } } @@ -259,7 +312,7 @@ private void CommentProvider_OnDisconnected(object sender, DisconnectEvtArgs e) InfoLogger.SendInfo(Roomid, "INFO", "弹幕服务器断开"); //如果不是用户触发的,则尝试重连。 - if (!mannul_destroying) return; + if (!force_stoping) return; InfoLogger.SendInfo(Roomid, "INFO", "尝试重新连接弹幕服务器"); commentProvider.Connect(); } @@ -316,12 +369,12 @@ await Task.Run(async () => while (true) { await Task.Delay(int.Parse(config.RefreshTime ?? "30") * 1000); - await RefreshInfo(); + RefreshInfo(); } }); } - public async Task RefreshInfo() + public void RefreshInfo() { foreach (var roomtask in this) { diff --git a/BiLiRoku/Version.cs b/BiLiRoku/Version.cs index 9304ea0..d4b9901 100644 --- a/BiLiRoku/Version.cs +++ b/BiLiRoku/Version.cs @@ -11,8 +11,8 @@ namespace BiliRoku internal static class Ver { public const string VER = "2.0.0"; - public const string DATE = "(2019-4-1)"; - public const string DESC = "修改API"; + public const string DATE = "(2019-3-30)"; + public const string DESC = "多直播间支持和自动检测开播功能支持。"; public static readonly string OS_VER = "(" + WinVer.SystemVersion.Major + "." + WinVer.SystemVersion.Minor + "." + WinVer.SystemVersion.Build + ")"; public static readonly string UA = "FeelyBlog/1.1 BiliRoku/2.0.0 " + OS_VER + " AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36"; }