Skip to content

Commit

Permalink
增加保存直播间封面的功能和设置能力
Browse files Browse the repository at this point in the history
  • Loading branch information
CHKZL committed Jun 30, 2024
1 parent 5accaf0 commit 98eba71
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 1 deletion.
22 changes: 22 additions & 0 deletions Core/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,28 @@ public string _Linux_Only_ShellCommand
}
}

private static string SaveCover = "false";
/// <summary>
/// 开始录制时时候保存当前直播间封面
/// 默认值:false
/// </summary>
public bool _SaveCover
{
get
{
return bool.Parse(SaveCover);
}
set
{
if (value.ToString() != SaveCover)
{
SaveCover = value.ToString();
OnPropertyChanged();
ModifyConfig(value);
}
}
}

}
#endregion
}
Expand Down
5 changes: 5 additions & 0 deletions Core/RuntimeObject/DetectRoom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ internal static async void DetectRoom_LiveStart(Object? sender, (RoomCardClass C
roomCard.DownInfo.LiveChatListener.MessageReceived += Basics.LiveChatListener_MessageReceived;
}
bool Reconnection = false;
//保存封面
if(Config.Core_RunConfig._SaveCover)
{
Cover.SaveCover(roomCard);
}
do
{
//如果是启动后第一次房间状态查询就触发下载,那就当作重连处理
Expand Down
33 changes: 33 additions & 0 deletions Core/RuntimeObject/Download/Cover.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Core.LogModule;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Core.RuntimeObject.Download
{
public class Cover
{
public static void SaveCover(RoomCardClass card)
{
Task.Run(() =>
{
try
{
if (card != null && !string.IsNullOrEmpty(card.cover_from_user.Value))
{
string File = $"{Config.Core_RunConfig._RecFileDirectory}{Core.Tools.KeyCharacterReplacement.ReplaceKeyword($"{Config.Core_RunConfig._DefaultLiverFolderName}/{Core.Config.Core_RunConfig._DefaultDataFolderName}{(string.IsNullOrEmpty(Core.Config.Core_RunConfig._DefaultDataFolderName) ? "" : "/")}{Config.Core_RunConfig._DefaultFileName}", DateTime.Now, card.UID)}_cover.jpg";
Basics.CreateDirectoryIfNotExists(File.Substring(0, File.LastIndexOf('/')));
Network.Download.File.DownloadFile(card.cover_from_user.Value, File, true);
Log.Info(nameof(SaveCover), $"保存{card.Name}({card.RoomId})封面完成");
}
}
catch (Exception ex)
{
Log.Error(nameof(SaveCover), $"保存{card.Name}({card.RoomId})封面出现意外错误!", ex, false);
}
});
}
}
}
17 changes: 16 additions & 1 deletion Desktop/Views/Pages/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,22 @@
</Grid>
</StackPanel>
</ui:CardExpander>

<ui:CardControl Padding="15,20,20,20" Header="开始录制时保存当前直播间封面" Icon="{ui:SymbolIcon Image20}" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Right">
<ui:ToggleSwitch Name="SaveCover_SwitchControl" IsChecked="{Binding _SaveCover, Mode=OneWay}" Grid.Row="0" Grid.RowSpan="2" Grid.Column="1" Margin="0,0,16,0" OffContent="" OnContent="" />
</Grid>
</Grid>
</ui:CardControl>

</StackPanel>
</ui:CardExpander>
<ui:CardExpander Grid.Row="4" Icon="{ui:SymbolIcon CalendarPlay20}">
Expand Down
6 changes: 6 additions & 0 deletions Desktop/Views/Pages/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ public async void SaveConfiguration()
{
Config.Core_RunConfig.CutAccordingToTime_For_ComboBox = CutAccordingToTime_For_ComboBox.SelectedIndex;
}
//保存直播间封面
if (Config.Core_RunConfig._SaveCover != SaveCover_SwitchControl.IsChecked)
{
Config.Core_RunConfig._SaveCover = (bool)SaveCover_SwitchControl.IsChecked;
}

#endregion

#region 播放窗口设置
Expand Down

0 comments on commit 98eba71

Please sign in to comment.