Merge pull request #39 from Bililive/dev

Release 1.1.5
This commit is contained in:
Genteure 2019-01-31 14:33:05 +08:00 committed by GitHub
commit fb21eb20c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 62 additions and 35 deletions

View File

@ -11,7 +11,6 @@
<UpgradeBackupLocation> <UpgradeBackupLocation>
</UpgradeBackupLocation> </UpgradeBackupLocation>
<OldToolsVersion>2.0</OldToolsVersion> <OldToolsVersion>2.0</OldToolsVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>none</DebugType> <DebugType>none</DebugType>
@ -19,7 +18,6 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Autofac" Version="4.8.1" /> <PackageReference Include="Autofac" Version="4.8.1" />
<PackageReference Include="DnsClient" Version="1.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" /> <PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="NLog" Version="4.5.10" /> <PackageReference Include="NLog" Version="4.5.10" />
</ItemGroup> </ItemGroup>

View File

@ -8,6 +8,11 @@ namespace BililiveRecorder.Core.Config
{ {
public static bool Load(string directory, ConfigV1 config = null) public static bool Load(string directory, ConfigV1 config = null)
{ {
if (!Directory.Exists(directory))
{
return false;
}
var filepath = Path.Combine(directory, "config.json"); var filepath = Path.Combine(directory, "config.json");
if (File.Exists(filepath)) if (File.Exists(filepath))
{ {

View File

@ -1,6 +1,5 @@
using BililiveRecorder.Core.Config; using BililiveRecorder.Core.Config;
using BililiveRecorder.FlvProcessor; using BililiveRecorder.FlvProcessor;
using DnsClient;
using NLog; using NLog;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -20,11 +19,6 @@ namespace BililiveRecorder.Core
private static readonly Logger logger = LogManager.GetCurrentClassLogger(); private static readonly Logger logger = LogManager.GetCurrentClassLogger();
private static readonly Random random = new Random(); private static readonly Random random = new Random();
private static readonly LookupClient lookupClient = new LookupClient()
{
ThrowDnsErrors = true,
};
private int _roomid; private int _roomid;
private int _realRoomid; private int _realRoomid;
private string _streamerName; private string _streamerName;
@ -215,11 +209,7 @@ namespace BililiveRecorder.Core
{ {
using (var client = new HttpClient()) using (var client = new HttpClient())
{ {
var raw_uri = new Uri(BililiveAPI.GetPlayUrl(RealRoomid));
client.Timeout = TimeSpan.FromMilliseconds(_config.TimingStreamConnect); client.Timeout = TimeSpan.FromMilliseconds(_config.TimingStreamConnect);
client.DefaultRequestHeaders.Host = raw_uri.Host;
client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*")); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*"));
client.DefaultRequestHeaders.UserAgent.Clear(); client.DefaultRequestHeaders.UserAgent.Clear();
@ -227,13 +217,11 @@ namespace BililiveRecorder.Core
client.DefaultRequestHeaders.Referrer = new Uri("https://live.bilibili.com"); client.DefaultRequestHeaders.Referrer = new Uri("https://live.bilibili.com");
client.DefaultRequestHeaders.Add("Origin", "https://live.bilibili.com"); client.DefaultRequestHeaders.Add("Origin", "https://live.bilibili.com");
var ips = lookupClient.Query(raw_uri.DnsSafeHost, QueryType.A).Answers?.ARecords()?.ToArray(); string flv_path = BililiveAPI.GetPlayUrl(RealRoomid);
var ip = ips[random.Next(0, ips.Count())].Address; logger.Log(RealRoomid, LogLevel.Info, "连接直播服务器 " + new Uri(flv_path).Host);
logger.Log(RealRoomid, LogLevel.Debug, "直播流地址: " + flv_path);
logger.Log(RealRoomid, LogLevel.Info, "连接直播服务器 " + raw_uri.Host + " (" + ip + ")"); _response = await client.GetAsync(flv_path, HttpCompletionOption.ResponseHeadersRead);
logger.Log(RealRoomid, LogLevel.Debug, "直播流地址: " + raw_uri.ToString());
_response = await client.GetAsync(new UriBuilder(raw_uri) { Host = ip.ToString() }.Uri, HttpCompletionOption.ResponseHeadersRead);
} }
if (_response.StatusCode != HttpStatusCode.OK) if (_response.StatusCode != HttpStatusCode.OK)

View File

@ -53,6 +53,9 @@
<Reference Include="Autofac, Version=4.8.1.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL"> <Reference Include="Autofac, Version=4.8.1.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<HintPath>..\packages\Autofac.4.8.1\lib\net45\Autofac.dll</HintPath> <HintPath>..\packages\Autofac.4.8.1\lib\net45\Autofac.dll</HintPath>
</Reference> </Reference>
<Reference Include="CommandLine, Version=2.4.3.0, Culture=neutral, PublicKeyToken=de6f01bd326f8c32, processorArchitecture=MSIL">
<HintPath>..\packages\CommandLineParser.2.4.3\lib\netstandard2.0\CommandLine.dll</HintPath>
</Reference>
<Reference Include="DeltaCompressionDotNet, Version=1.1.0.0, Culture=neutral, PublicKeyToken=1d14d6e5194e7f4a, processorArchitecture=MSIL"> <Reference Include="DeltaCompressionDotNet, Version=1.1.0.0, Culture=neutral, PublicKeyToken=1d14d6e5194e7f4a, processorArchitecture=MSIL">
<HintPath>..\packages\DeltaCompressionDotNet.1.1.0\lib\net20\DeltaCompressionDotNet.dll</HintPath> <HintPath>..\packages\DeltaCompressionDotNet.1.1.0\lib\net20\DeltaCompressionDotNet.dll</HintPath>
</Reference> </Reference>
@ -132,6 +135,7 @@
<Compile Include="ClickSelectTextBox.xaml.cs"> <Compile Include="ClickSelectTextBox.xaml.cs">
<DependentUpon>ClickSelectTextBox.xaml</DependentUpon> <DependentUpon>ClickSelectTextBox.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="CommandLineOption.cs" />
<Compile Include="EnumerableExtensions.cs" /> <Compile Include="EnumerableExtensions.cs" />
<Compile Include="ValueConverters.cs" /> <Compile Include="ValueConverters.cs" />
<Compile Include="SettingsWindow.xaml.cs"> <Compile Include="SettingsWindow.xaml.cs">

View File

@ -0,0 +1,10 @@
using CommandLine;
namespace BililiveRecorder.WPF
{
public class CommandLineOption
{
[Option('w', "workdirectory", Default = null, HelpText = "设置工作目录并跳过选择目录 GUI", Required = false)]
public string WorkDirectory { get; set; }
}
}

View File

@ -1,6 +1,7 @@
using Autofac; using Autofac;
using BililiveRecorder.Core; using BililiveRecorder.Core;
using BililiveRecorder.FlvProcessor; using BililiveRecorder.FlvProcessor;
using CommandLine;
using Hardcodet.Wpf.TaskbarNotification; using Hardcodet.Wpf.TaskbarNotification;
using NLog; using NLog;
using System; using System;
@ -66,30 +67,50 @@ namespace BililiveRecorder.WPF
{ {
Title += " " + BuildInfo.Version + " " + BuildInfo.HeadShaShort; Title += " " + BuildInfo.Version + " " + BuildInfo.HeadShaShort;
bool skip_ui = false;
string workdir = string.Empty; string workdir = string.Empty;
try
CommandLineOption commandLineOption = null;
Parser.Default
.ParseArguments<CommandLineOption>(Environment.GetCommandLineArgs())
.WithParsed(x => commandLineOption = x);
if (commandLineOption?.WorkDirectory != null)
{ {
workdir = File.ReadAllText(LAST_WORK_DIR_FILE); skip_ui = true;
workdir = commandLineOption.WorkDirectory;
} }
catch (Exception) { }
var wdw = new WorkDirectoryWindow() if (!skip_ui)
{ {
Owner = this, try
WorkPath = workdir, {
}; workdir = File.ReadAllText(LAST_WORK_DIR_FILE);
if (wdw.ShowDialog() == true) }
{ catch (Exception) { }
workdir = wdw.WorkPath; var wdw = new WorkDirectoryWindow()
} {
else Owner = this,
{ WorkPath = workdir,
Environment.Exit(-1); };
return;
if (wdw.ShowDialog() == true)
{
workdir = wdw.WorkPath;
}
else
{
Environment.Exit(-1);
return;
}
} }
if (!Recorder.Initialize(workdir)) if (!Recorder.Initialize(workdir))
{ {
MessageBox.Show("初始化错误", "录播姬", MessageBoxButton.OK, MessageBoxImage.Error); if (!skip_ui)
{
MessageBox.Show("初始化错误", "录播姬", MessageBoxButton.OK, MessageBoxImage.Error);
}
Environment.Exit(-2); Environment.Exit(-2);
return; return;
} }

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="Autofac" version="4.8.1" targetFramework="net462" /> <package id="Autofac" version="4.8.1" targetFramework="net462" />
<package id="CommandLineParser" version="2.4.3" targetFramework="net462" />
<package id="DeltaCompressionDotNet" version="1.1.0" targetFramework="net462" /> <package id="DeltaCompressionDotNet" version="1.1.0" targetFramework="net462" />
<package id="Hardcodet.NotifyIcon.Wpf" version="1.0.8" targetFramework="net462" /> <package id="Hardcodet.NotifyIcon.Wpf" version="1.0.8" targetFramework="net462" />
<package id="Mono.Cecil" version="0.9.6.1" targetFramework="net462" /> <package id="Mono.Cecil" version="0.9.6.1" targetFramework="net462" />

View File

@ -1 +1 @@
1.1.4 1.1.5