Skip to content

Commit

Permalink
v2.0.0版完成
Browse files Browse the repository at this point in the history
  • Loading branch information
zyzsdy committed Mar 30, 2019
1 parent 8e2948a commit 4c26408
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 16 deletions.
1 change: 0 additions & 1 deletion BiLiRoku/Bililivelib/FlvDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions BiLiRoku/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

75 changes: 64 additions & 11 deletions BiLiRoku/RoomList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -77,6 +78,7 @@ public async void Init()
{
await RefreshInfo();
commentProvider = ReceiveComment();
init_ready = true;
}

public async Task RefreshInfo()
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -116,7 +150,7 @@ public void Destroy()

public void EndProcess()
{
mannul_destroying = true;
force_stoping = true;
downloader?.Stop();
commentProvider?.Disconnect();
}
Expand Down Expand Up @@ -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()
Expand All @@ -180,13 +235,11 @@ public void StartButton()
{
if (record_status)
{
InfoLogger.SendInfo(Roomid, "DEBUG", "停止了?");
force_stoping = true;
Stop();
}
else
{
InfoLogger.SendInfo(Roomid, "DEBUG", "开始了?");

Start();
}

Expand Down Expand Up @@ -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();
}
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions BiLiRoku/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down

0 comments on commit 4c26408

Please sign in to comment.