diff --git a/.editorconfig b/.editorconfig index ff64d52..d1193ae 100644 --- a/.editorconfig +++ b/.editorconfig @@ -15,7 +15,7 @@ insert_final_newline = true indent_size = 2 -[.csproj] +[*.csproj] indent_size = 2 diff --git a/BililiveRecorder.Cli/BililiveRecorder.Cli.csproj b/BililiveRecorder.Cli/BililiveRecorder.Cli.csproj index 8e748b5..3734666 100644 --- a/BililiveRecorder.Cli/BililiveRecorder.Cli.csproj +++ b/BililiveRecorder.Cli/BililiveRecorder.Cli.csproj @@ -1,20 +1,23 @@ - Exe netcoreapp3.1 + enable + 9.0 BililiveRecorder.Cli.Program + win-x64;osx.10.11-x64;linux-arm64;linux-arm;linux-x64 + publish\any + publish\$(RuntimeIdentifier) + false + true - - - PreserveNewest @@ -23,22 +26,17 @@ PreserveNewest - - - - - diff --git a/BililiveRecorder.Cli/Program.cs b/BililiveRecorder.Cli/Program.cs index 7720a2b..2d42ece 100644 --- a/BililiveRecorder.Cli/Program.cs +++ b/BililiveRecorder.Cli/Program.cs @@ -1,5 +1,5 @@ -using System; -using System.ComponentModel.DataAnnotations; +using System; +using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -8,105 +8,110 @@ using BililiveRecorder.Core; using BililiveRecorder.Core.Config; using BililiveRecorder.FlvProcessor; using CommandLine; +using Newtonsoft.Json; using NLog; namespace BililiveRecorder.Cli { - class Program + internal class Program { - private static IContainer Container { get; set; } - private static ILifetimeScope RootScope { get; set; } - private static IRecorder Recorder { get; set; } private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - static void Main(string[] _) + private static void Main(string[] _) { var builder = new ContainerBuilder(); builder.RegisterModule(); builder.RegisterModule(); builder.RegisterType().As().InstancePerMatchingLifetimeScope("recorder_root"); - Container = builder.Build(); + var Container = builder.Build(); + var RootScope = Container.BeginLifetimeScope("recorder_root"); - RootScope = Container.BeginLifetimeScope("recorder_root"); - Recorder = RootScope.Resolve(); - if (!Recorder.Initialize(System.IO.Directory.GetCurrentDirectory())) + var Recorder = RootScope.Resolve(); + if (!Recorder.Initialize(Directory.GetCurrentDirectory())) { Console.WriteLine("Initialize Error"); return; } Parser.Default - .ParseArguments(() => (CommandConfigV1)Recorder.Config, Environment.GetCommandLineArgs()) + .ParseArguments(() => (CommandConfigV1)Recorder.Config, Environment.GetCommandLineArgs()) .WithParsed(Run); - } - private static void Run(ConfigV1 option) - { - foreach (var room in option.RoomList) + return; + void Run(ConfigV1 option) { - if (Recorder.Where(r => r.RoomId == room.Roomid).Count() == 0) + option.EnabledFeature = EnabledFeature.RecordOnly; + foreach (var room in option.RoomList) { - Recorder.AddRoom(room.Roomid); + if (Recorder.Where(r => r.RoomId == room.Roomid).Count() == 0) + { + Recorder.AddRoom(room.Roomid); + } + } + + logger.Info("Using workDir: " + option.WorkDirectory + "\n\tconfig: " + JsonConvert.SerializeObject(option, Formatting.Indented)); + + logger.Info("开始录播"); + Task.WhenAll(Recorder.Select(x => Task.Run(() => x.Start()))).Wait(); + Console.CancelKeyPress += (sender, e) => + { + Task.WhenAll(Recorder.Select(x => Task.Run(() => x.StopRecord()))).Wait(); + logger.Info("停止录播"); + }; + while (true) + { + Thread.Sleep(TimeSpan.FromSeconds(10)); } } - - logger.Info("开始录播"); - Task.WhenAll(Recorder.Select(x => Task.Run(() => x.Start()))).Wait(); - Console.CancelKeyPress += (sender, e) => - { - Task.WhenAll(Recorder.Select(x => Task.Run(() => x.StopRecord()))).Wait(); - logger.Info("停止录播"); - }; - while (true) - { - Thread.Sleep(TimeSpan.FromSeconds(10)); - } } } - class ConfigV1Metadata - { - [Option('o', "dir", Default = ".", HelpText = "Output directory", Required = false)] - [Utils.DoNotCopyProperty] - public object WorkDirectory { get; set; } - - [Option("cookie", HelpText = "Provide custom cookies", Required = false)] - public object Cookie { get; set; } - - [Option("avoidtxy", HelpText = "Avoid Tencent Cloud server", Required = false)] - public object AvoidTxy { get; set; } - - [Option("live_api_host", HelpText = "Use custom api host", Required = false)] - public object LiveApiHost { get; set; } - - [Option("record_filename_format", HelpText = "Recording name format", Required = false)] - public object RecordFilenameFormat { get; set; } - - - - } - - [MetadataType(typeof(ConfigV1Metadata))] - class CommandConfigV1 : ConfigV1 + public partial class CommandConfigV1 : ConfigV1 { [Option('i', "id", HelpText = "room id", Required = true)] - [Utils.DoNotCopyProperty] public string _RoomList { set { var roomids = value.Split(','); - RoomList.Clear(); + this.RoomList.Clear(); foreach (var roomid in roomids) { var room = new RoomV1(); - room.Roomid = Int32.Parse(roomid); + room.Roomid = int.Parse(roomid); room.Enabled = false; - RoomList.Add(room); + this.RoomList.Add(room); } } + } + [Option('o', "dir", Default = ".", HelpText = "Output directory", Required = false)] + public new string WorkDirectory + { + get => base.WorkDirectory; + set => base.WorkDirectory = value; + } + + [Option("cookie", HelpText = "Provide custom cookies", Required = false)] + public new string Cookie + { + get => base.Cookie; + set => base.Cookie = value; + } + + [Option("live_api_host", HelpText = "Use custom api host", Required = false)] + public new string LiveApiHost + { + get => base.LiveApiHost; + set => base.LiveApiHost = value; + } + + [Option("record_filename_format", HelpText = "Recording name format", Required = false)] + public new string RecordFilenameFormat + { + get => base.RecordFilenameFormat; + set => base.RecordFilenameFormat = value; } } -} \ No newline at end of file +} diff --git a/appveyor.yml b/appveyor.yml index 268f334..ac0ec49 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -38,6 +38,13 @@ before_build: build_script: - ps: msbuild /nologo /v:m /p:Configuration="$env:CONFIGURATION" /p:SquirrelBuildTarget="$env:DEPLOY_SITE_GIT\BililiveRecorder" /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" + - ps: msbuild /nologo /v:m /t:BililiveRecorder_Cli:Publish /p:Configuration="$env:CONFIGURATION" /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" + - ps: msbuild /nologo /v:m /t:BililiveRecorder_Cli:Publish /p:Configuration="$env:CONFIGURATION" /p:RuntimeIdentifier="linux-arm" /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" + - ps: msbuild /nologo /v:m /t:BililiveRecorder_Cli:Publish /p:Configuration="$env:CONFIGURATION" /p:RuntimeIdentifier="linux-arm64" /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" + - ps: msbuild /nologo /v:m /t:BililiveRecorder_Cli:Publish /p:Configuration="$env:CONFIGURATION" /p:RuntimeIdentifier="linux-x64" /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" + - ps: msbuild /nologo /v:m /t:BililiveRecorder_Cli:Publish /p:Configuration="$env:CONFIGURATION" /p:RuntimeIdentifier="osx.10.11-x64" /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" + - ps: msbuild /nologo /v:m /t:BililiveRecorder_Cli:Publish /p:Configuration="$env:CONFIGURATION" /p:RuntimeIdentifier="osx-x64" /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" + - ps: msbuild /nologo /v:m /t:BililiveRecorder_Cli:Publish /p:Configuration="$env:CONFIGURATION" /p:RuntimeIdentifier="win-x64" /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" for: - @@ -59,7 +66,21 @@ for: configuration: Debug artifacts: - path: BililiveRecorder.WPF\bin\Debug - name: BililiveRecorderDebugBuild + name: BililiveRecorderWPFDebugBuild + - path: BililiveRecorder.Cli\publish\any + name: BililiveRecorderCliDebugBuild + - path: BililiveRecorder.Cli\publish\linux-arm + name: BililiveRecorderCliDebugBuild-linux-arm + - path: BililiveRecorder.Cli\publish\linux-arm64 + name: BililiveRecorderCliDebugBuild-linux-arm64 + - path: BililiveRecorder.Cli\publish\linux-x64 + name: BililiveRecorderCliDebugBuild-linux-x64 + - path: BililiveRecorder.Cli\publish\osx.10.11-x64 + name: BililiveRecorderCliDebugBuild-osx.10.11-x64 + - path: BililiveRecorder.Cli\publish\osx-x64 + name: BililiveRecorderCliDebugBuild-osx-x64 + - path: BililiveRecorder.Cli\publish\win-x64 + name: BililiveRecorderCliDebugBuild-win-x64 -#on_finish: -# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) +on_finish: + #- ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))