Browse Source

bug fixes (#703)

* catch expected shutdown error in scheduler service

* fix streaming mode inconsistencies
pull/704/head
Jason Dove 4 years ago committed by GitHub
parent
commit
7de1a87bbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      CHANGELOG.md
  2. 3
      ErsatzTV.Application/Channels/Queries/GetChannelByNumber.cs
  3. 14
      ErsatzTV.Application/Channels/Queries/GetChannelByNumberHandler.cs
  4. 4
      ErsatzTV.Application/Streaming/Queries/GetHlsPlaylistByChannelNumberHandler.cs
  5. 45
      ErsatzTV/Controllers/IptvController.cs
  6. 8
      ErsatzTV/Services/SchedulerService.cs

2
CHANGELOG.md

@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased]
### Fixed
- Fix streaming mode inconsistencies when `mode` parameter is unspecified
## [0.4.4-alpha] - 2022-03-10
### Fixed

3
ErsatzTV.Application/Channels/Queries/GetChannelByNumber.cs

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
namespace ErsatzTV.Application.Channels;
public record GetChannelByNumber(string ChannelNumber) : IRequest<Option<ChannelViewModel>>;

14
ErsatzTV.Application/Channels/Queries/GetChannelByNumberHandler.cs

@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
using ErsatzTV.Core.Interfaces.Repositories;
using static ErsatzTV.Application.Channels.Mapper;
namespace ErsatzTV.Application.Channels;
public class GetChannelByNumberHandler : IRequestHandler<GetChannelByNumber, Option<ChannelViewModel>>
{
private readonly IChannelRepository _channelRepository;
public GetChannelByNumberHandler(IChannelRepository channelRepository) => _channelRepository = channelRepository;
public Task<Option<ChannelViewModel>> Handle(GetChannelByNumber request, CancellationToken cancellationToken) =>
_channelRepository.GetByNumber(request.ChannelNumber).MapT(ProjectToViewModel);
}

4
ErsatzTV.Application/Streaming/Queries/GetHlsPlaylistByChannelNumberHandler.cs

@ -25,10 +25,10 @@ public class GetHlsPlaylistByChannelNumberHandler : @@ -25,10 +25,10 @@ public class GetHlsPlaylistByChannelNumberHandler :
GetHlsPlaylistByChannelNumber request,
CancellationToken cancellationToken)
{
await using TvContext dbContext = _dbContextFactory.CreateDbContext();
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
DateTimeOffset now = DateTimeOffset.Now;
Validation<BaseError, Parameters> validation = await Validate(dbContext, request, now);
return await LanguageExtensions.Apply(validation, parameters => GetPlaylist(dbContext, request, parameters, now));
return await validation.Apply(parameters => GetPlaylist(dbContext, request, parameters, now));
}
private Task<string> GetPlaylist(

45
ErsatzTV/Controllers/IptvController.cs

@ -18,20 +18,17 @@ namespace ErsatzTV.Controllers; @@ -18,20 +18,17 @@ namespace ErsatzTV.Controllers;
public class IptvController : ControllerBase
{
private readonly IFFmpegSegmenterService _ffmpegSegmenterService;
private readonly IHlsPlaylistFilter _hlsPlaylistFilter;
private readonly ILogger<IptvController> _logger;
private readonly IMediator _mediator;
public IptvController(
IMediator mediator,
ILogger<IptvController> logger,
IFFmpegSegmenterService ffmpegSegmenterService,
IHlsPlaylistFilter hlsPlaylistFilter)
IFFmpegSegmenterService ffmpegSegmenterService)
{
_mediator = mediator;
_logger = logger;
_ffmpegSegmenterService = ffmpegSegmenterService;
_hlsPlaylistFilter = hlsPlaylistFilter;
}
[HttpGet("iptv/channels.m3u")]
@ -52,6 +49,26 @@ public class IptvController : ControllerBase @@ -52,6 +49,26 @@ public class IptvController : ControllerBase
[FromQuery]
string mode = null)
{
// if mode is "unspecified" - find the configured mode and set it or redirect
if (string.IsNullOrWhiteSpace(mode) || mode == "mixed")
{
Option<ChannelViewModel> maybeChannel = await _mediator.Send(new GetChannelByNumber(channelNumber));
foreach (ChannelViewModel channel in maybeChannel)
{
switch (channel.StreamingMode)
{
case StreamingMode.TransportStream:
mode = "ts-legacy";
break;
case StreamingMode.TransportStreamHybrid:
mode = "ts";
break;
default:
return Redirect($"/iptv/channel/{channelNumber}.m3u8");
}
}
}
FFmpegProcessRequest request = mode switch
{
"ts-legacy" => new GetConcatProcessByChannelNumber(Request.Scheme, Request.Host.ToString(), channelNumber),
@ -97,6 +114,26 @@ public class IptvController : ControllerBase @@ -97,6 +114,26 @@ public class IptvController : ControllerBase
[FromQuery]
string mode = "mixed")
{
// if mode is "unspecified" - find the configured mode and set it or redirect
if (string.IsNullOrWhiteSpace(mode) || mode == "mixed")
{
Option<ChannelViewModel> maybeChannel = await _mediator.Send(new GetChannelByNumber(channelNumber));
foreach (ChannelViewModel channel in maybeChannel)
{
switch (channel.StreamingMode)
{
case StreamingMode.HttpLiveStreamingDirect:
mode = "hls-direct";
break;
case StreamingMode.HttpLiveStreamingSegmenter:
mode = "segmenter";
break;
default:
return Redirect($"/iptv/channel/{channelNumber}.ts");
}
}
}
switch (mode)
{
case "segmenter":

8
ErsatzTV/Services/SchedulerService.cs

@ -56,7 +56,7 @@ public class SchedulerService : BackgroundService @@ -56,7 +56,7 @@ public class SchedulerService : BackgroundService
{
await Task.Delay(TimeSpan.FromMinutes(toWait), cancellationToken);
}
catch (TaskCanceledException)
catch (Exception ex) when (ex is TaskCanceledException or OperationCanceledException)
{
// do nothing
}
@ -89,10 +89,14 @@ public class SchedulerService : BackgroundService @@ -89,10 +89,14 @@ public class SchedulerService : BackgroundService
await ScanPlexMediaSources(cancellationToken);
await MatchTraktLists(cancellationToken);
}
catch (Exception ex) when (ex is TaskCanceledException or OperationCanceledException)
{
// do nothing
}
catch (Exception ex)
{
_logger.LogWarning(ex, "Error during scheduler run");
try
{
using (IServiceScope scope = _serviceScopeFactory.CreateScope())

Loading…
Cancel
Save