Browse Source

use base path in channel playlist and channel guide (#1028)

pull/1030/head
Jason Dove 4 years ago committed by GitHub
parent
commit
776bce9087
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 2
      ErsatzTV.Application/Channels/Queries/GetChannelGuide.cs
  3. 8
      ErsatzTV.Application/Channels/Queries/GetChannelGuideHandler.cs
  4. 2
      ErsatzTV.Application/Channels/Queries/GetChannelPlaylist.cs
  5. 2
      ErsatzTV.Application/Channels/Queries/GetChannelPlaylistHandler.cs
  6. 9
      ErsatzTV.Core/Iptv/ChannelGuide.cs
  7. 12
      ErsatzTV.Core/Iptv/ChannelPlaylist.cs
  8. 4
      ErsatzTV/Controllers/IptvController.cs
  9. 4
      ErsatzTV/Services/RunOnce/EndpointValidatorService.cs
  10. 12
      ErsatzTV/Startup.cs

1
CHANGELOG.md

@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Fixed
- Fix removing Jellyfin and Emby libraries that have been deleted from the source media server
- Fix `Work-Ahead HLS Segmenter Limit` setting to properly limit number of channels that can work-ahead at once
- Include base path value in generated channel playlist (M3U) and channel guide (XMLTV) links
### Added
- Add audio stream selector scripts for episodes and movies

2
ErsatzTV.Application/Channels/Queries/GetChannelGuide.cs

@ -2,4 +2,4 @@ @@ -2,4 +2,4 @@
namespace ErsatzTV.Application.Channels;
public record GetChannelGuide(string Scheme, string Host) : IRequest<ChannelGuide>;
public record GetChannelGuide(string Scheme, string Host, string BaseUrl) : IRequest<ChannelGuide>;

8
ErsatzTV.Application/Channels/Queries/GetChannelGuideHandler.cs

@ -19,5 +19,11 @@ public class GetChannelGuideHandler : IRequestHandler<GetChannelGuide, ChannelGu @@ -19,5 +19,11 @@ public class GetChannelGuideHandler : IRequestHandler<GetChannelGuide, ChannelGu
public Task<ChannelGuide> Handle(GetChannelGuide request, CancellationToken cancellationToken) =>
_channelRepository.GetAllForGuide()
.Map(channels => new ChannelGuide(_recyclableMemoryStreamManager, request.Scheme, request.Host, channels));
.Map(
channels => new ChannelGuide(
_recyclableMemoryStreamManager,
request.Scheme,
request.Host,
request.BaseUrl,
channels));
}

2
ErsatzTV.Application/Channels/Queries/GetChannelPlaylist.cs

@ -2,4 +2,4 @@ @@ -2,4 +2,4 @@
namespace ErsatzTV.Application.Channels;
public record GetChannelPlaylist(string Scheme, string Host, string Mode) : IRequest<ChannelPlaylist>;
public record GetChannelPlaylist(string Scheme, string Host, string BaseUrl, string Mode) : IRequest<ChannelPlaylist>;

2
ErsatzTV.Application/Channels/Queries/GetChannelPlaylistHandler.cs

@ -14,7 +14,7 @@ public class GetChannelPlaylistHandler : IRequestHandler<GetChannelPlaylist, Cha @@ -14,7 +14,7 @@ public class GetChannelPlaylistHandler : IRequestHandler<GetChannelPlaylist, Cha
public Task<ChannelPlaylist> Handle(GetChannelPlaylist request, CancellationToken cancellationToken) =>
_channelRepository.GetAll()
.Map(channels => EnsureMode(channels, request.Mode))
.Map(channels => new ChannelPlaylist(request.Scheme, request.Host, channels));
.Map(channels => new ChannelPlaylist(request.Scheme, request.Host, request.BaseUrl, channels));
private static List<Channel> EnsureMode(IEnumerable<Channel> channels, string mode)
{

9
ErsatzTV.Core/Iptv/ChannelGuide.cs

@ -13,6 +13,7 @@ public class ChannelGuide @@ -13,6 +13,7 @@ public class ChannelGuide
{
private readonly List<Channel> _channels;
private readonly string _host;
private readonly string _baseUrl;
private readonly RecyclableMemoryStreamManager _recyclableMemoryStreamManager;
private readonly string _scheme;
@ -20,11 +21,13 @@ public class ChannelGuide @@ -20,11 +21,13 @@ public class ChannelGuide
RecyclableMemoryStreamManager recyclableMemoryStreamManager,
string scheme,
string host,
string baseUrl,
List<Channel> channels)
{
_recyclableMemoryStreamManager = recyclableMemoryStreamManager;
_scheme = scheme;
_host = host;
_baseUrl = baseUrl;
_channels = channels;
}
@ -67,8 +70,8 @@ public class ChannelGuide @@ -67,8 +70,8 @@ public class ChannelGuide
.Filter(a => a.ArtworkKind == ArtworkKind.Logo)
.HeadOrNone()
.Match(
artwork => $"{_scheme}://{_host}/iptv/logos/{artwork.Path}.jpg",
() => $"{_scheme}://{_host}/iptv/images/ersatztv-500.png");
artwork => $"{_scheme}://{_host}{_baseUrl}/iptv/logos/{artwork.Path}.jpg",
() => $"{_scheme}://{_host}{_baseUrl}/iptv/images/ersatztv-500.png");
xml.WriteAttributeString("src", logo);
xml.WriteEndElement(); // icon
@ -394,7 +397,7 @@ public class ChannelGuide @@ -394,7 +397,7 @@ public class ChannelGuide
_ => "posters"
};
artworkPath = $"{_scheme}://{_host}/iptv/artwork/{artworkFolder}/{artwork.Path}.jpg";
artworkPath = $"{_scheme}://{_host}{_baseUrl}/iptv/artwork/{artworkFolder}/{artwork.Path}.jpg";
}
return artworkPath;

