diff --git a/Core/RuntimeObject/Download/Snapshot.cs b/Core/RuntimeObject/Download/Snapshot.cs
index efe34b18c..c2bcca536 100644
--- a/Core/RuntimeObject/Download/Snapshot.cs
+++ b/Core/RuntimeObject/Download/Snapshot.cs
@@ -15,28 +15,39 @@ public class Snapshot
///
///
///
- public static (bool state,string message) CreateRecordingSnapshot(long Uid)
+ public static (bool state, string message) CreateRecordingSnapshot(long Uid)
{
- if (Uid == 0) return (false,"UID不能为空");
+ if (Uid == 0) return (false, "UID不能为空");
RoomCardClass Card = new();
- if (!_Room.GetCardForUID(Uid, ref Card) || Card == null || !Card.DownInfo.IsDownload) return (false,"当前房间未开播或未录制");
+ if (!_Room.GetCardForUID(Uid, ref Card) || Card == null || !Card.DownInfo.IsDownload) return (false, "当前房间未开播或未录制");
- string videoFile = Card.DownInfo.DownloadFileList.CurrentOperationVideoFile;
- if (!File.Exists(videoFile)) return (false,"当前直播间还未开始录制流");
+ try
+ {
+ if (Card.DownInfo.DownloadFileList.SnapshotGenerationInProgress) Card.DownInfo.DownloadFileList.SnapshotGenerationInProgress = true;
+ else return (false, "当前房间已有快照正在生成中");
+
+ string videoFile = Card.DownInfo.DownloadFileList.CurrentOperationVideoFile;
+ if (!File.Exists(videoFile)) return (false, "当前直播间还未开始录制流");
- string tempFile = $"{Core.Config.Core_RunConfig._TemporaryFileDirectory}{Path.GetFileName(videoFile)}";
- File.Copy(videoFile, tempFile, true);
+ string tempFile = $"{Core.Config.Core_RunConfig._TemporaryFileDirectory}{Path.GetFileName(videoFile)}";
+ File.Copy(videoFile, tempFile, true);
- var listener = Card.DownInfo.LiveChatListener;
- if (listener != null)
+ var listener = Card.DownInfo.LiveChatListener;
+ if (listener != null)
+ {
+ Danmu.SevaDanmu(listener.DanmuMessage.Danmu, tempFile, Card.Name, Card.RoomId);
+ Danmu.SevaGift(listener.DanmuMessage.Gift, tempFile);
+ Danmu.SevaGuardBuy(listener.DanmuMessage.GuardBuy, tempFile);
+ Danmu.SevaSuperChat(listener.DanmuMessage.SuperChat, tempFile);
+ }
+ return (true, tempFile);
+ }
+ finally
{
- Danmu.SevaDanmu(listener.DanmuMessage.Danmu, tempFile, Card.Name, Card.RoomId);
- Danmu.SevaGift(listener.DanmuMessage.Gift, tempFile);
- Danmu.SevaGuardBuy(listener.DanmuMessage.GuardBuy, tempFile);
- Danmu.SevaSuperChat(listener.DanmuMessage.SuperChat, tempFile);
+ Card.DownInfo.DownloadFileList.SnapshotGenerationInProgress = false;
}
- return (true,tempFile);
+
}
}
}
\ No newline at end of file
diff --git a/Core/RuntimeObject/RoomInfo.cs b/Core/RuntimeObject/RoomInfo.cs
index 72a72f7ba..2b7ec619a 100644
--- a/Core/RuntimeObject/RoomInfo.cs
+++ b/Core/RuntimeObject/RoomInfo.cs
@@ -1452,6 +1452,10 @@ public class DownloadFile
/// 当前正在进行文件写入的视频文件
///
public string CurrentOperationVideoFile { get; set; } = string.Empty;
+ ///
+ /// 是否正在生成快照
+ ///
+ public bool SnapshotGenerationInProgress { get; set; } = false;
}
public DownloadInfo Clone()
diff --git a/Desktop/NetWork/Post.cs b/Desktop/NetWork/Post.cs
index 87fbed162..04b5897a7 100644
--- a/Desktop/NetWork/Post.cs
+++ b/Desktop/NetWork/Post.cs
@@ -24,9 +24,9 @@ public class Post
///
/// URL
/// POST要发送的键值对
- /// 需要额外携带的LongList
+ /// 超时时间
/// 请求返回体
- public static async Task PostBody(string url, Dictionary _dic = null)
+ public static async Task PostBody(string url, Dictionary _dic = null, TimeSpan TimeoutPeriod = default(TimeSpan))
{
if (!string.IsNullOrEmpty(url) && url.Length > 5 && url.Substring(0, 4) != "http")
@@ -37,11 +37,11 @@ public static async Task PostBody(string url, Dictionary _
try
{
Dictionary dic = new Dictionary
- {
- { "access_key_id", Core.Config.Core_RunConfig._DesktopAccessKeyId },
- { "access_key_secret", Core.Config.Core_RunConfig._DesktopAccessKeySecret },
- { "time", DateTimeOffset.Now.ToUnixTimeSeconds().ToString()}
- };
+ {
+ { "access_key_id", Core.Config.Core_RunConfig._DesktopAccessKeyId },
+ { "access_key_secret", Core.Config.Core_RunConfig._DesktopAccessKeySecret },
+ { "time", DateTimeOffset.Now.ToUnixTimeSeconds().ToString()}
+ };
if (_dic != null)
{
foreach (var item in _dic)
@@ -55,12 +55,15 @@ public static async Task PostBody(string url, Dictionary _
dic.Remove("access_key_secret");
using (HttpClient client = new HttpClient())
{
- client.Timeout = new TimeSpan(0, 0, 8);
+ if (TimeoutPeriod == default(TimeSpan))
+ client.Timeout = new TimeSpan(0, 0, 8); // 设置默认值为8秒
+ else
+ client.Timeout = TimeoutPeriod;
var content = new FormUrlEncodedContent(dic);
var response = await client.PostAsync(url, content);
var responseString = response.Content.ReadAsStringAsync().Result;
OperationQueue.pack A = JsonConvert.DeserializeObject>(responseString);
-
+
return A.data;
}
}
@@ -81,6 +84,12 @@ public static async Task PostBody(string url, Dictionary _
{
Log.Warn(nameof(PostBody), $"发起Post请求出错,URL:[{url}],错误堆栈:\r\n{ex.ToString()}", ex, false);
}
+
+ if (ex is TaskCanceledException)
+ {
+ Log.Warn(nameof(PostBody), $"发起Post请求超时,URL:[{url}]", ex);
+ }
+
return default;
}
}
diff --git a/Desktop/Views/Control/CardControl.xaml.cs b/Desktop/Views/Control/CardControl.xaml.cs
index fc9e317d6..8e572ad15 100644
--- a/Desktop/Views/Control/CardControl.xaml.cs
+++ b/Desktop/Views/Control/CardControl.xaml.cs
@@ -208,7 +208,7 @@ private void Snapshot_Task_Click(object sender, RoutedEventArgs e)
};
Task.Run(() =>
{
- var message = NetWork.Post.PostBody<(bool state, string message)>($"{Config.Core_RunConfig._DesktopIP}:{Config.Core_RunConfig._DesktopPort}/api/rec_task/generate_snapshot", dic).Result;
+ var message = NetWork.Post.PostBody<(bool state, string message)>($"{Config.Core_RunConfig._DesktopIP}:{Config.Core_RunConfig._DesktopPort}/api/rec_task/generate_snapshot", dic,new TimeSpan(0,1,0)).Result;
if (!message.state)
{
Log.Info(nameof(Snapshot_Task_Click), $"生成直播间录制快照失败,原因:{message.message}");