diff --git a/Jellyfin.Api/Auth/BaseAuthorizationHandler.cs b/Jellyfin.Api/Auth/BaseAuthorizationHandler.cs
index 953acac807..50b6468db4 100644
--- a/Jellyfin.Api/Auth/BaseAuthorizationHandler.cs
+++ b/Jellyfin.Api/Auth/BaseAuthorizationHandler.cs
@@ -42,11 +42,13 @@ namespace Jellyfin.Api.Auth
/// Request claims.
/// Whether to ignore parental control.
/// Whether access is to be allowed locally only.
+ /// Whether validation requires download permission.
/// Validated claim status.
protected bool ValidateClaims(
ClaimsPrincipal claimsPrincipal,
bool ignoreSchedule = false,
- bool localAccessOnly = false)
+ bool localAccessOnly = false,
+ bool requiredDownloadPermission = false)
{
// Ensure claim has userId.
var userId = ClaimHelpers.GetUserId(claimsPrincipal);
@@ -89,6 +91,13 @@ namespace Jellyfin.Api.Auth
return false;
}
+ // User attempting to download without permission.
+ if (requiredDownloadPermission
+ && !user.HasPermission(PermissionKind.EnableContentDownloading))
+ {
+ return false;
+ }
+
return true;
}
diff --git a/Jellyfin.Api/Auth/DownloadPolicy/DownloadHandler.cs b/Jellyfin.Api/Auth/DownloadPolicy/DownloadHandler.cs
new file mode 100644
index 0000000000..fcfa55dfec
--- /dev/null
+++ b/Jellyfin.Api/Auth/DownloadPolicy/DownloadHandler.cs
@@ -0,0 +1,45 @@
+using System.Threading.Tasks;
+using Jellyfin.Api.Auth.DefaultAuthorizationPolicy;
+using MediaBrowser.Common.Net;
+using MediaBrowser.Controller.Library;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Http;
+
+namespace Jellyfin.Api.Auth.DownloadPolicy
+{
+ ///
+ /// Download authorization handler.
+ ///
+ public class DownloadHandler : BaseAuthorizationHandler
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Instance of the interface.
+ /// Instance of the interface.
+ /// Instance of the interface.
+ public DownloadHandler(
+ IUserManager userManager,
+ INetworkManager networkManager,
+ IHttpContextAccessor httpContextAccessor)
+ : base(userManager, networkManager, httpContextAccessor)
+ {
+ }
+
+ ///
+ protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, DownloadRequirement requirement)
+ {
+ var validated = ValidateClaims(context.User);
+ if (validated)
+ {
+ context.Succeed(requirement);
+ }
+ else
+ {
+ context.Fail();
+ }
+
+ return Task.CompletedTask;
+ }
+ }
+}
diff --git a/Jellyfin.Api/Auth/DownloadPolicy/DownloadRequirement.cs b/Jellyfin.Api/Auth/DownloadPolicy/DownloadRequirement.cs
new file mode 100644
index 0000000000..b0a72a9dec
--- /dev/null
+++ b/Jellyfin.Api/Auth/DownloadPolicy/DownloadRequirement.cs
@@ -0,0 +1,11 @@
+using Microsoft.AspNetCore.Authorization;
+
+namespace Jellyfin.Api.Auth.DownloadPolicy
+{
+ ///
+ /// The download permission requirement.
+ ///
+ public class DownloadRequirement : IAuthorizationRequirement
+ {
+ }
+}
diff --git a/Jellyfin.Api/Constants/Policies.cs b/Jellyfin.Api/Constants/Policies.cs
index cf574e43df..851b56d732 100644
--- a/Jellyfin.Api/Constants/Policies.cs
+++ b/Jellyfin.Api/Constants/Policies.cs
@@ -29,5 +29,10 @@ namespace Jellyfin.Api.Constants
/// Policy name for escaping schedule controls.
///
public const string IgnoreSchedule = "IgnoreSchedule";
+
+ ///
+ /// Policy name for requiring download permission.
+ ///
+ public const string Download = "Download";
}
}
diff --git a/Jellyfin.Api/Controllers/ActivityLogController.cs b/Jellyfin.Api/Controllers/ActivityLogController.cs
index ec50fb022e..c287d1a773 100644
--- a/Jellyfin.Api/Controllers/ActivityLogController.cs
+++ b/Jellyfin.Api/Controllers/ActivityLogController.cs
@@ -35,17 +35,14 @@ namespace Jellyfin.Api.Controllers
/// Optional. The record index to start at. All items with a lower index will be dropped from the results.
/// Optional. The maximum number of records to return.
/// Optional. The minimum date. Format = ISO.
- /// Optional. Only returns activities that have a user associated.
/// Activity log returned.
/// A containing the log entries.
[HttpGet("Entries")]
[ProducesResponseType(StatusCodes.Status200OK)]
- [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "hasUserId", Justification = "Imported from ServiceStack")]
public ActionResult> GetLogEntries(
[FromQuery] int? startIndex,
[FromQuery] int? limit,
- [FromQuery] DateTime? minDate,
- bool? hasUserId)
+ [FromQuery] DateTime? minDate)
{
var filterFunc = new Func, IQueryable>(
entries => entries.Where(entry => entry.DateCreated >= minDate));
diff --git a/Jellyfin.Api/Controllers/AlbumsController.cs b/Jellyfin.Api/Controllers/AlbumsController.cs
new file mode 100644
index 0000000000..70315b0a33
--- /dev/null
+++ b/Jellyfin.Api/Controllers/AlbumsController.cs
@@ -0,0 +1,133 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Jellyfin.Api.Extensions;
+using Jellyfin.Api.Helpers;
+using MediaBrowser.Controller.Dto;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Entities.Audio;
+using MediaBrowser.Controller.Library;
+using MediaBrowser.Model.Dto;
+using MediaBrowser.Model.Querying;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Jellyfin.Api.Controllers
+{
+ ///
+ /// The albums controller.
+ ///
+ public class AlbumsController : BaseJellyfinApiController
+ {
+ private readonly IUserManager _userManager;
+ private readonly ILibraryManager _libraryManager;
+ private readonly IDtoService _dtoService;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Instance of the interface.
+ /// Instance of the interface.
+ /// Instance of the interface.
+ public AlbumsController(
+ IUserManager userManager,
+ ILibraryManager libraryManager,
+ IDtoService dtoService)
+ {
+ _userManager = userManager;
+ _libraryManager = libraryManager;
+ _dtoService = dtoService;
+ }
+
+ ///
+ /// Finds albums similar to a given album.
+ ///
+ /// The album id.
+ /// Optional. Filter by user id, and attach user data.
+ /// Optional. Ids of artists to exclude.
+ /// Optional. The maximum number of records to return.
+ /// Similar albums returned.
+ /// A with similar albums.
+ [HttpGet("/Albums/{albumId}/Similar")]
+ [ProducesResponseType(StatusCodes.Status200OK)]
+ public ActionResult> GetSimilarAlbums(
+ [FromRoute] string albumId,
+ [FromQuery] Guid userId,
+ [FromQuery] string? excludeArtistIds,
+ [FromQuery] int? limit)
+ {
+ var dtoOptions = new DtoOptions().AddClientFields(Request);
+
+ return SimilarItemsHelper.GetSimilarItemsResult(
+ dtoOptions,
+ _userManager,
+ _libraryManager,
+ _dtoService,
+ userId,
+ albumId,
+ excludeArtistIds,
+ limit,
+ new[] { typeof(MusicAlbum) },
+ GetAlbumSimilarityScore);
+ }
+
+ ///
+ /// Finds artists similar to a given artist.
+ ///
+ /// The artist id.
+ /// Optional. Filter by user id, and attach user data.
+ /// Optional. Ids of artists to exclude.
+ /// Optional. The maximum number of records to return.
+ /// Similar artists returned.
+ /// A with similar artists.
+ [HttpGet("/Artists/{artistId}/Similar")]
+ [ProducesResponseType(StatusCodes.Status200OK)]
+ public ActionResult> GetSimilarArtists(
+ [FromRoute] string artistId,
+ [FromQuery] Guid userId,
+ [FromQuery] string? excludeArtistIds,
+ [FromQuery] int? limit)
+ {
+ var dtoOptions = new DtoOptions().AddClientFields(Request);
+
+ return SimilarItemsHelper.GetSimilarItemsResult(
+ dtoOptions,
+ _userManager,
+ _libraryManager,
+ _dtoService,
+ userId,
+ artistId,
+ excludeArtistIds,
+ limit,
+ new[] { typeof(MusicArtist) },
+ SimilarItemsHelper.GetSimiliarityScore);
+ }
+
+ ///
+ /// Gets a similairty score of two albums.
+ ///
+ /// The first item.
+ /// The item1 people.
+ /// All people.
+ /// The second item.
+ /// System.Int32.
+ private int GetAlbumSimilarityScore(BaseItem item1, List item1People, List allPeople, BaseItem item2)
+ {
+ var points = SimilarItemsHelper.GetSimiliarityScore(item1, item1People, allPeople, item2);
+
+ var album1 = (MusicAlbum)item1;
+ var album2 = (MusicAlbum)item2;
+
+ var artists1 = album1
+ .GetAllArtists()
+ .DistinctNames()
+ .ToList();
+
+ var artists2 = new HashSet(
+ album2.GetAllArtists().DistinctNames(),
+ StringComparer.OrdinalIgnoreCase);
+
+ return points + artists1.Where(artists2.Contains).Sum(i => 5);
+ }
+ }
+}
diff --git a/Jellyfin.Api/Controllers/ApiKeyController.cs b/Jellyfin.Api/Controllers/ApiKeyController.cs
index ed521c1fc5..fef4d7262d 100644
--- a/Jellyfin.Api/Controllers/ApiKeyController.cs
+++ b/Jellyfin.Api/Controllers/ApiKeyController.cs
@@ -65,7 +65,7 @@ namespace Jellyfin.Api.Controllers
[HttpPost("Keys")]
[Authorize(Policy = Policies.RequiresElevation)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
- public ActionResult CreateKey([FromQuery, Required] string app)
+ public ActionResult CreateKey([FromQuery, Required] string? app)
{
_authRepo.Create(new AuthenticationInfo
{
@@ -88,7 +88,7 @@ namespace Jellyfin.Api.Controllers
[HttpDelete("Keys/{key}")]
[Authorize(Policy = Policies.RequiresElevation)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
- public ActionResult RevokeKey([FromRoute] string key)
+ public ActionResult RevokeKey([FromRoute] string? key)
{
_sessionManager.RevokeToken(key);
return NoContent();
diff --git a/Jellyfin.Api/Controllers/ArtistsController.cs b/Jellyfin.Api/Controllers/ArtistsController.cs
new file mode 100644
index 0000000000..6b2084170e
--- /dev/null
+++ b/Jellyfin.Api/Controllers/ArtistsController.cs
@@ -0,0 +1,488 @@
+using System;
+using System.Linq;
+using Jellyfin.Api.Constants;
+using Jellyfin.Api.Extensions;
+using Jellyfin.Api.Helpers;
+using Jellyfin.Data.Entities;
+using MediaBrowser.Controller.Dto;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Library;
+using MediaBrowser.Model.Dto;
+using MediaBrowser.Model.Querying;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Jellyfin.Api.Controllers
+{
+ ///
+ /// The artists controller.
+ ///
+ [Authorize(Policy = Policies.DefaultAuthorization)]
+ [Route("/Artists")]
+ public class ArtistsController : BaseJellyfinApiController
+ {
+ private readonly ILibraryManager _libraryManager;
+ private readonly IUserManager _userManager;
+ private readonly IDtoService _dtoService;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Instance of the interface.
+ /// Instance of the interface.
+ /// Instance of the interface.
+ public ArtistsController(
+ ILibraryManager libraryManager,
+ IUserManager userManager,
+ IDtoService dtoService)
+ {
+ _libraryManager = libraryManager;
+ _userManager = userManager;
+ _dtoService = dtoService;
+ }
+
+ ///
+ /// Gets all artists from a given item, folder, or the entire library.
+ ///
+ /// Optional filter by minimum community rating.
+ /// Optional. The record index to start at. All items with a lower index will be dropped from the results.
+ /// Optional. The maximum number of records to return.
+ /// Optional. Search term.
+ /// Specify this to localize the search to a specific item or folder. Omit to use the root.
+ /// Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimited. Options: Budget, Chapters, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines.
+ /// Optional. If specified, results will be filtered out based on item type. This allows multiple, comma delimited.
+ /// Optional. If specified, results will be filtered based on item type. This allows multiple, comma delimited.
+ /// Optional. Specify additional filters to apply. This allows multiple, comma delimited. Options: IsFolder, IsNotFolder, IsUnplayed, IsPlayed, IsFavorite, IsResumable, Likes, Dislikes.
+ /// Optional filter by items that are marked as favorite, or not.
+ /// Optional filter by MediaType. Allows multiple, comma delimited.
+ /// Optional. If specified, results will be filtered based on genre. This allows multiple, pipe delimited.
+ /// Optional. If specified, results will be filtered based on genre id. This allows multiple, pipe delimited.
+ /// Optional. If specified, results will be filtered based on OfficialRating. This allows multiple, pipe delimited.
+ /// Optional. If specified, results will be filtered based on tag. This allows multiple, pipe delimited.
+ /// Optional. If specified, results will be filtered based on production year. This allows multiple, comma delimited.
+ /// Optional, include user data.
+ /// Optional, the max number of images to return, per image type.
+ /// Optional. The image types to include in the output.
+ /// Optional. If specified, results will be filtered to include only those containing the specified person.
+ /// Optional. If specified, results will be filtered to include only those containing the specified person ids.
+ /// Optional. If specified, along with Person, results will be filtered to include only those containing the specified person and PersonType. Allows multiple, comma-delimited.
+ /// Optional. If specified, results will be filtered based on studio. This allows multiple, pipe delimited.
+ /// Optional. If specified, results will be filtered based on studio id. This allows multiple, pipe delimited.
+ /// User id.
+ /// Optional filter by items whose name is sorted equally or greater than a given input string.
+ /// Optional filter by items whose name is sorted equally than a given input string.
+ /// Optional filter by items whose name is equally or lesser than a given input string.
+ /// Optional, include image information in output.
+ /// Total record count.
+ /// Artists returned.
+ /// An containing the artists.
+ [HttpGet]
+ [ProducesResponseType(StatusCodes.Status200OK)]
+ public ActionResult> GetArtists(
+ [FromQuery] double? minCommunityRating,
+ [FromQuery] int? startIndex,
+ [FromQuery] int? limit,
+ [FromQuery] string searchTerm,
+ [FromQuery] string parentId,
+ [FromQuery] string fields,
+ [FromQuery] string excludeItemTypes,
+ [FromQuery] string includeItemTypes,
+ [FromQuery] string filters,
+ [FromQuery] bool? isFavorite,
+ [FromQuery] string mediaTypes,
+ [FromQuery] string genres,
+ [FromQuery] string genreIds,
+ [FromQuery] string officialRatings,
+ [FromQuery] string tags,
+ [FromQuery] string years,
+ [FromQuery] bool? enableUserData,
+ [FromQuery] int? imageTypeLimit,
+ [FromQuery] string enableImageTypes,
+ [FromQuery] string person,
+ [FromQuery] string personIds,
+ [FromQuery] string personTypes,
+ [FromQuery] string studios,
+ [FromQuery] string studioIds,
+ [FromQuery] Guid userId,
+ [FromQuery] string nameStartsWithOrGreater,
+ [FromQuery] string nameStartsWith,
+ [FromQuery] string nameLessThan,
+ [FromQuery] bool? enableImages = true,
+ [FromQuery] bool enableTotalRecordCount = true)
+ {
+ var dtoOptions = new DtoOptions()
+ .AddItemFields(fields)
+ .AddClientFields(Request)
+ .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
+
+ User? user = null;
+ BaseItem parentItem;
+
+ if (!userId.Equals(Guid.Empty))
+ {
+ user = _userManager.GetUserById(userId);
+ parentItem = string.IsNullOrEmpty(parentId) ? _libraryManager.GetUserRootFolder() : _libraryManager.GetItemById(parentId);
+ }
+ else
+ {
+ parentItem = string.IsNullOrEmpty(parentId) ? _libraryManager.RootFolder : _libraryManager.GetItemById(parentId);
+ }
+
+ var excludeItemTypesArr = RequestHelpers.Split(excludeItemTypes, ',', true);
+ var includeItemTypesArr = RequestHelpers.Split(includeItemTypes, ',', true);
+ var mediaTypesArr = RequestHelpers.Split(mediaTypes, ',', true);
+
+ var query = new InternalItemsQuery(user)
+ {
+ ExcludeItemTypes = excludeItemTypesArr,
+ IncludeItemTypes = includeItemTypesArr,
+ MediaTypes = mediaTypesArr,
+ StartIndex = startIndex,
+ Limit = limit,
+ IsFavorite = isFavorite,
+ NameLessThan = nameLessThan,
+ NameStartsWith = nameStartsWith,
+ NameStartsWithOrGreater = nameStartsWithOrGreater,
+ Tags = RequestHelpers.Split(tags, ',', true),
+ OfficialRatings = RequestHelpers.Split(officialRatings, ',', true),
+ Genres = RequestHelpers.Split(genres, ',', true),
+ GenreIds = RequestHelpers.GetGuids(genreIds),
+ StudioIds = RequestHelpers.GetGuids(studioIds),
+ Person = person,
+ PersonIds = RequestHelpers.GetGuids(personIds),
+ PersonTypes = RequestHelpers.Split(personTypes, ',', true),
+ Years = RequestHelpers.Split(years, ',', true).Select(int.Parse).ToArray(),
+ MinCommunityRating = minCommunityRating,
+ DtoOptions = dtoOptions,
+ SearchTerm = searchTerm,
+ EnableTotalRecordCount = enableTotalRecordCount
+ };
+
+ if (!string.IsNullOrWhiteSpace(parentId))
+ {
+ if (parentItem is Folder)
+ {
+ query.AncestorIds = new[] { new Guid(parentId) };
+ }
+ else
+ {
+ query.ItemIds = new[] { new Guid(parentId) };
+ }
+ }
+
+ // Studios
+ if (!string.IsNullOrEmpty(studios))
+ {
+ query.StudioIds = studios.Split('|').Select(i =>
+ {
+ try
+ {
+ return _libraryManager.GetStudio(i);
+ }
+ catch
+ {
+ return null;
+ }
+ }).Where(i => i != null).Select(i => i!.Id).ToArray();
+ }
+
+ foreach (var filter in RequestHelpers.GetFilters(filters))
+ {
+ switch (filter)
+ {
+ case ItemFilter.Dislikes:
+ query.IsLiked = false;
+ break;
+ case ItemFilter.IsFavorite:
+ query.IsFavorite = true;
+ break;
+ case ItemFilter.IsFavoriteOrLikes:
+ query.IsFavoriteOrLiked = true;
+ break;
+ case ItemFilter.IsFolder:
+ query.IsFolder = true;
+ break;
+ case ItemFilter.IsNotFolder:
+ query.IsFolder = false;
+ break;
+ case ItemFilter.IsPlayed:
+ query.IsPlayed = true;
+ break;
+ case ItemFilter.IsResumable:
+ query.IsResumable = true;
+ break;
+ case ItemFilter.IsUnplayed:
+ query.IsPlayed = false;
+ break;
+ case ItemFilter.Likes:
+ query.IsLiked = true;
+ break;
+ }
+ }
+
+ var result = _libraryManager.GetArtists(query);
+
+ var dtos = result.Items.Select(i =>
+ {
+ var (baseItem, itemCounts) = i;
+ var dto = _dtoService.GetItemByNameDto(baseItem, dtoOptions, null, user);
+
+ if (!string.IsNullOrWhiteSpace(includeItemTypes))
+ {
+ dto.ChildCount = itemCounts.ItemCount;
+ dto.ProgramCount = itemCounts.ProgramCount;
+ dto.SeriesCount = itemCounts.SeriesCount;
+ dto.EpisodeCount = itemCounts.EpisodeCount;
+ dto.MovieCount = itemCounts.MovieCount;
+ dto.TrailerCount = itemCounts.TrailerCount;
+ dto.AlbumCount = itemCounts.AlbumCount;
+ dto.SongCount = itemCounts.SongCount;
+ dto.ArtistCount = itemCounts.ArtistCount;
+ }
+
+ return dto;
+ });
+
+ return new QueryResult
+ {
+ Items = dtos.ToArray(),
+ TotalRecordCount = result.TotalRecordCount
+ };
+ }
+
+ ///
+ /// Gets all album artists from a given item, folder, or the entire library.
+ ///
+ /// Optional filter by minimum community rating.
+ /// Optional. The record index to start at. All items with a lower index will be dropped from the results.
+ /// Optional. The maximum number of records to return.
+ /// Optional. Search term.
+ /// Specify this to localize the search to a specific item or folder. Omit to use the root.
+ /// Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimited. Options: Budget, Chapters, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines.
+ /// Optional. If specified, results will be filtered out based on item type. This allows multiple, comma delimited.
+ /// Optional. If specified, results will be filtered based on item type. This allows multiple, comma delimited.
+ /// Optional. Specify additional filters to apply. This allows multiple, comma delimited. Options: IsFolder, IsNotFolder, IsUnplayed, IsPlayed, IsFavorite, IsResumable, Likes, Dislikes.
+ /// Optional filter by items that are marked as favorite, or not.
+ /// Optional filter by MediaType. Allows multiple, comma delimited.
+ /// Optional. If specified, results will be filtered based on genre. This allows multiple, pipe delimited.
+ /// Optional. If specified, results will be filtered based on genre id. This allows multiple, pipe delimited.
+ /// Optional. If specified, results will be filtered based on OfficialRating. This allows multiple, pipe delimited.
+ /// Optional. If specified, results will be filtered based on tag. This allows multiple, pipe delimited.
+ /// Optional. If specified, results will be filtered based on production year. This allows multiple, comma delimited.
+ /// Optional, include user data.
+ /// Optional, the max number of images to return, per image type.
+ /// Optional. The image types to include in the output.
+ /// Optional. If specified, results will be filtered to include only those containing the specified person.
+ /// Optional. If specified, results will be filtered to include only those containing the specified person ids.
+ /// Optional. If specified, along with Person, results will be filtered to include only those containing the specified person and PersonType. Allows multiple, comma-delimited.
+ /// Optional. If specified, results will be filtered based on studio. This allows multiple, pipe delimited.
+ /// Optional. If specified, results will be filtered based on studio id. This allows multiple, pipe delimited.
+ /// User id.
+ /// Optional filter by items whose name is sorted equally or greater than a given input string.
+ /// Optional filter by items whose name is sorted equally than a given input string.
+ /// Optional filter by items whose name is equally or lesser than a given input string.
+ /// Optional, include image information in output.
+ /// Total record count.
+ /// Album artists returned.
+ /// An containing the album artists.
+ [HttpGet("AlbumArtists")]
+ [ProducesResponseType(StatusCodes.Status200OK)]
+ public ActionResult> GetAlbumArtists(
+ [FromQuery] double? minCommunityRating,
+ [FromQuery] int? startIndex,
+ [FromQuery] int? limit,
+ [FromQuery] string searchTerm,
+ [FromQuery] string parentId,
+ [FromQuery] string fields,
+ [FromQuery] string excludeItemTypes,
+ [FromQuery] string includeItemTypes,
+ [FromQuery] string filters,
+ [FromQuery] bool? isFavorite,
+ [FromQuery] string mediaTypes,
+ [FromQuery] string genres,
+ [FromQuery] string genreIds,
+ [FromQuery] string officialRatings,
+ [FromQuery] string tags,
+ [FromQuery] string years,
+ [FromQuery] bool? enableUserData,
+ [FromQuery] int? imageTypeLimit,
+ [FromQuery] string enableImageTypes,
+ [FromQuery] string person,
+ [FromQuery] string personIds,
+ [FromQuery] string personTypes,
+ [FromQuery] string studios,
+ [FromQuery] string studioIds,
+ [FromQuery] Guid userId,
+ [FromQuery] string nameStartsWithOrGreater,
+ [FromQuery] string nameStartsWith,
+ [FromQuery] string nameLessThan,
+ [FromQuery] bool? enableImages = true,
+ [FromQuery] bool enableTotalRecordCount = true)
+ {
+ var dtoOptions = new DtoOptions()
+ .AddItemFields(fields)
+ .AddClientFields(Request)
+ .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
+
+ User? user = null;
+ BaseItem parentItem;
+
+ if (!userId.Equals(Guid.Empty))
+ {
+ user = _userManager.GetUserById(userId);
+ parentItem = string.IsNullOrEmpty(parentId) ? _libraryManager.GetUserRootFolder() : _libraryManager.GetItemById(parentId);
+ }
+ else
+ {
+ parentItem = string.IsNullOrEmpty(parentId) ? _libraryManager.RootFolder : _libraryManager.GetItemById(parentId);
+ }
+
+ var excludeItemTypesArr = RequestHelpers.Split(excludeItemTypes, ',', true);
+ var includeItemTypesArr = RequestHelpers.Split(includeItemTypes, ',', true);
+ var mediaTypesArr = RequestHelpers.Split(mediaTypes, ',', true);
+
+ var query = new InternalItemsQuery(user)
+ {
+ ExcludeItemTypes = excludeItemTypesArr,
+ IncludeItemTypes = includeItemTypesArr,
+ MediaTypes = mediaTypesArr,
+ StartIndex = startIndex,
+ Limit = limit,
+ IsFavorite = isFavorite,
+ NameLessThan = nameLessThan,
+ NameStartsWith = nameStartsWith,
+ NameStartsWithOrGreater = nameStartsWithOrGreater,
+ Tags = RequestHelpers.Split(tags, ',', true),
+ OfficialRatings = RequestHelpers.Split(officialRatings, ',', true),
+ Genres = RequestHelpers.Split(genres, ',', true),
+ GenreIds = RequestHelpers.GetGuids(genreIds),
+ StudioIds = RequestHelpers.GetGuids(studioIds),
+ Person = person,
+ PersonIds = RequestHelpers.GetGuids(personIds),
+ PersonTypes = RequestHelpers.Split(personTypes, ',', true),
+ Years = RequestHelpers.Split(years, ',', true).Select(int.Parse).ToArray(),
+ MinCommunityRating = minCommunityRating,
+ DtoOptions = dtoOptions,
+ SearchTerm = searchTerm,
+ EnableTotalRecordCount = enableTotalRecordCount
+ };
+
+ if (!string.IsNullOrWhiteSpace(parentId))
+ {
+ if (parentItem is Folder)
+ {
+ query.AncestorIds = new[] { new Guid(parentId) };
+ }
+ else
+ {
+ query.ItemIds = new[] { new Guid(parentId) };
+ }
+ }
+
+ // Studios
+ if (!string.IsNullOrEmpty(studios))
+ {
+ query.StudioIds = studios.Split('|').Select(i =>
+ {
+ try
+ {
+ return _libraryManager.GetStudio(i);
+ }
+ catch
+ {
+ return null;
+ }
+ }).Where(i => i != null).Select(i => i!.Id).ToArray();
+ }
+
+ foreach (var filter in RequestHelpers.GetFilters(filters))
+ {
+ switch (filter)
+ {
+ case ItemFilter.Dislikes:
+ query.IsLiked = false;
+ break;
+ case ItemFilter.IsFavorite:
+ query.IsFavorite = true;
+ break;
+ case ItemFilter.IsFavoriteOrLikes:
+ query.IsFavoriteOrLiked = true;
+ break;
+ case ItemFilter.IsFolder:
+ query.IsFolder = true;
+ break;
+ case ItemFilter.IsNotFolder:
+ query.IsFolder = false;
+ break;
+ case ItemFilter.IsPlayed:
+ query.IsPlayed = true;
+ break;
+ case ItemFilter.IsResumable:
+ query.IsResumable = true;
+ break;
+ case ItemFilter.IsUnplayed:
+ query.IsPlayed = false;
+ break;
+ case ItemFilter.Likes:
+ query.IsLiked = true;
+ break;
+ }
+ }
+
+ var result = _libraryManager.GetAlbumArtists(query);
+
+ var dtos = result.Items.Select(i =>
+ {
+ var (baseItem, itemCounts) = i;
+ var dto = _dtoService.GetItemByNameDto(baseItem, dtoOptions, null, user);
+
+ if (!string.IsNullOrWhiteSpace(includeItemTypes))
+ {
+ dto.ChildCount = itemCounts.ItemCount;
+ dto.ProgramCount = itemCounts.ProgramCount;
+ dto.SeriesCount = itemCounts.SeriesCount;
+ dto.EpisodeCount = itemCounts.EpisodeCount;
+ dto.MovieCount = itemCounts.MovieCount;
+ dto.TrailerCount = itemCounts.TrailerCount;
+ dto.AlbumCount = itemCounts.AlbumCount;
+ dto.SongCount = itemCounts.SongCount;
+ dto.ArtistCount = itemCounts.ArtistCount;
+ }
+
+ return dto;
+ });
+
+ return new QueryResult
+ {
+ Items = dtos.ToArray(),
+ TotalRecordCount = result.TotalRecordCount
+ };
+ }
+
+ ///
+ /// Gets an artist by name.
+ ///
+ /// Studio name.
+ /// Optional. Filter by user id, and attach user data.
+ /// Artist returned.
+ /// An containing the artist.
+ [HttpGet("{name}")]
+ [ProducesResponseType(StatusCodes.Status200OK)]
+ public ActionResult GetArtistByName([FromRoute] string name, [FromQuery] Guid userId)
+ {
+ var dtoOptions = new DtoOptions().AddClientFields(Request);
+
+ var item = _libraryManager.GetArtist(name, dtoOptions);
+
+ if (!userId.Equals(Guid.Empty))
+ {
+ var user = _userManager.GetUserById(userId);
+
+ return _dtoService.GetBaseItemDto(item, dtoOptions, user);
+ }
+
+ return _dtoService.GetBaseItemDto(item, dtoOptions);
+ }
+ }
+}
diff --git a/Jellyfin.Api/Controllers/CollectionController.cs b/Jellyfin.Api/Controllers/CollectionController.cs
new file mode 100644
index 0000000000..7ff98b2513
--- /dev/null
+++ b/Jellyfin.Api/Controllers/CollectionController.cs
@@ -0,0 +1,110 @@
+using System;
+using Jellyfin.Api.Constants;
+using Jellyfin.Api.Extensions;
+using Jellyfin.Api.Helpers;
+using MediaBrowser.Controller.Collections;
+using MediaBrowser.Controller.Dto;
+using MediaBrowser.Controller.Net;
+using MediaBrowser.Model.Collections;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Jellyfin.Api.Controllers
+{
+ ///
+ /// The collection controller.
+ ///
+ [Authorize(Policy = Policies.DefaultAuthorization)]
+ [Route("/Collections")]
+ public class CollectionController : BaseJellyfinApiController
+ {
+ private readonly ICollectionManager _collectionManager;
+ private readonly IDtoService _dtoService;
+ private readonly IAuthorizationContext _authContext;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Instance of interface.
+ /// Instance of interface.
+ /// Instance of interface.
+ public CollectionController(
+ ICollectionManager collectionManager,
+ IDtoService dtoService,
+ IAuthorizationContext authContext)
+ {
+ _collectionManager = collectionManager;
+ _dtoService = dtoService;
+ _authContext = authContext;
+ }
+
+ ///
+ /// Creates a new collection.
+ ///
+ /// The name of the collection.
+ /// Item Ids to add to the collection.
+ /// Whether or not to lock the new collection.
+ /// Optional. Create the collection within a specific folder.
+ /// Collection created.
+ /// A with information about the new collection.
+ [HttpPost]
+ [ProducesResponseType(StatusCodes.Status200OK)]
+ public ActionResult CreateCollection(
+ [FromQuery] string? name,
+ [FromQuery] string? ids,
+ [FromQuery] bool isLocked,
+ [FromQuery] Guid? parentId)
+ {
+ var userId = _authContext.GetAuthorizationInfo(Request).UserId;
+
+ var item = _collectionManager.CreateCollection(new CollectionCreationOptions
+ {
+ IsLocked = isLocked,
+ Name = name,
+ ParentId = parentId,
+ ItemIdList = RequestHelpers.Split(ids, ',', true),
+ UserIds = new[] { userId }
+ });
+
+ var dtoOptions = new DtoOptions().AddClientFields(Request);
+
+ var dto = _dtoService.GetBaseItemDto(item, dtoOptions);
+
+ return new CollectionCreationResult
+ {
+ Id = dto.Id
+ };
+ }
+
+ ///
+ /// Adds items to a collection.
+ ///
+ /// The collection id.
+ /// Item ids, comma delimited.
+ /// Items added to collection.
+ /// A indicating success.
+ [HttpPost("{collectionId}/Items")]
+ [ProducesResponseType(StatusCodes.Status204NoContent)]
+ public ActionResult AddToCollection([FromRoute] Guid collectionId, [FromQuery] string? itemIds)
+ {
+ _collectionManager.AddToCollection(collectionId, RequestHelpers.Split(itemIds, ',', true));
+ return NoContent();
+ }
+
+ ///
+ /// Removes items from a collection.
+ ///
+ /// The collection id.
+ /// Item ids, comma delimited.
+ /// Items removed from collection.
+ /// A indicating success.
+ [HttpDelete("{collectionId}/Items")]
+ [ProducesResponseType(StatusCodes.Status204NoContent)]
+ public ActionResult RemoveFromCollection([FromRoute] Guid collectionId, [FromQuery] string? itemIds)
+ {
+ _collectionManager.RemoveFromCollection(collectionId, RequestHelpers.Split(itemIds, ',', true));
+ return NoContent();
+ }
+ }
+}
diff --git a/Jellyfin.Api/Controllers/ConfigurationController.cs b/Jellyfin.Api/Controllers/ConfigurationController.cs
index d275ed2eba..13933cb33b 100644
--- a/Jellyfin.Api/Controllers/ConfigurationController.cs
+++ b/Jellyfin.Api/Controllers/ConfigurationController.cs
@@ -70,7 +70,7 @@ namespace Jellyfin.Api.Controllers
/// Configuration.
[HttpGet("Configuration/{key}")]
[ProducesResponseType(StatusCodes.Status200OK)]
- public ActionResult