diff options
| author | gnattu <gnattuoc@me.com> | 2024-05-06 08:10:16 +0800 |
|---|---|---|
| committer | gnattu <gnattuoc@me.com> | 2024-05-06 08:10:16 +0800 |
| commit | e355c7bfb533921fd367ec50cac241c5ab222dbf (patch) | |
| tree | eee25158b6c9bc1c475c2fca99f1b4a68e236334 | |
| parent | 6bdc7928e8b94b5f4b74b975e9c687a76565f375 (diff) | |
Workarounds TV tuners rejecting HEAD method
Fallback to the old behavior of checking path extension when 405 occurs on HEAD request. Required as the TV Tuner's http sever is not always properly implemented.
Signed-off-by: gnattu <gnattuoc@me.com>
| -rw-r--r-- | src/Jellyfin.LiveTv/TunerHosts/M3UTunerHost.cs | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/src/Jellyfin.LiveTv/TunerHosts/M3UTunerHost.cs b/src/Jellyfin.LiveTv/TunerHosts/M3UTunerHost.cs index 8d52151cb..3307626f4 100644 --- a/src/Jellyfin.LiveTv/TunerHosts/M3UTunerHost.cs +++ b/src/Jellyfin.LiveTv/TunerHosts/M3UTunerHost.cs @@ -5,7 +5,9 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.IO; using System.Linq; +using System.Net; using System.Net.Http; using System.Threading; using System.Threading.Tasks; @@ -38,6 +40,14 @@ namespace Jellyfin.LiveTv.TunerHosts "video/vnd.mpeg.dash.mpd" }; + private static readonly string[] _disallowedSharedStreamExtensions = + { + ".mkv", + ".mp4", + ".m3u8", + ".mpd" + }; + private readonly IHttpClientFactory _httpClientFactory; private readonly IServerApplicationHost _appHost; private readonly INetworkManager _networkManager; @@ -106,11 +116,26 @@ namespace Jellyfin.LiveTv.TunerHosts .SendAsync(message, cancellationToken) .ConfigureAwait(false); - response.EnsureSuccessStatusCode(); - - if (!_disallowedMimeTypes.Contains(response.Content.Headers.ContentType?.ToString(), StringComparison.OrdinalIgnoreCase)) + if (response.IsSuccessStatusCode) + { + if (!_disallowedMimeTypes.Contains(response.Content.Headers.ContentType?.ToString(), StringComparison.OrdinalIgnoreCase)) + { + return new SharedHttpStream(mediaSource, tunerHost, streamId, FileSystem, _httpClientFactory, Logger, Config, _appHost, _streamHelper); + } + } + else if (response.StatusCode == HttpStatusCode.MethodNotAllowed) + { + // Fallback to check path extension when the server does not support HEAD method + // Use UriBuilder to remove all query string as GetExtension will include them when used directly + var extension = Path.GetExtension(new UriBuilder(mediaSource.Path).Path); + if (!_disallowedSharedStreamExtensions.Contains(extension, StringComparison.OrdinalIgnoreCase)) + { + return new SharedHttpStream(mediaSource, tunerHost, streamId, FileSystem, _httpClientFactory, Logger, Config, _appHost, _streamHelper); + } + } + else { - return new SharedHttpStream(mediaSource, tunerHost, streamId, FileSystem, _httpClientFactory, Logger, Config, _appHost, _streamHelper); + response.EnsureSuccessStatusCode(); } } |
