From 49c6a99e00d5bef49c4154a5a9500f39b84cc32e Mon Sep 17 00:00:00 2001 From: Tim Eisele Date: Fri, 9 May 2025 16:35:29 +0200 Subject: Cleanup external item data cleanup (#14072) --- MediaBrowser.Controller/Entities/BaseItem.cs | 2 +- MediaBrowser.Controller/Entities/TV/Episode.cs | 39 +++++++++++++++++++++- MediaBrowser.Controller/IO/IExternalDataManager.cs | 19 +++++++++++ .../MediaSegments/IMediaSegmentManager.cs | 21 +++++------- .../Sorting/IUserBaseItemComparer.cs | 2 +- .../Trickplay/ITrickplayManager.cs | 12 +++++-- 6 files changed, 77 insertions(+), 18 deletions(-) create mode 100644 MediaBrowser.Controller/IO/IExternalDataManager.cs (limited to 'MediaBrowser.Controller') diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 16fde9440..c2efa4ad3 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -1436,7 +1436,7 @@ namespace MediaBrowser.Controller.Entities return info.LastWriteTimeUtc != DateModified; } - return info.LastWriteTimeUtc != DateModified && info.Length != (Size ?? 0); + return info.LastWriteTimeUtc != DateModified; } return false; diff --git a/MediaBrowser.Controller/Entities/TV/Episode.cs b/MediaBrowser.Controller/Entities/TV/Episode.cs index 46bad3f3b..6bdba36f9 100644 --- a/MediaBrowser.Controller/Entities/TV/Episode.cs +++ b/MediaBrowser.Controller/Entities/TV/Episode.cs @@ -7,12 +7,14 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text.Json.Serialization; +using System.Threading; using Jellyfin.Data.Enums; using Jellyfin.Extensions; +using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Controller.Providers; +using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Entities; using MediaBrowser.Model.IO; -using MediaBrowser.Model.Providers; using Microsoft.Extensions.Logging; namespace MediaBrowser.Controller.Entities.TV @@ -22,6 +24,8 @@ namespace MediaBrowser.Controller.Entities.TV /// public class Episode : Video, IHasTrailers, IHasLookupInfo, IHasSeries { + public static IMediaEncoder MediaEncoder { get; set; } + /// [JsonIgnore] public IReadOnlyList LocalTrailers => GetExtras() @@ -325,6 +329,39 @@ namespace MediaBrowser.Controller.Entities.TV { if (SourceType == SourceType.Library || SourceType == SourceType.LiveTV) { + var libraryOptions = LibraryManager.GetLibraryOptions(this); + if (libraryOptions.EnableEmbeddedEpisodeInfos && string.Equals(Container, "mp4", StringComparison.OrdinalIgnoreCase)) + { + try + { + var mediaInfo = MediaEncoder.GetMediaInfo( + new MediaInfoRequest + { + MediaSource = GetMediaSources(false)[0], + MediaType = DlnaProfileType.Video + }, + CancellationToken.None).GetAwaiter().GetResult(); + if (mediaInfo.ParentIndexNumber > 0) + { + ParentIndexNumber = mediaInfo.ParentIndexNumber; + } + + if (mediaInfo.IndexNumber > 0) + { + IndexNumber = mediaInfo.IndexNumber; + } + + if (!string.IsNullOrEmpty(mediaInfo.ShowName)) + { + SeriesName = mediaInfo.ShowName; + } + } + catch (Exception ex) + { + Logger.LogError(ex, "Error reading the episode information with ffprobe. Episode: {EpisodeInfo}", Path); + } + } + try { if (LibraryManager.FillMissingEpisodeNumbersFromPath(this, replaceAllMetadata)) diff --git a/MediaBrowser.Controller/IO/IExternalDataManager.cs b/MediaBrowser.Controller/IO/IExternalDataManager.cs new file mode 100644 index 000000000..f69f4586c --- /dev/null +++ b/MediaBrowser.Controller/IO/IExternalDataManager.cs @@ -0,0 +1,19 @@ +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Controller.Entities; + +namespace MediaBrowser.Controller.IO; + +/// +/// Interface IPathManager. +/// +public interface IExternalDataManager +{ + /// + /// Deletes all external item data. + /// + /// The item. + /// The cancellation token. + /// Task. + Task DeleteExternalItemDataAsync(BaseItem item, CancellationToken cancellationToken); +} diff --git a/MediaBrowser.Controller/MediaSegments/IMediaSegmentManager.cs b/MediaBrowser.Controller/MediaSegments/IMediaSegmentManager.cs index 6cd6474f7..720c607f1 100644 --- a/MediaBrowser.Controller/MediaSegments/IMediaSegmentManager.cs +++ b/MediaBrowser.Controller/MediaSegments/IMediaSegmentManager.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Jellyfin.Database.Implementations.Entities; using Jellyfin.Database.Implementations.Enums; using MediaBrowser.Controller.Entities; +using MediaBrowser.Model.Configuration; using MediaBrowser.Model.MediaSegments; namespace MediaBrowser.Controller.MediaSegments; @@ -18,10 +19,11 @@ public interface IMediaSegmentManager /// Uses all segment providers enabled for the 's library to get the Media Segments. /// /// The Item to evaluate. + /// The library options. /// If set, will remove existing segments and replace it with new ones otherwise will check for existing segments and if found any, stops. - /// stop request token. + /// The cancellation token. /// A task that indicates the Operation is finished. - Task RunSegmentPluginProviders(BaseItem baseItem, bool overwrite, CancellationToken cancellationToken); + Task RunSegmentPluginProviders(BaseItem baseItem, LibraryOptions libraryOptions, bool overwrite, CancellationToken cancellationToken); /// /// Returns if this item supports media segments. @@ -49,26 +51,19 @@ public interface IMediaSegmentManager /// Deletes all media segments of an item. /// /// The to delete all segments for. + /// The cancellation token. /// a task. - Task DeleteSegmentsAsync(Guid itemId); - - /// - /// Obtains all segments associated with the itemId. - /// - /// The id of the . - /// filters all media segments of the given type to be included. If null all types are included. - /// When set filters the segments to only return those that which providers are currently enabled on their library. - /// An enumerator of 's. - Task> GetSegmentsAsync(Guid itemId, IEnumerable? typeFilter, bool filterByProvider = true); + Task DeleteSegmentsAsync(Guid itemId, CancellationToken cancellationToken); /// /// Obtains all segments associated with the itemId. /// /// The . /// filters all media segments of the given type to be included. If null all types are included. + /// The library options. /// When set filters the segments to only return those that which providers are currently enabled on their library. /// An enumerator of 's. - Task> GetSegmentsAsync(BaseItem item, IEnumerable? typeFilter, bool filterByProvider = true); + Task> GetSegmentsAsync(BaseItem item, IEnumerable? typeFilter, LibraryOptions libraryOptions, bool filterByProvider = true); /// /// Gets information about any media segments stored for the given itemId. diff --git a/MediaBrowser.Controller/Sorting/IUserBaseItemComparer.cs b/MediaBrowser.Controller/Sorting/IUserBaseItemComparer.cs index 97f653edf..2206a021a 100644 --- a/MediaBrowser.Controller/Sorting/IUserBaseItemComparer.cs +++ b/MediaBrowser.Controller/Sorting/IUserBaseItemComparer.cs @@ -26,6 +26,6 @@ namespace MediaBrowser.Controller.Sorting /// Gets or sets the user data repository. /// /// The user data repository. - IUserDataManager UserDataRepository { get; set; } + IUserDataManager UserDataManager { get; set; } } } diff --git a/MediaBrowser.Controller/Trickplay/ITrickplayManager.cs b/MediaBrowser.Controller/Trickplay/ITrickplayManager.cs index 9ac8ead11..fba24329a 100644 --- a/MediaBrowser.Controller/Trickplay/ITrickplayManager.cs +++ b/MediaBrowser.Controller/Trickplay/ITrickplayManager.cs @@ -21,7 +21,7 @@ public interface ITrickplayManager /// The library options. /// CancellationToken to use for operation. /// Task. - Task RefreshTrickplayDataAsync(Video video, bool replace, LibraryOptions? libraryOptions, CancellationToken cancellationToken); + Task RefreshTrickplayDataAsync(Video video, bool replace, LibraryOptions libraryOptions, CancellationToken cancellationToken); /// /// Creates trickplay tiles out of individual thumbnails. @@ -58,6 +58,14 @@ public interface ITrickplayManager /// Task. Task SaveTrickplayInfo(TrickplayInfo info); + /// + /// Deletes all trickplay info for an item. + /// + /// The item id. + /// The cancellation token. + /// Task. + Task DeleteTrickplayDataAsync(Guid itemId, CancellationToken cancellationToken); + /// /// Gets all trickplay infos for all media streams of an item. /// @@ -93,7 +101,7 @@ public interface ITrickplayManager /// The library options. /// CancellationToken to use for operation. /// Task. - Task MoveGeneratedTrickplayDataAsync(Video video, LibraryOptions? libraryOptions, CancellationToken cancellationToken); + Task MoveGeneratedTrickplayDataAsync(Video video, LibraryOptions libraryOptions, CancellationToken cancellationToken); /// /// Gets the trickplay HLS playlist. -- cgit v1.2.3