mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-11-16 03:32:20 +08:00
~
This commit is contained in:
parent
bab05ec0d7
commit
ba2b438293
28
BililiveRecorder.Core/RecordInfo.cs
Normal file
28
BililiveRecorder.Core/RecordInfo.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace BililiveRecorder.Core
|
||||
{
|
||||
public class RecordInfo
|
||||
{
|
||||
private static readonly Random random = new Random();
|
||||
|
||||
public DirectoryInfo SavePath;
|
||||
|
||||
public string StreamFilePrefix = "录制";
|
||||
public string ClipFilePrefix = "片段";
|
||||
|
||||
public string StreamName = "某直播间";
|
||||
|
||||
public string GetStreamFilePath()
|
||||
=> Path.Combine(SavePath.FullName, $@"{StreamFilePrefix}-{StreamName}-{DateTime.Now.ToString("yyyyMMddHHmmss")}-{random.Next(100, 999)}.flv");
|
||||
|
||||
public string GetClipFilePath()
|
||||
=> Path.Combine(SavePath.FullName, $@"{ClipFilePrefix}-{StreamName}-{DateTime.Now.ToString("yyyyMMddHHmmss")}-{random.Next(100, 999)}.flv");
|
||||
|
||||
public RecordInfo() { }
|
||||
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ namespace BililiveRecorder.Core
|
|||
{
|
||||
public int roomID { get; private set; }
|
||||
public RoomInfo roomInfo { get; private set; }
|
||||
public RecordInfo recordInfo { get; private set; }
|
||||
|
||||
public RecordStatus Status;
|
||||
|
||||
|
@ -22,16 +23,36 @@ namespace BililiveRecorder.Core
|
|||
public FlvStreamProcessor Processor; // FlvProcessor
|
||||
public readonly ObservableCollection<FlvClipProcessor> Clips = new ObservableCollection<FlvClipProcessor>();
|
||||
private HttpWebRequest webRequest;
|
||||
private readonly Settings _settings;
|
||||
|
||||
public RecordedRoom()
|
||||
public RecordedRoom(Settings settings)
|
||||
{
|
||||
_settings = settings;
|
||||
|
||||
_settings.PropertyChanged += _settings_PropertyChanged;
|
||||
|
||||
Processor.TagProcessed += Processor_TagProcessed;
|
||||
Processor.StreamFinalized += Processor_StreamFinalized;
|
||||
Processor.GetFileName = recordInfo.GetStreamFilePath;
|
||||
streamMonitor.StreamStatusChanged += StreamMonitor_StreamStatusChanged;
|
||||
|
||||
UpdateRoomInfo();
|
||||
}
|
||||
|
||||
private void _settings_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(_settings.Clip_Past))
|
||||
{
|
||||
if (Processor != null)
|
||||
Processor.Clip_Past = _settings.Clip_Past;
|
||||
}
|
||||
else if (e.PropertyName == nameof(_settings.Clip_Future))
|
||||
{
|
||||
if (Processor != null)
|
||||
Processor.Clip_Future = _settings.Clip_Future;
|
||||
}
|
||||
}
|
||||
|
||||
private void StreamMonitor_StreamStatusChanged(object sender, StreamStatusChangedArgs e)
|
||||
{
|
||||
if (e.status.isStreaming)
|
||||
|
@ -155,6 +176,7 @@ namespace BililiveRecorder.Core
|
|||
{
|
||||
var clip = Processor.Clip();
|
||||
clip.ClipFinalized += CallBack_ClipFinalized;
|
||||
clip.GetFileName = recordInfo.GetClipFilePath;
|
||||
Clips.Add(clip);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,12 @@ namespace BililiveRecorder.Core
|
|||
public class Recorder
|
||||
{
|
||||
public readonly ObservableCollection<RecordedRoom> Rooms = new ObservableCollection<RecordedRoom>();
|
||||
public readonly Settings settings = new Settings();
|
||||
|
||||
public Recorder()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
25
BililiveRecorder.Core/Settings.cs
Normal file
25
BililiveRecorder.Core/Settings.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace BililiveRecorder.Core
|
||||
{
|
||||
public class Settings : INotifyPropertyChanged
|
||||
{
|
||||
|
||||
public int Clip_Past { get; set; } = 90;
|
||||
public int Clip_Future { get; set; } = 30;
|
||||
|
||||
public string SavePath = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos);
|
||||
|
||||
|
||||
public Settings()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ using System.Net.Sockets;
|
|||
|
||||
namespace BililiveRecorder.Core
|
||||
{
|
||||
internal static class DanmakuUtils
|
||||
internal static class Utils
|
||||
{
|
||||
public static byte[] ToBE(this byte[] b)
|
||||
{
|
||||
|
@ -27,5 +27,15 @@ namespace BililiveRecorder.Core
|
|||
offset += available;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ApplyTo<T>(this T val1, T val2)
|
||||
{
|
||||
foreach (var p in val1.GetType().GetProperties())
|
||||
{
|
||||
var val = p.GetValue(val1);
|
||||
if (!val.Equals(p.GetValue(val2)))
|
||||
p.SetValue(val2, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,6 +11,8 @@ namespace BililiveRecorder.FlvProcessor
|
|||
public List<FlvTag> Tags;
|
||||
private int target = -1;
|
||||
|
||||
public Func<string> GetFileName;
|
||||
|
||||
public FlvClipProcessor(FlvMetadata header, List<FlvTag> past, int future)
|
||||
{
|
||||
Header = header;
|
||||
|
@ -29,7 +31,7 @@ namespace BililiveRecorder.FlvProcessor
|
|||
|
||||
public void FinallizeFile()
|
||||
{
|
||||
using (var fs = new FileStream("", FileMode.CreateNew, FileAccess.ReadWrite))
|
||||
using (var fs = new FileStream(GetFileName(), FileMode.CreateNew, FileAccess.ReadWrite))
|
||||
{
|
||||
fs.Write(FlvStreamProcessor.FLV_HEADER_BYTES, 0, FlvStreamProcessor.FLV_HEADER_BYTES.Length);
|
||||
|
||||
|
|
|
@ -29,10 +29,10 @@ namespace BililiveRecorder.FlvProcessor
|
|||
// 0x00, // the "0th" tag has a length of 0
|
||||
};
|
||||
|
||||
public RecordInfo Info; // not used for now.
|
||||
public FlvMetadata Metadata = null;
|
||||
public event TagProcessedEvent TagProcessed;
|
||||
public event StreamFinalizedEvent StreamFinalized;
|
||||
public Func<string> GetFileName;
|
||||
|
||||
public int Clip_Past = 90;
|
||||
public int Clip_Future = 30;
|
||||
|
@ -53,9 +53,8 @@ namespace BililiveRecorder.FlvProcessor
|
|||
public int TagAudioCount { get; private set; } = 0;
|
||||
private bool hasOffset = false;
|
||||
|
||||
public FlvStreamProcessor(RecordInfo info, string path)
|
||||
public FlvStreamProcessor(string path)
|
||||
{
|
||||
Info = info;
|
||||
_fs = new FileStream(path, FileMode.CreateNew, FileAccess.ReadWrite);
|
||||
if (!_fs.CanSeek)
|
||||
{
|
||||
|
@ -224,12 +223,13 @@ namespace BililiveRecorder.FlvProcessor
|
|||
{
|
||||
lock (_writelock)
|
||||
{
|
||||
return new FlvClipProcessor(Metadata, Tags, 30);
|
||||
return new FlvClipProcessor(Metadata, new List<FlvTag>(Tags), 30);
|
||||
}
|
||||
}
|
||||
|
||||
public void FinallizeFile()
|
||||
{
|
||||
|
||||
lock (_writelock)
|
||||
{
|
||||
Metadata.Meta["duration"] = MaxTimeStamp / 1000.0;
|
||||
|
@ -256,9 +256,9 @@ namespace BililiveRecorder.FlvProcessor
|
|||
|
||||
StreamFinalized?.Invoke(this, new StreamFinalizedArgs() { StreamProcessor = this });
|
||||
|
||||
// TODO: 通知 Clip 也进行保存
|
||||
// TODO: 阻止再尝试写入任何数据
|
||||
// TODO: 清空 Tags List
|
||||
// 通知 Clip 也进行保存
|
||||
// 阻止再尝试写入任何数据
|
||||
// 清空 Tags List
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BililiveRecorder.FlvProcessor
|
||||
{
|
||||
public class RecordInfo
|
||||
{
|
||||
public int roomid;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user