Merge branch 'NyaMisty-dev' into dev #139

This commit is contained in:
Genteure 2020-12-21 19:09:23 +08:00
commit 31859a67cc
4 changed files with 96 additions and 72 deletions

View File

@ -15,7 +15,7 @@ insert_final_newline = true
indent_size = 2
[.csproj]
[*.csproj]
indent_size = 2

View File

@ -1,20 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>9.0</LangVersion>
<StartupObject>BililiveRecorder.Cli.Program</StartupObject>
<RuntimeIdentifiers>win-x64;osx.10.11-x64;linux-arm64;linux-arm;linux-x64</RuntimeIdentifiers>
<PublishDir Condition=" '$(RuntimeIdentifier)' == '' ">publish\any</PublishDir>
<PublishDir Condition=" '$(RuntimeIdentifier)' != '' ">publish\$(RuntimeIdentifier)</PublishDir>
<SelfContained Condition=" '$(RuntimeIdentifier)' == '' ">false</SelfContained>
<SelfContained Condition=" '$(SelfContained)' == '' ">true</SelfContained>
</PropertyGroup>
<ItemGroup>
<None Remove="config.json" />
<None Remove="NLog.config" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\TempBuildInfo\BuildInfo.Cli.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@ -23,22 +26,17 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="4.9.4" />
<PackageReference Include="CommandLineParser" Version="2.4.3" />
<PackageReference Include="NLog" Version="4.7.6" />
<PackageReference Include="NLog.Config" Version="4.7.6" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BililiveRecorder.Core\BililiveRecorder.Core.csproj" />
<ProjectReference Include="..\BililiveRecorder.FlvProcessor\BililiveRecorder.FlvProcessor.csproj" />
</ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="cd $(SolutionDir)&#xD;&#xA;powershell -ExecutionPolicy Bypass -File .\CI\patch_buildinfo.ps1 Cli" />
</Target>
</Project>

View File

@ -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<FlvProcessorModule>();
builder.RegisterModule<CoreModule>();
builder.RegisterType<CommandConfigV1>().As<ConfigV1>().InstancePerMatchingLifetimeScope("recorder_root");
Container = builder.Build();
var Container = builder.Build();
var RootScope = Container.BeginLifetimeScope("recorder_root");
RootScope = Container.BeginLifetimeScope("recorder_root");
Recorder = RootScope.Resolve<IRecorder>();
if (!Recorder.Initialize(System.IO.Directory.GetCurrentDirectory()))
var Recorder = RootScope.Resolve<IRecorder>();
if (!Recorder.Initialize(Directory.GetCurrentDirectory()))
{
Console.WriteLine("Initialize Error");
return;
}
Parser.Default
.ParseArguments<CommandConfigV1>(() => (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;
}
}
}

View File

@ -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'))