Browse Source

custom binding and port number (#195)

* allow custom bindings

* reorganize

* cleanup
pull/197/head
Jason Dove 5 years ago committed by GitHub
parent
commit
c0b5ecd388
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      ErsatzTV.Core.Tests/Scheduling/MultiPartEpisodeGrouperTests.cs
  2. 4
      ErsatzTV.Core/FFmpeg/ConcatPlaylist.cs
  3. 2
      ErsatzTV.Core/FFmpeg/FFmpegProcessService.cs
  4. 3
      ErsatzTV.Core/Scheduling/MultiPartEpisodeGrouper.cs
  5. 7
      ErsatzTV.Core/Settings.cs
  6. 2
      ErsatzTV.Infrastructure/Search/SearchIndex.cs
  7. 2
      ErsatzTV/Program.cs
  8. 1
      ErsatzTV/Properties/launchSettings.json
  9. 63
      ErsatzTV/Services/RunOnce/EndpointValidatorService.cs
  10. 6
      ErsatzTV/Startup.cs
  11. 9
      ErsatzTV/appsettings.json

8
ErsatzTV.Core.Tests/Scheduling/MultiPartEpisodeGrouperTests.cs

@ -16,7 +16,7 @@ namespace ErsatzTV.Core.Tests.Scheduling @@ -16,7 +16,7 @@ namespace ErsatzTV.Core.Tests.Scheduling
NamedEpisode("Episode 1"),
NamedEpisode("Episode 2 (1)"),
NamedEpisode("Episode 3 (2)"),
NamedEpisode("Episode 4"),
NamedEpisode("Episode 4")
};
List<GroupedMediaItem> result = MultiPartEpisodeGrouper.GroupMediaItems(mediaItems);
@ -35,7 +35,7 @@ namespace ErsatzTV.Core.Tests.Scheduling @@ -35,7 +35,7 @@ namespace ErsatzTV.Core.Tests.Scheduling
{
NamedEpisode("Episode 1 (1)"),
NamedEpisode("Episode 2 (2)"),
NamedEpisode("Episode 3"),
NamedEpisode("Episode 3")
};
List<GroupedMediaItem> result = MultiPartEpisodeGrouper.GroupMediaItems(mediaItems);
@ -55,7 +55,7 @@ namespace ErsatzTV.Core.Tests.Scheduling @@ -55,7 +55,7 @@ namespace ErsatzTV.Core.Tests.Scheduling
NamedEpisode("Episode 2 (2)"),
NamedEpisode("Episode 3"),
NamedEpisode("Episode 4 (1)"),
NamedEpisode("Episode 5 (2)"),
NamedEpisode("Episode 5 (2)")
};
List<GroupedMediaItem> result = MultiPartEpisodeGrouper.GroupMediaItems(mediaItems);
@ -76,7 +76,7 @@ namespace ErsatzTV.Core.Tests.Scheduling @@ -76,7 +76,7 @@ namespace ErsatzTV.Core.Tests.Scheduling
NamedEpisode("Episode 1 (1)"),
NamedEpisode("Episode 2 (2)"),
NamedEpisode("Episode 3 (1)"),
NamedEpisode("Episode 4 (2)"),
NamedEpisode("Episode 4 (2)")
};
List<GroupedMediaItem> result = MultiPartEpisodeGrouper.GroupMediaItems(mediaItems);

4
ErsatzTV.Core/FFmpeg/ConcatPlaylist.cs

@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
{
public override string ToString() =>
$@"ffconcat version 1.0
file http://localhost:8409/ffmpeg/stream/{ChannelNumber}
file http://localhost:8409/ffmpeg/stream/{ChannelNumber}";
file http://localhost:{Settings.ListenPort}/ffmpeg/stream/{ChannelNumber}
file http://localhost:{Settings.ListenPort}/ffmpeg/stream/{ChannelNumber}";
}
}

2
ErsatzTV.Core/FFmpeg/FFmpegProcessService.cs

@ -134,7 +134,7 @@ namespace ErsatzTV.Core.FFmpeg @@ -134,7 +134,7 @@ namespace ErsatzTV.Core.FFmpeg
.WithFormatFlags(playbackSettings.FormatFlags)
.WithRealtimeOutput(playbackSettings.RealtimeOutput)
.WithInfiniteLoop()
.WithConcat($"http://localhost:8409/ffmpeg/concat/{channel.Number}")
.WithConcat($"http://localhost:{Settings.ListenPort}/ffmpeg/concat/{channel.Number}")
.WithMetadata(channel)
.WithFormat("mpegts")
.WithPipe()

3
ErsatzTV.Core/Scheduling/MultiPartEpisodeGrouper.cs