12
ErsatzTV.Core/Iptv/ChannelPlaylist.cs

@ -7,12 +7,14 @@ public class ChannelPlaylist @@ -7,12 +7,14 @@ public class ChannelPlaylist
{
private readonly List<Channel> _channels;
private readonly string _host;
private readonly string _baseUrl;
private readonly string _scheme;
public ChannelPlaylist(string scheme, string host, List<Channel> channels)
public ChannelPlaylist(string scheme, string host, string baseUrl, List<Channel> channels)
{
_scheme = scheme;
_host = host;
_baseUrl = baseUrl;
_channels = channels;
}
@ -20,7 +22,7 @@ public class ChannelPlaylist @@ -20,7 +22,7 @@ public class ChannelPlaylist
{
var sb = new StringBuilder();
var xmltv = $"{_scheme}://{_host}/iptv/xmltv.xml";
string xmltv = $"{_scheme}://{_host}{_baseUrl}/iptv/xmltv.xml";
sb.AppendLine($"#EXTM3U url-tvg=\"{xmltv}\" x-tvg-url=\"{xmltv}\"");
foreach (Channel channel in _channels.OrderBy(c => decimal.Parse(c.Number)))
{
@ -28,8 +30,8 @@ public class ChannelPlaylist @@ -28,8 +30,8 @@ public class ChannelPlaylist
.Filter(a => a.ArtworkKind == ArtworkKind.Logo)
.HeadOrNone()
.Match(
artwork => $"{_scheme}://{_host}/iptv/logos/{artwork.Path}.jpg",
() => $"{_scheme}://{_host}/iptv/images/ersatztv-500.png");
artwork => $"{_scheme}://{_host}{_baseUrl}/iptv/logos/{artwork.Path}.jpg",
() => $"{_scheme}://{_host}{_baseUrl}/iptv/images/ersatztv-500.png");
string shortUniqueId = Convert.ToBase64String(channel.UniqueId.ToByteArray())
.TrimEnd('=')
@ -49,7 +51,7 @@ public class ChannelPlaylist @@ -49,7 +51,7 @@ public class ChannelPlaylist
sb.AppendLine(
$"#EXTINF:0 tvg-id=\"{channel.Number}.etv\" channel-id=\"{shortUniqueId}\" channel-number=\"{channel.Number}\" CUID=\"{shortUniqueId}\" tvg-chno=\"{channel.Number}\" tvg-name=\"{channel.Name}\" tvg-logo=\"{logo}\" group-title=\"{channel.Group}\" tvc-stream-vcodec=\"{vcodec}\" tvc-stream-acodec=\"{acodec}\", {channel.Name}");
sb.AppendLine($"{_scheme}://{_host}/iptv/channel/{channel.Number}.{format}");
sb.AppendLine($"{_scheme}://{_host}{_baseUrl}/iptv/channel/{channel.Number}.{format}");
}
return sb.ToString();

4
ErsatzTV/Controllers/IptvController.cs

@ -36,12 +36,12 @@ public class IptvController : ControllerBase @@ -36,12 +36,12 @@ public class IptvController : ControllerBase
public Task<IActionResult> GetChannelPlaylist(
[FromQuery]
string mode = "mixed") =>
_mediator.Send(new GetChannelPlaylist(Request.Scheme, Request.Host.ToString(), mode))
_mediator.Send(new GetChannelPlaylist(Request.Scheme, Request.Host.ToString(), Request.PathBase, mode))
.Map<ChannelPlaylist, IActionResult>(Ok);
[HttpGet("iptv/xmltv.xml")]
public Task<IActionResult> GetGuide() =>
_mediator.Send(new GetChannelGuide(Request.Scheme, Request.Host.ToString()))
_mediator.Send(new GetChannelGuide(Request.Scheme, Request.Host.ToString(), Request.PathBase))
.Map<ChannelGuide, IActionResult>(Ok);
[HttpGet("iptv/hdhr/channel/{channelNumber}.ts")]

4
ErsatzTV/Services/RunOnce/EndpointValidatorService.cs

@ -43,11 +43,13 @@ public class EndpointValidatorService : IHostedService @@ -43,11 +43,13 @@ public class EndpointValidatorService : IHostedService
{
throw new NotSupportedException($"Invalid endpoint format: {urls}");
}
string baseUrl = Environment.GetEnvironmentVariable("ETV_BASE_URL");
_logger.LogInformation(
"Server will listen on port {Port} - try UI at {UI}",
Settings.ListenPort,
$"http://localhost:{Settings.ListenPort}");
$"http://localhost:{Settings.ListenPort}{baseUrl}");
return Task.CompletedTask;
}

12
ErsatzTV/Startup.cs

@ -288,7 +288,17 @@ public class Startup @@ -288,7 +288,17 @@ public class Startup
string baseUrl = Environment.GetEnvironmentVariable("ETV_BASE_URL");
if (!string.IsNullOrWhiteSpace(baseUrl))
{
app.UsePathBase(baseUrl);
try
{
app.UsePathBase(baseUrl);
}
catch (Exception ex)
{
Log.Error(
ex,
"Failed to configure ETV_BASE_URL; please check syntax and include leading slash e.g. `/etv`: {BaseUrl}",
baseUrl);
}
}
app.UseCors("AllowAll");

Loading…
Cancel
Save