aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgnattu <gnattu@users.noreply.github.com>2024-05-25 11:46:28 -0400
committerJoshua M. Boniface <joshua@boniface.me>2024-05-25 11:46:28 -0400
commit876ae44b8ab8972f44202c91ce71c6c3bea28688 (patch)
treea11978d02874a3c37dfff32bd67dab0301ee61b9 /src
parent39ae56db0ae03a118d9199ebe16d196fdff90b6c (diff)
Backport pull request #11805 from jellyfin/release-10.9.z
Use SharedStream for LiveTV more restrictively Original-merge: ef985896e2f80f66321fc9dce91cbbe156f0a843 Merged-by: crobibero <cody@robibe.ro> Backported-by: Joshua M. Boniface <joshua@boniface.me>
Diffstat (limited to 'src')
-rw-r--r--src/Jellyfin.LiveTv/TunerHosts/M3UTunerHost.cs57
1 files changed, 23 insertions, 34 deletions
diff --git a/src/Jellyfin.LiveTv/TunerHosts/M3UTunerHost.cs b/src/Jellyfin.LiveTv/TunerHosts/M3UTunerHost.cs
index c1e1a7bda..365f0188d 100644
--- a/src/Jellyfin.LiveTv/TunerHosts/M3UTunerHost.cs
+++ b/src/Jellyfin.LiveTv/TunerHosts/M3UTunerHost.cs
@@ -30,25 +30,8 @@ namespace Jellyfin.LiveTv.TunerHosts
{
public class M3UTunerHost : BaseTunerHost, ITunerHost, IConfigurableTunerHost
{
- private static readonly string[] _disallowedMimeTypes =
- {
- "text/plain",
- "text/html",
- "video/x-matroska",
- "video/mp4",
- "application/vnd.apple.mpegurl",
- "application/mpegurl",
- "application/x-mpegurl",
- "video/vnd.mpeg.dash.mpd"
- };
-
- private static readonly string[] _disallowedSharedStreamExtensions =
- {
- ".mkv",
- ".mp4",
- ".m3u8",
- ".mpd"
- };
+ private static readonly string[] _mimeTypesCanShareHttpStream = ["video/MP2T"];
+ private static readonly string[] _extensionsCanShareHttpStream = [".ts", ".tsv", ".m2t"];
private readonly IHttpClientFactory _httpClientFactory;
private readonly IServerApplicationHost _appHost;
@@ -113,28 +96,34 @@ namespace Jellyfin.LiveTv.TunerHosts
if (mediaSource.Protocol == MediaProtocol.Http && !mediaSource.RequiresLooping)
{
- using var message = new HttpRequestMessage(HttpMethod.Head, mediaSource.Path);
- using var response = await _httpClientFactory.CreateClient(NamedClient.Default)
- .SendAsync(message, cancellationToken)
- .ConfigureAwait(false);
+ var extension = Path.GetExtension(new UriBuilder(mediaSource.Path).Path);
- if (response.IsSuccessStatusCode)
+ if (string.IsNullOrEmpty(extension))
{
- if (!_disallowedMimeTypes.Contains(response.Content.Headers.ContentType?.MediaType, StringComparison.OrdinalIgnoreCase))
+ try
{
- return new SharedHttpStream(mediaSource, tunerHost, streamId, FileSystem, _httpClientFactory, Logger, Config, _appHost, _streamHelper);
+ using var message = new HttpRequestMessage(HttpMethod.Head, mediaSource.Path);
+ using var response = await _httpClientFactory.CreateClient(NamedClient.Default)
+ .SendAsync(message, cancellationToken)
+ .ConfigureAwait(false);
+
+ if (response.IsSuccessStatusCode)
+ {
+ if (_mimeTypesCanShareHttpStream.Contains(response.Content.Headers.ContentType?.MediaType, StringComparison.OrdinalIgnoreCase))
+ {
+ return new SharedHttpStream(mediaSource, tunerHost, streamId, FileSystem, _httpClientFactory, Logger, Config, _appHost, _streamHelper);
+ }
+ }
}
- }
- else
- {
- // 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))
+ catch (Exception)
{
- return new SharedHttpStream(mediaSource, tunerHost, streamId, FileSystem, _httpClientFactory, Logger, Config, _appHost, _streamHelper);
+ Logger.LogWarning("HEAD request to check MIME type failed, shared stream disabled");
}
}
+ else if (_extensionsCanShareHttpStream.Contains(extension, StringComparison.OrdinalIgnoreCase))
+ {
+ return new SharedHttpStream(mediaSource, tunerHost, streamId, FileSystem, _httpClientFactory, Logger, Config, _appHost, _streamHelper);
+ }
}
return new LiveStream(mediaSource, tunerHost, FileSystem, Logger, Config, _streamHelper);