2018-03-20 00:12:32 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace BililiveRecorder.Core
|
|
|
|
|
{
|
2018-10-24 14:33:05 +08:00
|
|
|
|
public class RecordInfo : IRecordInfo
|
2018-03-20 00:12:32 +08:00
|
|
|
|
{
|
|
|
|
|
private static readonly Random random = new Random();
|
|
|
|
|
|
2018-10-25 19:20:23 +08:00
|
|
|
|
private ISettings Settings { get; }
|
|
|
|
|
public string SavePath { get => Settings.SavePath; }
|
2018-03-20 00:12:32 +08:00
|
|
|
|
|
2018-10-24 14:33:05 +08:00
|
|
|
|
public string StreamFilePrefix { get; set; } = "录制";
|
|
|
|
|
public string ClipFilePrefix { get; set; } = "剪辑";
|
2018-03-20 00:12:32 +08:00
|
|
|
|
|
2018-10-24 14:33:05 +08:00
|
|
|
|
public string StreamName { get; set; } = "某直播间";
|
2018-03-20 00:12:32 +08:00
|
|
|
|
|
|
|
|
|
public string GetStreamFilePath()
|
2018-05-10 06:27:53 +08:00
|
|
|
|
=> Path.Combine(SavePath, RemoveInvalidFileName($@"{StreamFilePrefix}-{StreamName}-{DateTime.Now.ToString("yyyyMMddHHmmss")}-{random.Next(100, 999)}.flv"));
|
2018-03-20 00:12:32 +08:00
|
|
|
|
|
|
|
|
|
public string GetClipFilePath()
|
2018-05-10 06:27:53 +08:00
|
|
|
|
=> Path.Combine(SavePath, RemoveInvalidFileName($@"{ClipFilePrefix}-{StreamName}-{DateTime.Now.ToString("yyyyMMddHHmmss")}-{random.Next(100, 999)}.flv"));
|
2018-05-08 08:22:32 +08:00
|
|
|
|
|
|
|
|
|
private static string RemoveInvalidFileName(string name)
|
|
|
|
|
{
|
|
|
|
|
foreach (char c in Path.GetInvalidFileNameChars())
|
2018-10-24 14:33:05 +08:00
|
|
|
|
{
|
2018-05-08 08:22:32 +08:00
|
|
|
|
name = name.Replace(c, '_');
|
2018-10-24 14:33:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-08 08:22:32 +08:00
|
|
|
|
return name;
|
|
|
|
|
}
|
2018-03-20 00:12:32 +08:00
|
|
|
|
|
2018-10-25 19:20:23 +08:00
|
|
|
|
public RecordInfo(string name, ISettings settings)
|
2018-03-21 20:56:56 +08:00
|
|
|
|
{
|
|
|
|
|
StreamName = name;
|
2018-10-25 19:20:23 +08:00
|
|
|
|
Settings = settings;
|
2018-03-21 20:56:56 +08:00
|
|
|
|
}
|
2018-03-20 00:12:32 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|