From 6b8d1695297c28098924c5da18da133083ca9c92 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Bachmann Date: Wed, 1 Feb 2023 19:34:58 +0100 Subject: Added CleanupCollection task --- .../Collections/CollectionManager.cs | 3 +- .../Tasks/CleanupCollectionPathsTask.cs | 118 +++++++++++++++++++++ 2 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs (limited to 'Emby.Server.Implementations') diff --git a/Emby.Server.Implementations/Collections/CollectionManager.cs b/Emby.Server.Implementations/Collections/CollectionManager.cs index b53c8ca512..20370fff5d 100644 --- a/Emby.Server.Implementations/Collections/CollectionManager.cs +++ b/Emby.Server.Implementations/Collections/CollectionManager.cs @@ -112,7 +112,8 @@ namespace Emby.Server.Implementations.Collections return Path.Combine(_appPaths.DataPath, "collections"); } - private Task GetCollectionsFolder(bool createIfNeeded) + /// + public Task GetCollectionsFolder(bool createIfNeeded) { return EnsureLibraryFolder(GetCollectionsFolderPath(), createIfNeeded); } diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs new file mode 100644 index 0000000000..8e9270a125 --- /dev/null +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Emby.Server.Implementations.Collections; +using MediaBrowser.Controller.Collections; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities.Movies; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Providers; +using MediaBrowser.Model.Globalization; +using MediaBrowser.Model.IO; +using MediaBrowser.Model.Tasks; +using Microsoft.Extensions.Logging; + +namespace Emby.Server.Implementations.ScheduledTasks.Tasks; + +/// +/// Deletes Path references from collections that no longer exists. +/// +public class CleanupCollectionPathsTask : IScheduledTask +{ + private readonly ILocalizationManager _localization; + private readonly ICollectionManager _collectionManager; + private readonly ILogger _logger; + private readonly IProviderManager _providerManager; + private readonly IFileSystem _fileSystem; + + /// + /// Initializes a new instance of the class. + /// + /// Instance of the interface. + /// Instance of the interface. + /// The logger. + /// The provider manager. + /// The filesystem. + public CleanupCollectionPathsTask( + ILocalizationManager localization, + ICollectionManager collectionManager, + ILogger logger, + IProviderManager providerManager, + IFileSystem fileSystem) + { + _localization = localization; + _collectionManager = collectionManager; + _logger = logger; + _providerManager = providerManager; + _fileSystem = fileSystem; + } + + /// + public string Name => _localization.GetLocalizedString("TaskCleanCollections"); + + /// + public string Key => "CleanCollections"; + + /// + public string Description => _localization.GetLocalizedString("TaskCleanCollectionsDescription"); + + /// + public string Category => _localization.GetLocalizedString("TasksMaintenanceCategory"); + + /// + public async Task ExecuteAsync(IProgress progress, CancellationToken cancellationToken) + { + var collectionsFolder = await _collectionManager.GetCollectionsFolder(true).ConfigureAwait(false); + if (collectionsFolder is null) + { + _logger.LogInformation("There is no collection folder to be found."); + return; + } + + var collections = collectionsFolder.Children.OfType() + .ToArray(); + _logger.LogTrace("Found {CollectionLength} Boxsets.", collections.Length); + for (var index = 0; index < collections.Length; index++) + { + var collection = collections[index]; + _logger.LogTrace("Check Boxset {CollectionName}.", collection.Name); + var itemsToRemove = new List(); + foreach (var collectionLinkedChild in collection.LinkedChildren.ToArray()) + { + if (!File.Exists(collectionLinkedChild.Path)) + { + _logger.LogInformation("Item in boxset {0} cannot be found at {1}.", collection.Name, collectionLinkedChild.Path); + itemsToRemove.Add(collectionLinkedChild); + } + } + + if (itemsToRemove.Any()) + { + _logger.LogTrace("Update Boxset {CollectionName}.", collection.Name); + collection.LinkedChildren = collection.LinkedChildren.Except(itemsToRemove).ToArray(); + await collection.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, cancellationToken) + .ConfigureAwait(false); + + _providerManager.QueueRefresh( + collection.Id, + new MetadataRefreshOptions(new DirectoryService(_fileSystem)) + { + ForceSave = true + }, + RefreshPriority.High); + } + + progress.Report(100D / collections.Length * (index + 1)); + } + } + + /// + public IEnumerable GetDefaultTriggers() + { + return new[] { new TaskTriggerInfo() { Type = TaskTriggerInfo.TriggerStartup } }; + // return Enumerable.Empty(); + } +} -- cgit v1.2.3 From 341658b55259084635b52983245800deff8d561d Mon Sep 17 00:00:00 2001 From: JPVenson Date: Wed, 1 Feb 2023 22:42:10 +0100 Subject: Update CleanupCollectionPathsTask.cs Removed code smell and switched to non creation for non existing collection folder --- .../ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'Emby.Server.Implementations') diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs index 8e9270a125..7519af5b0d 100644 --- a/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs @@ -65,16 +65,16 @@ public class CleanupCollectionPathsTask : IScheduledTask /// public async Task ExecuteAsync(IProgress progress, CancellationToken cancellationToken) { - var collectionsFolder = await _collectionManager.GetCollectionsFolder(true).ConfigureAwait(false); + var collectionsFolder = await _collectionManager.GetCollectionsFolder(false).ConfigureAwait(false); if (collectionsFolder is null) { _logger.LogInformation("There is no collection folder to be found."); return; } - var collections = collectionsFolder.Children.OfType() - .ToArray(); + var collections = collectionsFolder.Children.OfType().ToArray(); _logger.LogTrace("Found {CollectionLength} Boxsets.", collections.Length); + for (var index = 0; index < collections.Length; index++) { var collection = collections[index]; @@ -84,7 +84,7 @@ public class CleanupCollectionPathsTask : IScheduledTask { if (!File.Exists(collectionLinkedChild.Path)) { - _logger.LogInformation("Item in boxset {0} cannot be found at {1}.", collection.Name, collectionLinkedChild.Path); + _logger.LogInformation("Item in boxset {CollectionName} cannot be found at {ItemPath}.", collection.Name, collectionLinkedChild.Path); itemsToRemove.Add(collectionLinkedChild); } } @@ -113,6 +113,5 @@ public class CleanupCollectionPathsTask : IScheduledTask public IEnumerable GetDefaultTriggers() { return new[] { new TaskTriggerInfo() { Type = TaskTriggerInfo.TriggerStartup } }; - // return Enumerable.Empty(); } } -- cgit v1.2.3 From 0b71974054b4f520fa0ef3ead8f1b688ec2d1d74 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Bachmann Date: Wed, 1 Feb 2023 23:45:06 +0100 Subject: Fixed whitespace --- .../ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Emby.Server.Implementations') diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs index 7519af5b0d..e1be43b9b2 100644 --- a/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs @@ -74,7 +74,7 @@ public class CleanupCollectionPathsTask : IScheduledTask var collections = collectionsFolder.Children.OfType().ToArray(); _logger.LogTrace("Found {CollectionLength} Boxsets.", collections.Length); - + for (var index = 0; index < collections.Length; index++) { var collection = collections[index]; -- cgit v1.2.3 From 2a4cc4d942828886eb0c10389e602d67155aeca4 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Bachmann Date: Sun, 5 Feb 2023 21:08:08 +0200 Subject: Updated logging level and formatting --- .../ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'Emby.Server.Implementations') diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs index e1be43b9b2..617fd687a3 100644 --- a/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs @@ -4,7 +4,6 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; -using Emby.Server.Implementations.Collections; using MediaBrowser.Controller.Collections; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; @@ -68,30 +67,30 @@ public class CleanupCollectionPathsTask : IScheduledTask var collectionsFolder = await _collectionManager.GetCollectionsFolder(false).ConfigureAwait(false); if (collectionsFolder is null) { - _logger.LogInformation("There is no collection folder to be found."); + _logger.LogDebug("There is no collection folder to be found"); return; } var collections = collectionsFolder.Children.OfType().ToArray(); - _logger.LogTrace("Found {CollectionLength} Boxsets.", collections.Length); + _logger.LogTrace("Found {CollectionLength} Boxsets", collections.Length); for (var index = 0; index < collections.Length; index++) { var collection = collections[index]; - _logger.LogTrace("Check Boxset {CollectionName}.", collection.Name); + _logger.LogDebug("Check Boxset {CollectionName}", collection.Name); var itemsToRemove = new List(); foreach (var collectionLinkedChild in collection.LinkedChildren.ToArray()) { if (!File.Exists(collectionLinkedChild.Path)) { - _logger.LogInformation("Item in boxset {CollectionName} cannot be found at {ItemPath}.", collection.Name, collectionLinkedChild.Path); + _logger.LogInformation("Item in boxset {CollectionName} cannot be found at {ItemPath}", collection.Name, collectionLinkedChild.Path); itemsToRemove.Add(collectionLinkedChild); } } if (itemsToRemove.Any()) { - _logger.LogTrace("Update Boxset {CollectionName}.", collection.Name); + _logger.LogDebug("Update Boxset {CollectionName}", collection.Name); collection.LinkedChildren = collection.LinkedChildren.Except(itemsToRemove).ToArray(); await collection.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, cancellationToken) .ConfigureAwait(false); -- cgit v1.2.3 From 0ed4fd5759156dd12b0de749d5c452972f8d9fb8 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Bachmann Date: Sun, 5 Feb 2023 21:38:50 +0200 Subject: Changed LogTrace to LogDebug --- .../ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Emby.Server.Implementations') diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs index 617fd687a3..83e07478d2 100644 --- a/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs @@ -72,7 +72,7 @@ public class CleanupCollectionPathsTask : IScheduledTask } var collections = collectionsFolder.Children.OfType().ToArray(); - _logger.LogTrace("Found {CollectionLength} Boxsets", collections.Length); + _logger.LogDebug("Found {CollectionLength} Boxsets", collections.Length); for (var index = 0; index < collections.Length; index++) { -- cgit v1.2.3 From 8b6fca59a1129c161e0b2ca44813921df20771b5 Mon Sep 17 00:00:00 2001 From: JPVenson Date: Tue, 2 May 2023 14:26:55 +0200 Subject: Update Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs Co-authored-by: Cody Robibero --- .../ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Emby.Server.Implementations') diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs index 83e07478d2..989c37242e 100644 --- a/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs @@ -79,7 +79,7 @@ public class CleanupCollectionPathsTask : IScheduledTask var collection = collections[index]; _logger.LogDebug("Check Boxset {CollectionName}", collection.Name); var itemsToRemove = new List(); - foreach (var collectionLinkedChild in collection.LinkedChildren.ToArray()) + foreach (var collectionLinkedChild in collection.LinkedChildren) { if (!File.Exists(collectionLinkedChild.Path)) { -- cgit v1.2.3 From 45ed1d9f880774031532a0fbb5a2a9e846afe066 Mon Sep 17 00:00:00 2001 From: Sushil Shrestha Date: Fri, 23 Jun 2023 14:29:41 +0000 Subject: Translated using Weblate (Nepali) Translation: Jellyfin/Jellyfin Translate-URL: https://translate.jellyfin.org/projects/jellyfin/jellyfin-core/ne/ --- Emby.Server.Implementations/Localization/Core/ne.json | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'Emby.Server.Implementations') diff --git a/Emby.Server.Implementations/Localization/Core/ne.json b/Emby.Server.Implementations/Localization/Core/ne.json index 4c8e820a5c..7c6b08fb36 100644 --- a/Emby.Server.Implementations/Localization/Core/ne.json +++ b/Emby.Server.Implementations/Localization/Core/ne.json @@ -109,5 +109,19 @@ "Sync": "समकालीन", "SubtitleDownloadFailureFromForItem": "उपशीर्षकहरू {0} बाट {1} को लागि डाउनलोड गर्न असफल", "PluginUpdatedWithName": "{0} अद्यावधिक गरिएको थियो", - "PluginUninstalledWithName": "{0} को स्थापना रद्द गरिएको थियो" + "PluginUninstalledWithName": "{0} को स्थापना रद्द गरिएको थियो", + "HearingImpaired": "सुन्न नसक्ने", + "TaskUpdatePluginsDescription": "स्वचालित रूपमा अद्यावधिक गर्न कन्फिगर गरिएका प्लगइनहरूका लागि अद्यावधिकहरू डाउनलोड र स्थापना गर्दछ।", + "TaskCleanTranscode": "सफा ट्रान्सकोड निर्देशिका", + "TaskCleanTranscodeDescription": "एक दिन भन्दा पुराना ट्रान्सकोड फाइलहरू मेटाउँछ।", + "TaskRefreshChannels": "च्यानलहरू ताजा गर्नुहोस्", + "TaskDownloadMissingSubtitlesDescription": "मेटाडेटा कन्फिगरेसनमा आधारित हराइरहेको उपशीर्षकहरूको लागि इन्टरनेट खोज्छ।", + "TaskOptimizeDatabase": "डेटाबेस अप्टिमाइज गर्नुहोस्", + "TaskOptimizeDatabaseDescription": "डाटाबेस कम्प्याक्ट र खाली ठाउँ काट्छ। पुस्तकालय स्क्यान गरेपछि वा डाटाबेस परिमार्जनलाई संकेत गर्ने अन्य परिवर्तनहरू गरेपछि यो कार्य चलाउँदा कार्यसम्पादनमा सुधार हुन सक्छ।", + "TaskKeyframeExtractorDescription": "थप सटीक एचएलएस प्लेलिस्टहरू सिर्जना गर्न भिडियो फाइलहरूबाट कीफ्रेमहरू निकाल्छ। यो कार्य लामो समय सम्म चल्न सक्छ।", + "TaskUpdatePlugins": "प्लगइनहरू अपडेट गर्नुहोस्", + "TaskRefreshPeopleDescription": "तपाईंको मिडिया लाइब्रेरीमा अभिनेता र निर्देशकहरूको लागि मेटाडेटा अपडेट गर्दछ।", + "TaskRefreshChannelsDescription": "इन्टरनेट च्यानल जानकारी ताजा गर्दछ।", + "TaskDownloadMissingSubtitles": "छुटेका उपशीर्षकहरू डाउनलोड गर्नुहोस्", + "TaskKeyframeExtractor": "कीफ्रेम एक्स्ट्रक्टर" } -- cgit v1.2.3 From 0f60ec3013a4b1c776513fd92dc3829897b78db7 Mon Sep 17 00:00:00 2001 From: JPVenson Date: Tue, 27 Jun 2023 16:05:07 +0200 Subject: Update Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs Co-authored-by: Bond-009 --- .../ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Emby.Server.Implementations') diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs index 989c37242e..f8b044d46f 100644 --- a/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs @@ -88,7 +88,7 @@ public class CleanupCollectionPathsTask : IScheduledTask } } - if (itemsToRemove.Any()) + if (itemsToRemove.Count != 0) { _logger.LogDebug("Update Boxset {CollectionName}", collection.Name); collection.LinkedChildren = collection.LinkedChildren.Except(itemsToRemove).ToArray(); -- cgit v1.2.3 From cc82ca189fcbd068c34c0d1c38a67d2332a96d44 Mon Sep 17 00:00:00 2001 From: Cody Robibero Date: Tue, 27 Jun 2023 21:19:15 -0600 Subject: suggestions from review --- .../ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'Emby.Server.Implementations') diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs index f8b044d46f..f78fc6f970 100644 --- a/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionPathsTask.cs @@ -74,11 +74,12 @@ public class CleanupCollectionPathsTask : IScheduledTask var collections = collectionsFolder.Children.OfType().ToArray(); _logger.LogDebug("Found {CollectionLength} Boxsets", collections.Length); + var itemsToRemove = new List(); for (var index = 0; index < collections.Length; index++) { var collection = collections[index]; _logger.LogDebug("Check Boxset {CollectionName}", collection.Name); - var itemsToRemove = new List(); + foreach (var collectionLinkedChild in collection.LinkedChildren) { if (!File.Exists(collectionLinkedChild.Path)) @@ -102,6 +103,8 @@ public class CleanupCollectionPathsTask : IScheduledTask ForceSave = true }, RefreshPriority.High); + + itemsToRemove.Clear(); } progress.Report(100D / collections.Length * (index + 1)); -- cgit v1.2.3 From f954dc5c969ef5654c31bec7a81b0b92b38637ae Mon Sep 17 00:00:00 2001 From: Bond-009 Date: Wed, 28 Jun 2023 05:36:39 +0200 Subject: Do HEAD request to get content type instead of checking for extension (#8823) --- .../LiveTv/TunerHosts/M3UTunerHost.cs | 21 ++++++---- .../LiveTv/TunerHosts/SharedHttpStream.cs | 47 +++++----------------- 2 files changed, 25 insertions(+), 43 deletions(-) (limited to 'Emby.Server.Implementations') diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs index bcb42e1626..acf3964c8c 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs @@ -30,12 +30,14 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts { public class M3UTunerHost : BaseTunerHost, ITunerHost, IConfigurableTunerHost { - private static readonly string[] _disallowedSharedStreamExtensions = + private static readonly string[] _disallowedMimeTypes = { - ".mkv", - ".mp4", - ".m3u8", - ".mpd" + "video/x-matroska", + "video/mp4", + "application/vnd.apple.mpegurl", + "application/mpegurl", + "application/x-mpegurl", + "video/vnd.mpeg.dash.mpd" }; private readonly IHttpClientFactory _httpClientFactory; @@ -118,9 +120,14 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts if (mediaSource.Protocol == MediaProtocol.Http && !mediaSource.RequiresLooping) { - var extension = Path.GetExtension(mediaSource.Path) ?? string.Empty; + using var message = new HttpRequestMessage(HttpMethod.Head, mediaSource.Path); + using var response = await _httpClientFactory.CreateClient(NamedClient.Default) + .SendAsync(message, cancellationToken) + .ConfigureAwait(false); - if (!_disallowedSharedStreamExtensions.Contains(extension, StringComparison.OrdinalIgnoreCase)) + response.EnsureSuccessStatusCode(); + + if (!_disallowedMimeTypes.Contains(response.Content.Headers.ContentType?.ToString(), StringComparison.OrdinalIgnoreCase)) { return new SharedHttpStream(mediaSource, tunerHost, streamId, FileSystem, _httpClientFactory, Logger, Config, _appHost, _streamHelper); } diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs index e84e1e074c..51f46f4dac 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs @@ -38,7 +38,6 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts _httpClientFactory = httpClientFactory; _appHost = appHost; OriginalStreamId = originalStreamId; - EnableStreamSharing = true; } public override async Task Open(CancellationToken openCancellationToken) @@ -59,39 +58,13 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts .GetAsync(url, HttpCompletionOption.ResponseHeadersRead, CancellationToken.None) .ConfigureAwait(false); - var contentType = response.Content.Headers.ContentType?.ToString() ?? string.Empty; - if (contentType.Contains("matroska", StringComparison.OrdinalIgnoreCase) - || contentType.Contains("mp4", StringComparison.OrdinalIgnoreCase) - || contentType.Contains("dash", StringComparison.OrdinalIgnoreCase) - || contentType.Contains("mpegURL", StringComparison.OrdinalIgnoreCase) - || contentType.Contains("text/", StringComparison.OrdinalIgnoreCase)) - { - // Close the stream without any sharing features - response.Dispose(); - return; - } - - SetTempFilePath("ts"); - var taskCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); _ = StartStreaming(response, taskCompletionSource, LiveStreamCancellationTokenSource.Token); - // OpenedMediaSource.Protocol = MediaProtocol.File; - // OpenedMediaSource.Path = tempFile; - // OpenedMediaSource.ReadAtNativeFramerate = true; - MediaSource.Path = _appHost.GetApiUrlForLocalAccess() + "/LiveTv/LiveStreamFiles/" + UniqueId + "/stream.ts"; MediaSource.Protocol = MediaProtocol.Http; - // OpenedMediaSource.Path = TempFilePath; - // OpenedMediaSource.Protocol = MediaProtocol.File; - - // OpenedMediaSource.Path = _tempFilePath; - // OpenedMediaSource.Protocol = MediaProtocol.File; - // OpenedMediaSource.SupportsDirectPlay = false; - // OpenedMediaSource.SupportsDirectStream = true; - // OpenedMediaSource.SupportsTranscoding = true; var res = await taskCompletionSource.Task.ConfigureAwait(false); if (!res) { @@ -108,15 +81,17 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts try { Logger.LogInformation("Beginning {StreamType} stream to {FilePath}", GetType().Name, TempFilePath); - using var message = response; - await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false); - await using var fileStream = new FileStream(TempFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, FileOptions.Asynchronous); - await StreamHelper.CopyToAsync( - stream, - fileStream, - IODefaults.CopyToBufferSize, - () => Resolve(openTaskCompletionSource), - cancellationToken).ConfigureAwait(false); + using (response) + { + await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false); + await using var fileStream = new FileStream(TempFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, FileOptions.Asynchronous); + await StreamHelper.CopyToAsync( + stream, + fileStream, + IODefaults.CopyToBufferSize, + () => Resolve(openTaskCompletionSource), + cancellationToken).ConfigureAwait(false); + } } catch (OperationCanceledException ex) { -- cgit v1.2.3