mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-11-16 11:42:22 +08:00
支持自定义保存目录结构
This commit is contained in:
parent
f903336f27
commit
d94ff4a3a5
|
@ -138,8 +138,8 @@ namespace BililiveRecorder.Core.Config
|
|||
|
||||
private string _cookie = string.Empty;
|
||||
|
||||
private string _record_filename_format = @"record-{room_id}-{date}-{time}-{random}";
|
||||
private string _clip_filename_format = @"record-{room_id}-{date}-{time}-{random}";
|
||||
private string _record_filename_format = @"{roomid}-{name}\录制-{roomid}-{date}-{time}-{title}.flv";
|
||||
private string _clip_filename_format = @"{roomid}-{name}\剪辑片段-{roomid}-{date}-{time}-{title}.flv";
|
||||
|
||||
private bool _avoidTxy = true;
|
||||
}
|
||||
|
|
|
@ -427,11 +427,9 @@ namespace BililiveRecorder.Core
|
|||
Dispose(true);
|
||||
}
|
||||
|
||||
private string GetStreamFilePath() => Path.Combine(_config.WorkDirectory, RoomId.ToString(), "record",
|
||||
$@"{FormatFilename(_config.RecordFilenameFormat)}.flv".RemoveInvalidFileName());
|
||||
private string GetStreamFilePath() => FormatFilename(_config.RecordFilenameFormat);
|
||||
|
||||
private string GetClipFilePath() => Path.Combine(_config.WorkDirectory, RoomId.ToString(), "clip",
|
||||
$@"{FormatFilename(_config.ClipFilenameFormat)}.flv".RemoveInvalidFileName());
|
||||
private string GetClipFilePath() => FormatFilename(_config.ClipFilenameFormat);
|
||||
|
||||
private string FormatFilename(string formatString)
|
||||
{
|
||||
|
@ -439,12 +437,53 @@ namespace BililiveRecorder.Core
|
|||
string date = now.ToString("yyyyMMdd");
|
||||
string time = now.ToString("HHmmss");
|
||||
string randomStr = random.Next(100, 999).ToString();
|
||||
return formatString.Replace(@"{date}", date)
|
||||
|
||||
var filename = formatString
|
||||
.Replace(@"{date}", date)
|
||||
.Replace(@"{time}", time)
|
||||
.Replace(@"{random}", randomStr)
|
||||
.Replace(@"{room_id}", RoomId.ToString())
|
||||
.Replace(@"{title}", Title)
|
||||
.Replace(@"{streamer_name}", StreamerName);
|
||||
.Replace(@"{roomid}", RoomId.ToString())
|
||||
.Replace(@"{title}", Title.RemoveInvalidFileName())
|
||||
.Replace(@"{name}", StreamerName.RemoveInvalidFileName());
|
||||
|
||||
if (!filename.EndsWith(".flv", StringComparison.OrdinalIgnoreCase))
|
||||
filename += ".flv";
|
||||
|
||||
filename = Path.Combine(_config.WorkDirectory, filename);
|
||||
filename = Path.GetFullPath(filename);
|
||||
|
||||
if (!CheckPath(_config.WorkDirectory, Path.GetDirectoryName(filename)))
|
||||
{
|
||||
logger.Log(RoomId, LogLevel.Warn, "录制文件位置超出允许范围,请检查设置。将写入到默认路径。");
|
||||
filename = Path.Combine(_config.WorkDirectory, RoomId.ToString(), $"{RoomId}-{date}-{time}-{randomStr}.flv");
|
||||
}
|
||||
|
||||
if (new FileInfo(filename).Exists)
|
||||
{
|
||||
logger.Log(RoomId, LogLevel.Warn, "录制文件名冲突,请检查设置。将写入到默认路径。");
|
||||
filename = Path.Combine(_config.WorkDirectory, RoomId.ToString(), $"{RoomId}-{date}-{time}-{randomStr}.flv");
|
||||
}
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
private static bool CheckPath(string parent, string child)
|
||||
{
|
||||
DirectoryInfo di_p = new DirectoryInfo(parent);
|
||||
DirectoryInfo di_c = new DirectoryInfo(child);
|
||||
|
||||
bool isParent = false;
|
||||
while (di_c.Parent != null)
|
||||
{
|
||||
if (di_c.Parent.FullName == di_p.FullName)
|
||||
{
|
||||
isParent = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
di_c = di_c.Parent;
|
||||
}
|
||||
return isParent;
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
|
|
@ -322,9 +322,8 @@
|
|||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock HorizontalAlignment="Left">文件名变量说明:</TextBlock>
|
||||
<TextBlock Grid.Row="1" HorizontalAlignment="Left">日期: {date} 时间: {time} 房号: {room_id}</TextBlock>
|
||||
<TextBlock Grid.Row="2" HorizontalAlignment="Left">随机数: {random} 主播名: {streamer_name}</TextBlock>
|
||||
<TextBlock Grid.Row="4" HorizontalAlignment="Left">直播标题: {title}</TextBlock>
|
||||
<TextBlock Grid.Row="1" HorizontalAlignment="Left">日期: {date} 时间: {time} 房间号: {roomid}</TextBlock>
|
||||
<TextBlock Grid.Row="2" HorizontalAlignment="Left">标题: {title} 主播名: {name} 随机数: {random}</TextBlock>
|
||||
</Grid>
|
||||
<!--
|
||||
<TextBlock Grid.Row="4" Grid.Column="0"></TextBlock>
|
||||
|
|
Loading…
Reference in New Issue
Block a user