@ -56,7 +56,8 @@ namespace ErsatzTV.Core.Scheduling @@ -56,7 +56,8 @@ namespace ErsatzTV.Core.Scheduling
else
{
// this should never happen
throw new InvalidOperationException($"Bad shuffle state; unexpected number {number} after {lastNumber}");
throw new InvalidOperationException(
$"Bad shuffle state; unexpected number {number} after {lastNumber}");
}
}
else

7
ErsatzTV.Core/Settings.cs

@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
namespace ErsatzTV.Core
{
public static class Settings
{
public static int ListenPort { get; set; }
}
}

2
ErsatzTV.Infrastructure/Search/SearchIndex.cs

@ -55,8 +55,8 @@ namespace ErsatzTV.Infrastructure.Search @@ -55,8 +55,8 @@ namespace ErsatzTV.Infrastructure.Search
private readonly ILogger<SearchIndex> _logger;
private FSDirectory _directory;
private IndexWriter _writer;
private bool _initialized;
private IndexWriter _writer;
public SearchIndex(ILogger<SearchIndex> logger)
{

2
ErsatzTV/Program.cs

@ -48,7 +48,7 @@ namespace ErsatzTV @@ -48,7 +48,7 @@ namespace ErsatzTV
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(
webBuilder => webBuilder.UseStartup<Startup>()
.UseUrls("http://+:8409")
.UseConfiguration(Configuration)
.UseKestrel(options => options.AddServerHeader = false))
.UseSerilog();
}

1
ErsatzTV/Properties/launchSettings.json

@ -3,7 +3,6 @@ @@ -3,7 +3,6 @@
"ErsatzTV": {
"commandName": "Project",
"launchBrowser": false,
"applicationUrl": "http://0.0.0.0:8409",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}

63
ErsatzTV/Services/RunOnce/EndpointValidatorService.cs

@ -0,0 +1,63 @@ @@ -0,0 +1,63 @@
using System;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using ErsatzTV.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace ErsatzTV.Services.RunOnce
{
public class EndpointValidatorService : IHostedService
{
private readonly IConfiguration _configuration;
private readonly ILogger<EndpointValidatorService> _logger;
public EndpointValidatorService(IConfiguration configuration, ILogger<EndpointValidatorService> logger)
{
_configuration = configuration;
_logger = logger;
}
public Task StartAsync(CancellationToken cancellationToken)
{
string urls = _configuration.GetValue<string>("Kestrel:Endpoints:Http:Url");
if (urls.Split(";").Length > 1)
{
throw new NotSupportedException($"Multiple endpoints are not supported: {urls}");
}
const string PATTERN = @"http:\/\/(.*):(\d+)";
Match match = Regex.Match(urls, PATTERN);
if (match.Success)
{
string hostname = match.Groups[1].Value;
Settings.ListenPort = int.Parse(match.Groups[2].Value);
// IP address must be 0.0.0.0 or 127.0.0.1
if (IPAddress.TryParse(hostname, out IPAddress address))
{
if (!address.Equals(IPAddress.Parse("0.0.0.0")) && !IPAddress.IsLoopback(address))
{
throw new NotSupportedException($"Endpoint MUST include loopback: {urls}");
}
}
}
else
{
throw new NotSupportedException($"Invalid endpoint format: {urls}");
}
_logger.LogInformation(
"Server will listen on port {Port} - try UI at {UI}",
Settings.ListenPort,
$"http://localhost:{Settings.ListenPort}");
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
}

6
ErsatzTV/Startup.cs

@ -110,11 +110,6 @@ namespace ErsatzTV @@ -110,11 +110,6 @@ namespace ErsatzTV
"https://github.com/jasongdove/ErsatzTV",
"https://discord.gg/hHaJm3yGy6");
Log.Logger.Information(
"Server will listen on port {Port} - try UI at {UI}",
8409,
"http://localhost:8409");
if (!Directory.Exists(FileSystemLayout.AppDataFolder))
{
Directory.CreateDirectory(FileSystemLayout.AppDataFolder);
@ -247,6 +242,7 @@ namespace ErsatzTV @@ -247,6 +242,7 @@ namespace ErsatzTV
});
services.AddScoped<IJellyfinSecretStore, JellyfinSecretStore>();
services.AddHostedService<EndpointValidatorService>();
services.AddHostedService<DatabaseMigratorService>();
services.AddHostedService<CacheCleanerService>();
services.AddHostedService<JellyfinService>();

9
ErsatzTV/appsettings.json

@ -24,5 +24,12 @@ @@ -24,5 +24,12 @@
"WithThreadId"
]
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"Kestrel": {
"EndPoints": {
"Http": {
"Url": "http://+:8409"
}
}
}
}
Loading…
Cancel
Save