From cd9154f1100f2133fc4f8aaa4d021c1848222e32 Mon Sep 17 00:00:00 2001 From: Kevin G Date: Wed, 22 Oct 2025 22:17:28 -0500 Subject: Add moveToTop option to IPlaylistManager.AddItemToPlaylistAsync Signed-off-by: Kevin G --- MediaBrowser.Controller/Playlists/IPlaylistManager.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'MediaBrowser.Controller') diff --git a/MediaBrowser.Controller/Playlists/IPlaylistManager.cs b/MediaBrowser.Controller/Playlists/IPlaylistManager.cs index 497c4a511e..3d265f6915 100644 --- a/MediaBrowser.Controller/Playlists/IPlaylistManager.cs +++ b/MediaBrowser.Controller/Playlists/IPlaylistManager.cs @@ -61,9 +61,10 @@ namespace MediaBrowser.Controller.Playlists /// /// The playlist identifier. /// The item ids. + /// Optional. Whether to move the added item to the top. /// The user identifier. /// Task. - Task AddItemToPlaylistAsync(Guid playlistId, IReadOnlyCollection itemIds, Guid userId); + Task AddItemToPlaylistAsync(Guid playlistId, IReadOnlyCollection itemIds, bool? moveToTop, Guid userId); /// /// Removes from playlist. -- cgit v1.2.3 From 79061f463507b98f8b03db3431d23789d90de412 Mon Sep 17 00:00:00 2001 From: Kevin G Date: Thu, 23 Oct 2025 19:27:34 -0500 Subject: Change moveToTop in AddItemToPlaylistAsync to 0-based position Signed-off-by: Kevin G --- .../Playlists/PlaylistManager.cs | 25 +++++++++++++++++----- Jellyfin.Api/Controllers/PlaylistsController.cs | 6 +++--- .../Playlists/IPlaylistManager.cs | 4 ++-- 3 files changed, 25 insertions(+), 10 deletions(-) (limited to 'MediaBrowser.Controller') diff --git a/Emby.Server.Implementations/Playlists/PlaylistManager.cs b/Emby.Server.Implementations/Playlists/PlaylistManager.cs index 6ce2883d16..4538fc6a3f 100644 --- a/Emby.Server.Implementations/Playlists/PlaylistManager.cs +++ b/Emby.Server.Implementations/Playlists/PlaylistManager.cs @@ -198,7 +198,7 @@ namespace Emby.Server.Implementations.Playlists return Playlist.GetPlaylistItems(items, user, options); } - public Task AddItemToPlaylistAsync(Guid playlistId, IReadOnlyCollection itemIds, bool? moveToTop, Guid userId) + public Task AddItemToPlaylistAsync(Guid playlistId, IReadOnlyCollection itemIds, int? position, Guid userId) { var user = userId.IsEmpty() ? null : _userManager.GetUserById(userId); @@ -210,10 +210,10 @@ namespace Emby.Server.Implementations.Playlists { EnableImages = true }, - moveToTop); + position); } - private async Task AddToPlaylistInternal(Guid playlistId, IReadOnlyCollection newItemIds, User user, DtoOptions options, bool? moveToTop = null) + private async Task AddToPlaylistInternal(Guid playlistId, IReadOnlyCollection newItemIds, User user, DtoOptions options, int? position = null) { // Retrieve the existing playlist var playlist = _libraryManager.GetItemById(playlistId) as Playlist @@ -248,9 +248,24 @@ namespace Emby.Server.Implementations.Playlists } // Update the playlist in the repository - if (moveToTop.HasValue && moveToTop.Value) + if (position.HasValue) { - playlist.LinkedChildren = [.. childrenToAdd, .. playlist.LinkedChildren]; + if (position.Value <= 0) + { + playlist.LinkedChildren = [.. childrenToAdd, .. playlist.LinkedChildren]; + } + else if (position.Value >= playlist.LinkedChildren.Length) + { + playlist.LinkedChildren = [.. playlist.LinkedChildren, .. childrenToAdd]; + } + else + { + playlist.LinkedChildren = [ + .. playlist.LinkedChildren[0..position.Value], + .. childrenToAdd, + .. playlist.LinkedChildren[position.Value..playlist.LinkedChildren.Length] + ]; + } } else { diff --git a/Jellyfin.Api/Controllers/PlaylistsController.cs b/Jellyfin.Api/Controllers/PlaylistsController.cs index 6cf403c953..1076d1eb06 100644 --- a/Jellyfin.Api/Controllers/PlaylistsController.cs +++ b/Jellyfin.Api/Controllers/PlaylistsController.cs @@ -359,7 +359,7 @@ public class PlaylistsController : BaseJellyfinApiController /// /// The playlist id. /// Item id, comma delimited. - /// Optional. Whether to move the added item to the top. + /// Optional. 0-based index where to place the items or at the end if null. /// The userId. /// Items added to playlist. /// Access forbidden. @@ -372,7 +372,7 @@ public class PlaylistsController : BaseJellyfinApiController public async Task AddItemToPlaylist( [FromRoute, Required] Guid playlistId, [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] Guid[] ids, - [FromQuery] bool? moveToTop, + [FromQuery] int? position, [FromQuery] Guid? userId) { userId = RequestHelpers.GetUserId(User, userId); @@ -390,7 +390,7 @@ public class PlaylistsController : BaseJellyfinApiController return Forbid(); } - await _playlistManager.AddItemToPlaylistAsync(playlistId, ids, moveToTop, userId.Value).ConfigureAwait(false); + await _playlistManager.AddItemToPlaylistAsync(playlistId, ids, position, userId.Value).ConfigureAwait(false); return NoContent(); } diff --git a/MediaBrowser.Controller/Playlists/IPlaylistManager.cs b/MediaBrowser.Controller/Playlists/IPlaylistManager.cs index 3d265f6915..92aa923968 100644 --- a/MediaBrowser.Controller/Playlists/IPlaylistManager.cs +++ b/MediaBrowser.Controller/Playlists/IPlaylistManager.cs @@ -61,10 +61,10 @@ namespace MediaBrowser.Controller.Playlists /// /// The playlist identifier. /// The item ids. - /// Optional. Whether to move the added item to the top. + /// Optional. 0-based index where to place the items or at the end if null. /// The user identifier. /// Task. - Task AddItemToPlaylistAsync(Guid playlistId, IReadOnlyCollection itemIds, bool? moveToTop, Guid userId); + Task AddItemToPlaylistAsync(Guid playlistId, IReadOnlyCollection itemIds, int? position, Guid userId); /// /// Removes from playlist. -- cgit v1.2.3 From a37e83d448598cfd06fee7f52ee7130248d6bac3 Mon Sep 17 00:00:00 2001 From: dfederm Date: Sat, 14 Feb 2026 05:57:25 -0500 Subject: Backport pull request #16227 from jellyfin/release-10.11.z Reattach user data after item removal during library scan Original-merge: be712956932a9337f0706fd8ef68eb53feb3f4ff Merged-by: Bond-009 Backported-by: Bond_009 --- MediaBrowser.Controller/Entities/Folder.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'MediaBrowser.Controller') diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index d2a3290c47..2ecb6cbdff 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -452,6 +452,7 @@ namespace MediaBrowser.Controller.Entities // That's all the new and changed ones - now see if any have been removed and need cleanup var itemsRemoved = currentChildren.Values.Except(validChildren).ToList(); var shouldRemove = !IsRoot || allowRemoveRoot; + var actuallyRemoved = new List(); // If it's an AggregateFolder, don't remove if (shouldRemove && itemsRemoved.Count > 0) { @@ -467,6 +468,7 @@ namespace MediaBrowser.Controller.Entities { Logger.LogDebug("Removed item: {Path}", item.Path); + actuallyRemoved.Add(item); item.SetParent(null); LibraryManager.DeleteItem(item, new DeleteOptions { DeleteFileLocation = false }, this, false); } @@ -477,6 +479,20 @@ namespace MediaBrowser.Controller.Entities { LibraryManager.CreateItems(newItems, this, cancellationToken); } + + // After removing items, reattach any detached user data to remaining children + // that share the same user data keys (eg. same episode replaced with a new file). + if (actuallyRemoved.Count > 0) + { + var removedKeys = actuallyRemoved.SelectMany(i => i.GetUserDataKeys()).ToHashSet(); + foreach (var child in validChildren) + { + if (child.GetUserDataKeys().Any(removedKeys.Contains)) + { + await child.ReattachUserDataAsync(cancellationToken).ConfigureAwait(false); + } + } + } } else { -- cgit v1.2.3