mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-11-16 11:42:22 +08:00
Cherry-picked from linux fork: cli & ICU package fix
This commit is contained in:
parent
1090f9a724
commit
a7c3ecde68
28
BililiveRecorder.Cli/BililiveRecorder.Cli.csproj
Normal file
28
BililiveRecorder.Cli/BililiveRecorder.Cli.csproj
Normal file
|
@ -0,0 +1,28 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<StartupObject>BililiveRecorder.Cli.Program</StartupObject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\TempBuildInfo\BuildInfo.Cli.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Autofac" Version="4.9.4" />
|
||||
<PackageReference Include="CommandLineParser" Version="2.4.3" />
|
||||
</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)
powershell -ExecutionPolicy Bypass -File .\CI\patch_buildinfo.ps1 Cli" />
|
||||
</Target>
|
||||
|
||||
|
||||
</Project>
|
71
BililiveRecorder.Cli/NLog.Debug.config
Normal file
71
BililiveRecorder.Cli/NLog.Debug.config
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
|
||||
autoReload="true"
|
||||
throwExceptions="false"
|
||||
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
|
||||
|
||||
<!-- optional, add some variables
|
||||
https://github.com/nlog/NLog/wiki/Configuration-file#variables
|
||||
-->
|
||||
<variable name="myvar" value="myvalue"/>
|
||||
|
||||
<!--
|
||||
See https://github.com/nlog/nlog/wiki/Configuration-file
|
||||
for information on customizing logging rules and outputs.
|
||||
-->
|
||||
<targets>
|
||||
<target name="WPFLogger" xsi:type="MethodCall" className="BililiveRecorder.WPF.MainWindow, BililiveRecorder.WPF" methodName="AddLog">
|
||||
<parameter layout="[${date:format=HH\:mm\:ss}] ${uppercase:${level}} ${event-properties:item=roomid} ${message} ${exception:format=Message}" />
|
||||
</target>
|
||||
|
||||
<target name="file" xsi:type="File"
|
||||
encoding="utf-8"
|
||||
lineEnding="CRLF"
|
||||
fileName="log.txt"
|
||||
maxArchiveFiles="15"
|
||||
archiveFileName="log_archive.{#}.txt"
|
||||
archiveNumbering="Date"
|
||||
archiveEvery="Day"
|
||||
archiveDateFormat="yyyyMMdd">
|
||||
<layout xsi:type="JsonLayout">
|
||||
<attribute name='time' layout='${longdate}' />
|
||||
<attribute name='level' layout='${level:upperCase=true}'/>
|
||||
<attribute name='pid' layout='${processid}'/>
|
||||
<attribute name='logger' layout='${logger}'/>
|
||||
<attribute name='roomid' layout='${event-properties:item=roomid}'/>
|
||||
<attribute name='message' layout='${message}'/>
|
||||
<attribute name='exception' encode='false'>
|
||||
<layout xsi:type='JsonLayout'>
|
||||
<attribute name='type' layout='${exception:format=Type}'/>
|
||||
<attribute name='message' layout='${exception:format=Message}'/>
|
||||
<attribute name='tostring' layout='${exception:format=ToString}'/>
|
||||
</layout>
|
||||
</attribute>
|
||||
</layout>
|
||||
</target>
|
||||
|
||||
<!--
|
||||
add your targets here
|
||||
See https://github.com/nlog/NLog/wiki/Targets for possible targets.
|
||||
See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
|
||||
-->
|
||||
|
||||
<!--
|
||||
Write events to a file with the date in the filename.
|
||||
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
|
||||
layout="${longdate} ${uppercase:${level}} ${message}" />
|
||||
-->
|
||||
</targets>
|
||||
|
||||
<rules>
|
||||
<!-- add your logging rules here -->
|
||||
<logger name="*" minlevel="Trace" writeTo="WPFLogger"/>
|
||||
<logger name="*" minlevel="Trace" writeTo="file"/>
|
||||
<!--
|
||||
Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f"
|
||||
<logger name="*" minlevel="Debug" writeTo="f" />
|
||||
-->
|
||||
</rules>
|
||||
</nlog>
|
17
BililiveRecorder.Cli/NLog.config
Normal file
17
BililiveRecorder.Cli/NLog.config
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
|
||||
autoReload="true"
|
||||
throwExceptions="false"
|
||||
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log"
|
||||
>
|
||||
<targets>
|
||||
<target name="console" xsi:type="Console" encoding="utf-8"
|
||||
layout="${longdate} ${level:upperCase=true} ${processid} ${logger} ${event-properties:item=roomid} ${message} ${exception:format=Type} ${exception:format=Message} ${exception:format=ToString}"
|
||||
/>
|
||||
</targets>
|
||||
<rules>
|
||||
<logger name="*" minlevel="Info" writeTo="console"/>
|
||||
</rules>
|
||||
</nlog>
|
3168
BililiveRecorder.Cli/NLog.xsd
Normal file
3168
BililiveRecorder.Cli/NLog.xsd
Normal file
File diff suppressed because it is too large
Load Diff
42
BililiveRecorder.Cli/Nlog.Release.config
Normal file
42
BililiveRecorder.Cli/Nlog.Release.config
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
|
||||
autoReload="true"
|
||||
throwExceptions="false"
|
||||
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
|
||||
<targets>
|
||||
<target name="WPFLogger" xsi:type="MethodCall" className="BililiveRecorder.WPF.MainWindow, BililiveRecorder.WPF" methodName="AddLog">
|
||||
<parameter layout="[${date:format=HH\:mm\:ss}] ${uppercase:${level}} ${event-properties:item=roomid} ${message} ${exception:format=Message}" />
|
||||
</target>
|
||||
<target name="file" xsi:type="File"
|
||||
encoding="utf-8"
|
||||
lineEnding="CRLF"
|
||||
fileName="log.txt"
|
||||
maxArchiveFiles="15"
|
||||
archiveFileName="log_archive.{#}.txt"
|
||||
archiveNumbering="Date"
|
||||
archiveEvery="Day"
|
||||
archiveDateFormat="yyyyMMdd">
|
||||
<layout xsi:type="JsonLayout">
|
||||
<attribute name='time' layout='${longdate}' />
|
||||
<attribute name='level' layout='${level:upperCase=true}'/>
|
||||
<attribute name='pid' layout='${processid}'/>
|
||||
<attribute name='logger' layout='${logger}'/>
|
||||
<attribute name='roomid' layout='${event-properties:item=roomid}'/>
|
||||
<attribute name='message' layout='${message}'/>
|
||||
<attribute name='exception' encode='false'>
|
||||
<layout xsi:type='JsonLayout'>
|
||||
<attribute name='type' layout='${exception:format=Type}'/>
|
||||
<attribute name='message' layout='${exception:format=Message}'/>
|
||||
<attribute name='tostring' layout='${exception:format=ToString}'/>
|
||||
</layout>
|
||||
</attribute>
|
||||
</layout>
|
||||
</target>
|
||||
</targets>
|
||||
<rules>
|
||||
<logger name="*" minlevel="Info" writeTo="WPFLogger"/>
|
||||
<logger name="*" minlevel="Trace" writeTo="file"/>
|
||||
</rules>
|
||||
</nlog>
|
67
BililiveRecorder.Cli/Program.cs
Normal file
67
BililiveRecorder.Cli/Program.cs
Normal file
|
@ -0,0 +1,67 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Autofac;
|
||||
using BililiveRecorder.Core;
|
||||
using BililiveRecorder.FlvProcessor;
|
||||
using CommandLine;
|
||||
|
||||
namespace BililiveRecorder.Cli
|
||||
{
|
||||
class Program
|
||||
{
|
||||
private static int roomid = 528819;
|
||||
private static IContainer Container { get; set; }
|
||||
private static ILifetimeScope RootScope { get; set; }
|
||||
private static IRecorder Recorder { get; set; }
|
||||
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
static void Main(string[] _)
|
||||
{
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterModule<FlvProcessorModule>();
|
||||
builder.RegisterModule<CoreModule>();
|
||||
Container = builder.Build();
|
||||
RootScope = Container.BeginLifetimeScope("recorder_root");
|
||||
Recorder = RootScope.Resolve<IRecorder>();
|
||||
if (!Recorder.Initialize(System.IO.Directory.GetCurrentDirectory()))
|
||||
{
|
||||
Console.WriteLine("Initialize Error");
|
||||
return;
|
||||
}
|
||||
Parser.Default
|
||||
.ParseArguments<CommandLineOption>(Environment.GetCommandLineArgs())
|
||||
.WithParsed(Run);
|
||||
}
|
||||
|
||||
private static void Run(CommandLineOption option)
|
||||
{
|
||||
if (option.RoomID == 0) return;
|
||||
roomid = option.RoomID;
|
||||
Recorder.Config.AvoidTxy = true;
|
||||
|
||||
if (Recorder.Where(r => r.RoomId == roomid).Count() == 0)
|
||||
{
|
||||
Recorder.AddRoom(roomid);
|
||||
}
|
||||
logger.Info("开始录播");
|
||||
Task.WhenAll(Recorder.Where(r => r.RoomId == roomid).Select(x => Task.Run(() => x.Start()))).Wait();
|
||||
Console.CancelKeyPress += (sender, e) =>
|
||||
{
|
||||
Task.WhenAll(Recorder.Where(r => r.RoomId == roomid).Select(x => Task.Run(() => x.StopRecord()))).Wait();
|
||||
logger.Info("停止录播");
|
||||
};
|
||||
while (true)
|
||||
{
|
||||
Thread.Sleep(TimeSpan.FromSeconds(10));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class CommandLineOption
|
||||
{
|
||||
[Option('i', "id", Default = 0, HelpText = "room id", Required = false)]
|
||||
public int RoomID { get; set; }
|
||||
}
|
||||
}
|
1
BililiveRecorder.Cli/config.json
Normal file
1
BililiveRecorder.Cli/config.json
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":1,"data":"{\"roomlist\":[],\"feature\":0,\"clip_length_future\":10,\"clip_length_past\":20,\"cutting_mode\":0,\"cutting_number\":10,\"timing_stream_retry\":6000,\"timing_stream_connect\":3000,\"timing_danmaku_retry\":2000,\"timing_check_interval\":300,\"timing_watchdog_timeout\":10000,\"cookie\":\"\",\"avoidtxy\":true}"}
|
5
BililiveRecorder.Cli/runtimeconfig.template.json
Normal file
5
BililiveRecorder.Cli/runtimeconfig.template.json
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"configProperties": {
|
||||
"System.Globalization.Invariant": true
|
||||
}
|
||||
}
|
|
@ -1,16 +1,18 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.27428.1
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.29924.181
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BililiveRecorder.WPF", "BililiveRecorder.WPF\BililiveRecorder.WPF.csproj", "{0C7D4236-BF43-4944-81FE-E07E05A3F31D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BililiveRecorder.Core", "BililiveRecorder.Core\BililiveRecorder.Core.csproj", "{CB9F2D58-181D-49F7-9560-D35A9B9C1D8C}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BililiveRecorder.Core", "BililiveRecorder.Core\BililiveRecorder.Core.csproj", "{CB9F2D58-181D-49F7-9560-D35A9B9C1D8C}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{51748048-1949-4218-8DED-94014ABE7633} = {51748048-1949-4218-8DED-94014ABE7633}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BililiveRecorder.FlvProcessor", "BililiveRecorder.FlvProcessor\BililiveRecorder.FlvProcessor.csproj", "{51748048-1949-4218-8DED-94014ABE7633}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BililiveRecorder.FlvProcessor", "BililiveRecorder.FlvProcessor\BililiveRecorder.FlvProcessor.csproj", "{51748048-1949-4218-8DED-94014ABE7633}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BililiveRecorder.Cli", "BililiveRecorder.Cli\BililiveRecorder.Cli.csproj", "{1B626335-283F-4313-9045-B5B96FAAB2DF}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -18,10 +20,6 @@ Global
|
|||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{51748048-1949-4218-8DED-94014ABE7633}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{51748048-1949-4218-8DED-94014ABE7633}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{51748048-1949-4218-8DED-94014ABE7633}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{51748048-1949-4218-8DED-94014ABE7633}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0C7D4236-BF43-4944-81FE-E07E05A3F31D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0C7D4236-BF43-4944-81FE-E07E05A3F31D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0C7D4236-BF43-4944-81FE-E07E05A3F31D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
|
@ -30,6 +28,14 @@ Global
|
|||
{CB9F2D58-181D-49F7-9560-D35A9B9C1D8C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CB9F2D58-181D-49F7-9560-D35A9B9C1D8C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CB9F2D58-181D-49F7-9560-D35A9B9C1D8C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{51748048-1949-4218-8DED-94014ABE7633}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{51748048-1949-4218-8DED-94014ABE7633}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{51748048-1949-4218-8DED-94014ABE7633}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{51748048-1949-4218-8DED-94014ABE7633}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1B626335-283F-4313-9045-B5B96FAAB2DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1B626335-283F-4313-9045-B5B96FAAB2DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1B626335-283F-4313-9045-B5B96FAAB2DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1B626335-283F-4313-9045-B5B96FAAB2DF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
Loading…
Reference in New Issue
Block a user