From 4e56117e0e3a80400a3a73e0055126d53af0cf1e Mon Sep 17 00:00:00 2001 From: Jason Dove <1695733+jasongdove@users.noreply.github.com> Date: Fri, 29 Mar 2024 21:36:49 -0500 Subject: [PATCH] use jwt for mpeg-ts streaming mode (#1661) --- CHANGELOG.md | 1 + .../Queries/GetWrappedProcessByChannelNumber.cs | 4 +++- .../Queries/GetWrappedProcessByChannelNumberHandler.cs | 3 ++- ErsatzTV.Core/FFmpeg/FFmpegLibraryProcessService.cs | 9 +++++++-- ErsatzTV.Core/Interfaces/FFmpeg/IFFmpegProcessService.cs | 8 +++++++- ErsatzTV/Controllers/IptvController.cs | 2 +- 6 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4cb8cbb..3938f886 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - This fix will require a one-time re-scan of each Plex library in full - After the initial full scan, incremental scans will behave as normal - Fix edge case where some local episodes, music videos, other videos, songs, images would not automatically be restored from trash +- Fix `MPEG-TS` playback when JWT tokens are enabled for streaming endpoints ### Changed - Log search index updates under scanner category at debug level, to indicate a potential cause for the UI being out of date diff --git a/ErsatzTV.Application/Streaming/Queries/GetWrappedProcessByChannelNumber.cs b/ErsatzTV.Application/Streaming/Queries/GetWrappedProcessByChannelNumber.cs index 765151d8..94315af3 100644 --- a/ErsatzTV.Application/Streaming/Queries/GetWrappedProcessByChannelNumber.cs +++ b/ErsatzTV.Application/Streaming/Queries/GetWrappedProcessByChannelNumber.cs @@ -2,7 +2,7 @@ public record GetWrappedProcessByChannelNumber : FFmpegProcessRequest { - public GetWrappedProcessByChannelNumber(string scheme, string host, string channelNumber) : base( + public GetWrappedProcessByChannelNumber(string scheme, string host, string accessToken, string channelNumber) : base( channelNumber, "ts", DateTimeOffset.Now, @@ -12,8 +12,10 @@ public record GetWrappedProcessByChannelNumber : FFmpegProcessRequest { Scheme = scheme; Host = host; + AccessToken = accessToken; } public string Scheme { get; } public string Host { get; } + public string AccessToken { get; } } diff --git a/ErsatzTV.Application/Streaming/Queries/GetWrappedProcessByChannelNumberHandler.cs b/ErsatzTV.Application/Streaming/Queries/GetWrappedProcessByChannelNumberHandler.cs index 0c1c6581..9002cfb8 100644 --- a/ErsatzTV.Application/Streaming/Queries/GetWrappedProcessByChannelNumberHandler.cs +++ b/ErsatzTV.Application/Streaming/Queries/GetWrappedProcessByChannelNumberHandler.cs @@ -35,7 +35,8 @@ public class GetWrappedProcessByChannelNumberHandler : FFmpegProcessHandler.None, DateTimeOffset.MaxValue, true); } diff --git a/ErsatzTV.Core/FFmpeg/FFmpegLibraryProcessService.cs b/ErsatzTV.Core/FFmpeg/FFmpegLibraryProcessService.cs index 39719a19..74ccd4e3 100644 --- a/ErsatzTV.Core/FFmpeg/FFmpegLibraryProcessService.cs +++ b/ErsatzTV.Core/FFmpeg/FFmpegLibraryProcessService.cs @@ -724,12 +724,17 @@ public class FFmpegLibraryProcessService : IFFmpegProcessService bool saveReports, Channel channel, string scheme, - string host) + string host, + string accessToken) { var resolution = new FrameSize(channel.FFmpegProfile.Resolution.Width, channel.FFmpegProfile.Resolution.Height); + string accessTokenQuery = string.IsNullOrWhiteSpace(accessToken) + ? string.Empty + : $"&access_token={accessToken}"; + var concatInputFile = new ConcatInputFile( - $"http://localhost:{Settings.ListenPort}/iptv/channel/{channel.Number}.m3u8?mode=segmenter", + $"http://localhost:{Settings.ListenPort}/iptv/channel/{channel.Number}.m3u8?mode=segmenter{accessTokenQuery}", resolution); IPipelineBuilder pipelineBuilder = await _pipelineBuilderFactory.GetBuilder( diff --git a/ErsatzTV.Core/Interfaces/FFmpeg/IFFmpegProcessService.cs b/ErsatzTV.Core/Interfaces/FFmpeg/IFFmpegProcessService.cs index de688978..95265947 100644 --- a/ErsatzTV.Core/Interfaces/FFmpeg/IFFmpegProcessService.cs +++ b/ErsatzTV.Core/Interfaces/FFmpeg/IFFmpegProcessService.cs @@ -60,7 +60,13 @@ public interface IFFmpegProcessService string scheme, string host); - Task WrapSegmenter(string ffmpegPath, bool saveReports, Channel channel, string scheme, string host); + Task WrapSegmenter( + string ffmpegPath, + bool saveReports, + Channel channel, + string scheme, + string host, + string accessToken); Task ResizeImage(string ffmpegPath, string inputFile, string outputFile, int height); diff --git a/ErsatzTV/Controllers/IptvController.cs b/ErsatzTV/Controllers/IptvController.cs index cb337d5b..23bc970e 100644 --- a/ErsatzTV/Controllers/IptvController.cs +++ b/ErsatzTV/Controllers/IptvController.cs @@ -100,7 +100,7 @@ public class IptvController : ControllerBase FFmpegProcessRequest request = mode switch { "ts-legacy" => new GetConcatProcessByChannelNumber(Request.Scheme, Request.Host.ToString(), channelNumber), - _ => new GetWrappedProcessByChannelNumber(Request.Scheme, Request.Host.ToString(), channelNumber) + _ => new GetWrappedProcessByChannelNumber(Request.Scheme, Request.Host.ToString(), Request.Query["access_token"], channelNumber) }; return await _mediator.Send(request)