mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-07-30 17:25:40 +02:00
Move TrailersService to Jellyfin.Api
This commit is contained in:
parent
121de44ad0
commit
31a492b2b9
306
Jellyfin.Api/Controllers/TrailersController.cs
Normal file
306
Jellyfin.Api/Controllers/TrailersController.cs
Normal file
|
@ -0,0 +1,306 @@
|
||||||
|
using System;
|
||||||
|
using Jellyfin.Api.Constants;
|
||||||
|
using MediaBrowser.Controller.Dto;
|
||||||
|
using MediaBrowser.Controller.Library;
|
||||||
|
using MediaBrowser.Model.Dto;
|
||||||
|
using MediaBrowser.Model.Globalization;
|
||||||
|
using MediaBrowser.Model.Querying;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace Jellyfin.Api.Controllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The trailers controller.
|
||||||
|
/// </summary>
|
||||||
|
[Authorize(Policy = Policies.DefaultAuthorization)]
|
||||||
|
public class TrailersController : BaseJellyfinApiController
|
||||||
|
{
|
||||||
|
private readonly IUserManager _userManager;
|
||||||
|
private readonly ILibraryManager _libraryManager;
|
||||||
|
private readonly ILogger<ItemsController> _logger;
|
||||||
|
private readonly IDtoService _dtoService;
|
||||||
|
private readonly ILocalizationManager _localizationManager;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="TrailersController"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="loggerFactory">Instance of the <see cref="ILoggerFactory"/> interface.</param>
|
||||||
|
/// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
|
||||||
|
/// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
|
||||||
|
/// <param name="dtoService">Instance of the <see cref="IDtoService"/> interface.</param>
|
||||||
|
/// <param name="localizationManager">Instance of the <see cref="ILocalizationManager"/> interface.</param>
|
||||||
|
public TrailersController(
|
||||||
|
ILoggerFactory loggerFactory,
|
||||||
|
IUserManager userManager,
|
||||||
|
ILibraryManager libraryManager,
|
||||||
|
IDtoService dtoService,
|
||||||
|
ILocalizationManager localizationManager)
|
||||||
|
{
|
||||||
|
_userManager = userManager;
|
||||||
|
_libraryManager = libraryManager;
|
||||||
|
_dtoService = dtoService;
|
||||||
|
_localizationManager = localizationManager;
|
||||||
|
_logger = loggerFactory.CreateLogger<ItemsController>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Finds movies and trailers similar to a given trailer.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId">The user id.</param>
|
||||||
|
/// <param name="maxOfficialRating">Optional filter by maximum official rating (PG, PG-13, TV-MA, etc).</param>
|
||||||
|
/// <param name="hasThemeSong">Optional filter by items with theme songs.</param>
|
||||||
|
/// <param name="hasThemeVideo">Optional filter by items with theme videos.</param>
|
||||||
|
/// <param name="hasSubtitles">Optional filter by items with subtitles.</param>
|
||||||
|
/// <param name="hasSpecialFeature">Optional filter by items with special features.</param>
|
||||||
|
/// <param name="hasTrailer">Optional filter by items with trailers.</param>
|
||||||
|
/// <param name="adjacentTo">Optional. Return items that are siblings of a supplied item.</param>
|
||||||
|
/// <param name="parentIndexNumber">Optional filter by parent index number.</param>
|
||||||
|
/// <param name="hasParentalRating">Optional filter by items that have or do not have a parental rating.</param>
|
||||||
|
/// <param name="isHd">Optional filter by items that are HD or not.</param>
|
||||||
|
/// <param name="is4K">Optional filter by items that are 4K or not.</param>
|
||||||
|
/// <param name="locationTypes">Optional. If specified, results will be filtered based on LocationType. This allows multiple, comma delimeted.</param>
|
||||||
|
/// <param name="excludeLocationTypes">Optional. If specified, results will be filtered based on the LocationType. This allows multiple, comma delimeted.</param>
|
||||||
|
/// <param name="isMissing">Optional filter by items that are missing episodes or not.</param>
|
||||||
|
/// <param name="isUnaired">Optional filter by items that are unaired episodes or not.</param>
|
||||||
|
/// <param name="minCommunityRating">Optional filter by minimum community rating.</param>
|
||||||
|
/// <param name="minCriticRating">Optional filter by minimum critic rating.</param>
|
||||||
|
/// <param name="minPremiereDate">Optional. The minimum premiere date. Format = ISO.</param>
|
||||||
|
/// <param name="minDateLastSaved">Optional. The minimum last saved date. Format = ISO.</param>
|
||||||
|
/// <param name="minDateLastSavedForUser">Optional. The minimum last saved date for the current user. Format = ISO.</param>
|
||||||
|
/// <param name="maxPremiereDate">Optional. The maximum premiere date. Format = ISO.</param>
|
||||||
|
/// <param name="hasOverview">Optional filter by items that have an overview or not.</param>
|
||||||
|
/// <param name="hasImdbId">Optional filter by items that have an imdb id or not.</param>
|
||||||
|
/// <param name="hasTmdbId">Optional filter by items that have a tmdb id or not.</param>
|
||||||
|
/// <param name="hasTvdbId">Optional filter by items that have a tvdb id or not.</param>
|
||||||
|
/// <param name="excludeItemIds">Optional. If specified, results will be filtered by exxcluding item ids. This allows multiple, comma delimeted.</param>
|
||||||
|
/// <param name="startIndex">Optional. The record index to start at. All items with a lower index will be dropped from the results.</param>
|
||||||
|
/// <param name="limit">Optional. The maximum number of records to return.</param>
|
||||||
|
/// <param name="recursive">When searching within folders, this determines whether or not the search will be recursive. true/false.</param>
|
||||||
|
/// <param name="searchTerm">Optional. Filter based on a search term.</param>
|
||||||
|
/// <param name="sortOrder">Sort Order - Ascending,Descending.</param>
|
||||||
|
/// <param name="parentId">Specify this to localize the search to a specific item or folder. Omit to use the root.</param>
|
||||||
|
/// <param name="fields">Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimeted. Options: Budget, Chapters, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines.</param>
|
||||||
|
/// <param name="excludeItemTypes">Optional. If specified, results will be filtered based on item type. This allows multiple, comma delimeted.</param>
|
||||||
|
/// <param name="filters">Optional. Specify additional filters to apply. This allows multiple, comma delimeted. Options: IsFolder, IsNotFolder, IsUnplayed, IsPlayed, IsFavorite, IsResumable, Likes, Dislikes.</param>
|
||||||
|
/// <param name="isFavorite">Optional filter by items that are marked as favorite, or not.</param>
|
||||||
|
/// <param name="mediaTypes">Optional filter by MediaType. Allows multiple, comma delimited.</param>
|
||||||
|
/// <param name="imageTypes">Optional. If specified, results will be filtered based on those containing image types. This allows multiple, comma delimited.</param>
|
||||||
|
/// <param name="sortBy">Optional. Specify one or more sort orders, comma delimeted. Options: Album, AlbumArtist, Artist, Budget, CommunityRating, CriticRating, DateCreated, DatePlayed, PlayCount, PremiereDate, ProductionYear, SortName, Random, Revenue, Runtime.</param>
|
||||||
|
/// <param name="isPlayed">Optional filter by items that are played, or not.</param>
|
||||||
|
/// <param name="genres">Optional. If specified, results will be filtered based on genre. This allows multiple, pipe delimeted.</param>
|
||||||
|
/// <param name="officialRatings">Optional. If specified, results will be filtered based on OfficialRating. This allows multiple, pipe delimeted.</param>
|
||||||
|
/// <param name="tags">Optional. If specified, results will be filtered based on tag. This allows multiple, pipe delimeted.</param>
|
||||||
|
/// <param name="years">Optional. If specified, results will be filtered based on production year. This allows multiple, comma delimeted.</param>
|
||||||
|
/// <param name="enableUserData">Optional, include user data.</param>
|
||||||
|
/// <param name="imageTypeLimit">Optional, the max number of images to return, per image type.</param>
|
||||||
|
/// <param name="enableImageTypes">Optional. The image types to include in the output.</param>
|
||||||
|
/// <param name="person">Optional. If specified, results will be filtered to include only those containing the specified person.</param>
|
||||||
|
/// <param name="personIds">Optional. If specified, results will be filtered to include only those containing the specified person id.</param>
|
||||||
|
/// <param name="personTypes">Optional. If specified, along with Person, results will be filtered to include only those containing the specified person and PersonType. Allows multiple, comma-delimited.</param>
|
||||||
|
/// <param name="studios">Optional. If specified, results will be filtered based on studio. This allows multiple, pipe delimeted.</param>
|
||||||
|
/// <param name="artists">Optional. If specified, results will be filtered based on artists. This allows multiple, pipe delimeted.</param>
|
||||||
|
/// <param name="excludeArtistIds">Optional. If specified, results will be filtered based on artist id. This allows multiple, pipe delimeted.</param>
|
||||||
|
/// <param name="artistIds">Optional. If specified, results will be filtered to include only those containing the specified artist id.</param>
|
||||||
|
/// <param name="albumArtistIds">Optional. If specified, results will be filtered to include only those containing the specified album artist id.</param>
|
||||||
|
/// <param name="contributingArtistIds">Optional. If specified, results will be filtered to include only those containing the specified contributing artist id.</param>
|
||||||
|
/// <param name="albums">Optional. If specified, results will be filtered based on album. This allows multiple, pipe delimeted.</param>
|
||||||
|
/// <param name="albumIds">Optional. If specified, results will be filtered based on album id. This allows multiple, pipe delimeted.</param>
|
||||||
|
/// <param name="ids">Optional. If specific items are needed, specify a list of item id's to retrieve. This allows multiple, comma delimited.</param>
|
||||||
|
/// <param name="videoTypes">Optional filter by VideoType (videofile, dvd, bluray, iso). Allows multiple, comma delimeted.</param>
|
||||||
|
/// <param name="minOfficialRating">Optional filter by minimum official rating (PG, PG-13, TV-MA, etc).</param>
|
||||||
|
/// <param name="isLocked">Optional filter by items that are locked.</param>
|
||||||
|
/// <param name="isPlaceHolder">Optional filter by items that are placeholders.</param>
|
||||||
|
/// <param name="hasOfficialRating">Optional filter by items that have official ratings.</param>
|
||||||
|
/// <param name="collapseBoxSetItems">Whether or not to hide items behind their boxsets.</param>
|
||||||
|
/// <param name="minWidth">Optional. Filter by the minimum width of the item.</param>
|
||||||
|
/// <param name="minHeight">Optional. Filter by the minimum height of the item.</param>
|
||||||
|
/// <param name="maxWidth">Optional. Filter by the maximum width of the item.</param>
|
||||||
|
/// <param name="maxHeight">Optional. Filter by the maximum height of the item.</param>
|
||||||
|
/// <param name="is3D">Optional filter by items that are 3D, or not.</param>
|
||||||
|
/// <param name="seriesStatus">Optional filter by Series Status. Allows multiple, comma delimeted.</param>
|
||||||
|
/// <param name="nameStartsWithOrGreater">Optional filter by items whose name is sorted equally or greater than a given input string.</param>
|
||||||
|
/// <param name="nameStartsWith">Optional filter by items whose name is sorted equally than a given input string.</param>
|
||||||
|
/// <param name="nameLessThan">Optional filter by items whose name is equally or lesser than a given input string.</param>
|
||||||
|
/// <param name="studioIds">Optional. If specified, results will be filtered based on studio id. This allows multiple, pipe delimeted.</param>
|
||||||
|
/// <param name="genreIds">Optional. If specified, results will be filtered based on genre id. This allows multiple, pipe delimeted.</param>
|
||||||
|
/// <param name="enableTotalRecordCount">Optional. Enable the total record count.</param>
|
||||||
|
/// <param name="enableImages">Optional, include image information in output.</param>
|
||||||
|
/// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the trailers.</returns>
|
||||||
|
[HttpGet("/Trailers")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
public ActionResult<QueryResult<BaseItemDto>> GetTrailers(
|
||||||
|
[FromQuery] Guid userId,
|
||||||
|
[FromQuery] string? maxOfficialRating,
|
||||||
|
[FromQuery] bool? hasThemeSong,
|
||||||
|
[FromQuery] bool? hasThemeVideo,
|
||||||
|
[FromQuery] bool? hasSubtitles,
|
||||||
|
[FromQuery] bool? hasSpecialFeature,
|
||||||
|
[FromQuery] bool? hasTrailer,
|
||||||
|
[FromQuery] string? adjacentTo,
|
||||||
|
[FromQuery] int? parentIndexNumber,
|
||||||
|
[FromQuery] bool? hasParentalRating,
|
||||||
|
[FromQuery] bool? isHd,
|
||||||
|
[FromQuery] bool? is4K,
|
||||||
|
[FromQuery] string? locationTypes,
|
||||||
|
[FromQuery] string? excludeLocationTypes,
|
||||||
|
[FromQuery] bool? isMissing,
|
||||||
|
[FromQuery] bool? isUnaired,
|
||||||
|
[FromQuery] double? minCommunityRating,
|
||||||
|
[FromQuery] double? minCriticRating,
|
||||||
|
[FromQuery] DateTime? minPremiereDate,
|
||||||
|
[FromQuery] DateTime? minDateLastSaved,
|
||||||
|
[FromQuery] DateTime? minDateLastSavedForUser,
|
||||||
|
[FromQuery] DateTime? maxPremiereDate,
|
||||||
|
[FromQuery] bool? hasOverview,
|
||||||
|
[FromQuery] bool? hasImdbId,
|
||||||
|
[FromQuery] bool? hasTmdbId,
|
||||||
|
[FromQuery] bool? hasTvdbId,
|
||||||
|
[FromQuery] string? excludeItemIds,
|
||||||
|
[FromQuery] int? startIndex,
|
||||||
|
[FromQuery] int? limit,
|
||||||
|
[FromQuery] bool? recursive,
|
||||||
|
[FromQuery] string? searchTerm,
|
||||||
|
[FromQuery] string? sortOrder,
|
||||||
|
[FromQuery] string? parentId,
|
||||||
|
[FromQuery] string? fields,
|
||||||
|
[FromQuery] string? excludeItemTypes,
|
||||||
|
[FromQuery] string? filters,
|
||||||
|
[FromQuery] bool? isFavorite,
|
||||||
|
[FromQuery] string? mediaTypes,
|
||||||
|
[FromQuery] string? imageTypes,
|
||||||
|
[FromQuery] string? sortBy,
|
||||||
|
[FromQuery] bool? isPlayed,
|
||||||
|
[FromQuery] string? genres,
|
||||||
|
[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? artists,
|
||||||
|
[FromQuery] string? excludeArtistIds,
|
||||||
|
[FromQuery] string? artistIds,
|
||||||
|
[FromQuery] string? albumArtistIds,
|
||||||
|
[FromQuery] string? contributingArtistIds,
|
||||||
|
[FromQuery] string? albums,
|
||||||
|
[FromQuery] string? albumIds,
|
||||||
|
[FromQuery] string? ids,
|
||||||
|
[FromQuery] string? videoTypes,
|
||||||
|
[FromQuery] string? minOfficialRating,
|
||||||
|
[FromQuery] bool? isLocked,
|
||||||
|
[FromQuery] bool? isPlaceHolder,
|
||||||
|
[FromQuery] bool? hasOfficialRating,
|
||||||
|
[FromQuery] bool? collapseBoxSetItems,
|
||||||
|
[FromQuery] int? minWidth,
|
||||||
|
[FromQuery] int? minHeight,
|
||||||
|
[FromQuery] int? maxWidth,
|
||||||
|
[FromQuery] int? maxHeight,
|
||||||
|
[FromQuery] bool? is3D,
|
||||||
|
[FromQuery] string? seriesStatus,
|
||||||
|
[FromQuery] string? nameStartsWithOrGreater,
|
||||||
|
[FromQuery] string? nameStartsWith,
|
||||||
|
[FromQuery] string? nameLessThan,
|
||||||
|
[FromQuery] string? studioIds,
|
||||||
|
[FromQuery] string? genreIds,
|
||||||
|
[FromQuery] bool enableTotalRecordCount = true,
|
||||||
|
[FromQuery] bool? enableImages = true)
|
||||||
|
{
|
||||||
|
var includeItemTypes = "Trailer";
|
||||||
|
|
||||||
|
return new ItemsController(
|
||||||
|
_userManager,
|
||||||
|
_libraryManager,
|
||||||
|
_localizationManager,
|
||||||
|
_dtoService,
|
||||||
|
_logger)
|
||||||
|
.GetItems(
|
||||||
|
userId,
|
||||||
|
maxOfficialRating,
|
||||||
|
hasThemeSong,
|
||||||
|
hasThemeVideo,
|
||||||
|
hasSubtitles,
|
||||||
|
hasSpecialFeature,
|
||||||
|
hasTrailer,
|
||||||
|
adjacentTo,
|
||||||
|
parentIndexNumber,
|
||||||
|
hasParentalRating,
|
||||||
|
isHd,
|
||||||
|
is4K,
|
||||||
|
locationTypes,
|
||||||
|
excludeLocationTypes,
|
||||||
|
isMissing,
|
||||||
|
isUnaired,
|
||||||
|
minCommunityRating,
|
||||||
|
minCriticRating,
|
||||||
|
minPremiereDate,
|
||||||
|
minDateLastSaved,
|
||||||
|
minDateLastSavedForUser,
|
||||||
|
maxPremiereDate,
|
||||||
|
hasOverview,
|
||||||
|
hasImdbId,
|
||||||
|
hasTmdbId,
|
||||||
|
hasTvdbId,
|
||||||
|
excludeItemIds,
|
||||||
|
startIndex,
|
||||||
|
limit,
|
||||||
|
recursive,
|
||||||
|
searchTerm,
|
||||||
|
sortOrder,
|
||||||
|
parentId,
|
||||||
|
fields,
|
||||||
|
excludeItemTypes,
|
||||||
|
includeItemTypes,
|
||||||
|
filters,
|
||||||
|
isFavorite,
|
||||||
|
mediaTypes,
|
||||||
|
imageTypes,
|
||||||
|
sortBy,
|
||||||
|
isPlayed,
|
||||||
|
genres,
|
||||||
|
officialRatings,
|
||||||
|
tags,
|
||||||
|
years,
|
||||||
|
enableUserData,
|
||||||
|
imageTypeLimit,
|
||||||
|
enableImageTypes,
|
||||||
|
person,
|
||||||
|
personIds,
|
||||||
|
personTypes,
|
||||||
|
studios,
|
||||||
|
artists,
|
||||||
|
excludeArtistIds,
|
||||||
|
artistIds,
|
||||||
|
albumArtistIds,
|
||||||
|
contributingArtistIds,
|
||||||
|
albums,
|
||||||
|
albumIds,
|
||||||
|
ids,
|
||||||
|
videoTypes,
|
||||||
|
minOfficialRating,
|
||||||
|
isLocked,
|
||||||
|
isPlaceHolder,
|
||||||
|
hasOfficialRating,
|
||||||
|
collapseBoxSetItems,
|
||||||
|
minWidth,
|
||||||
|
minHeight,
|
||||||
|
maxWidth,
|
||||||
|
maxHeight,
|
||||||
|
is3D,
|
||||||
|
seriesStatus,
|
||||||
|
nameStartsWithOrGreater,
|
||||||
|
nameStartsWith,
|
||||||
|
nameLessThan,
|
||||||
|
studioIds,
|
||||||
|
genreIds,
|
||||||
|
enableTotalRecordCount,
|
||||||
|
enableImages);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,89 +0,0 @@
|
||||||
using MediaBrowser.Api.UserLibrary;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
|
||||||
using MediaBrowser.Controller.Dto;
|
|
||||||
using MediaBrowser.Controller.Library;
|
|
||||||
using MediaBrowser.Controller.Net;
|
|
||||||
using MediaBrowser.Model.Dto;
|
|
||||||
using MediaBrowser.Model.Globalization;
|
|
||||||
using MediaBrowser.Model.Querying;
|
|
||||||
using MediaBrowser.Model.Serialization;
|
|
||||||
using MediaBrowser.Model.Services;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Api.Movies
|
|
||||||
{
|
|
||||||
[Route("/Trailers", "GET", Summary = "Finds movies and trailers similar to a given trailer.")]
|
|
||||||
public class Getrailers : BaseItemsRequest, IReturn<QueryResult<BaseItemDto>>
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Class TrailersService
|
|
||||||
/// </summary>
|
|
||||||
[Authenticated]
|
|
||||||
public class TrailersService : BaseApiService
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The _user manager
|
|
||||||
/// </summary>
|
|
||||||
private readonly IUserManager _userManager;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The _library manager
|
|
||||||
/// </summary>
|
|
||||||
private readonly ILibraryManager _libraryManager;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The logger for the created <see cref="ItemsService"/> instances.
|
|
||||||
/// </summary>
|
|
||||||
private readonly ILogger<ItemsService> _logger;
|
|
||||||
|
|
||||||
private readonly IDtoService _dtoService;
|
|
||||||
private readonly ILocalizationManager _localizationManager;
|
|
||||||
private readonly IJsonSerializer _json;
|
|
||||||
private readonly IAuthorizationContext _authContext;
|
|
||||||
|
|
||||||
public TrailersService(
|
|
||||||
ILoggerFactory loggerFactory,
|
|
||||||
IServerConfigurationManager serverConfigurationManager,
|
|
||||||
IHttpResultFactory httpResultFactory,
|
|
||||||
IUserManager userManager,
|
|
||||||
ILibraryManager libraryManager,
|
|
||||||
IDtoService dtoService,
|
|
||||||
ILocalizationManager localizationManager,
|
|
||||||
IJsonSerializer json,
|
|
||||||
IAuthorizationContext authContext)
|
|
||||||
: base(loggerFactory.CreateLogger<TrailersService>(), serverConfigurationManager, httpResultFactory)
|
|
||||||
{
|
|
||||||
_userManager = userManager;
|
|
||||||
_libraryManager = libraryManager;
|
|
||||||
_dtoService = dtoService;
|
|
||||||
_localizationManager = localizationManager;
|
|
||||||
_json = json;
|
|
||||||
_authContext = authContext;
|
|
||||||
_logger = loggerFactory.CreateLogger<ItemsService>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public object Get(Getrailers request)
|
|
||||||
{
|
|
||||||
var json = _json.SerializeToString(request);
|
|
||||||
var getItems = _json.DeserializeFromString<GetItems>(json);
|
|
||||||
|
|
||||||
getItems.IncludeItemTypes = "Trailer";
|
|
||||||
|
|
||||||
return new ItemsService(
|
|
||||||
_logger,
|
|
||||||
ServerConfigurationManager,
|
|
||||||
ResultFactory,
|
|
||||||
_userManager,
|
|
||||||
_libraryManager,
|
|
||||||
_localizationManager,
|
|
||||||
_dtoService,
|
|
||||||
_authContext)
|
|
||||||
{
|
|
||||||
Request = Request,
|
|
||||||
|
|
||||||
}.Get(getItems);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,511 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Globalization;
|
|
||||||
using System.Linq;
|
|
||||||
using Jellyfin.Data.Entities;
|
|
||||||
using Jellyfin.Data.Enums;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
|
||||||
using MediaBrowser.Controller.Dto;
|
|
||||||
using MediaBrowser.Controller.Entities;
|
|
||||||
using MediaBrowser.Controller.Library;
|
|
||||||
using MediaBrowser.Controller.Net;
|
|
||||||
using MediaBrowser.Model.Dto;
|
|
||||||
using MediaBrowser.Model.Entities;
|
|
||||||
using MediaBrowser.Model.Globalization;
|
|
||||||
using MediaBrowser.Model.Querying;
|
|
||||||
using MediaBrowser.Model.Services;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using MusicAlbum = MediaBrowser.Controller.Entities.Audio.MusicAlbum;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Api.UserLibrary
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Class GetItems
|
|
||||||
/// </summary>
|
|
||||||
public class GetItems : BaseItemsRequest, IReturn<QueryResult<BaseItemDto>>
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public class GetResumeItems : BaseItemsRequest, IReturn<QueryResult<BaseItemDto>>
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Class ItemsService
|
|
||||||
/// </summary>
|
|
||||||
[Authenticated]
|
|
||||||
public class ItemsService : BaseApiService
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The _user manager
|
|
||||||
/// </summary>
|
|
||||||
private readonly IUserManager _userManager;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The _library manager
|
|
||||||
/// </summary>
|
|
||||||
private readonly ILibraryManager _libraryManager;
|
|
||||||
private readonly ILocalizationManager _localization;
|
|
||||||
|
|
||||||
private readonly IDtoService _dtoService;
|
|
||||||
private readonly IAuthorizationContext _authContext;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="ItemsService" /> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="userManager">The user manager.</param>
|
|
||||||
/// <param name="libraryManager">The library manager.</param>
|
|
||||||
/// <param name="localization">The localization.</param>
|
|
||||||
/// <param name="dtoService">The dto service.</param>
|
|
||||||
public ItemsService(
|
|
||||||
ILogger<ItemsService> logger,
|
|
||||||
IServerConfigurationManager serverConfigurationManager,
|
|
||||||
IHttpResultFactory httpResultFactory,
|
|
||||||
IUserManager userManager,
|
|
||||||
ILibraryManager libraryManager,
|
|
||||||
ILocalizationManager localization,
|
|
||||||
IDtoService dtoService,
|
|
||||||
IAuthorizationContext authContext)
|
|
||||||
: base(logger, serverConfigurationManager, httpResultFactory)
|
|
||||||
{
|
|
||||||
_userManager = userManager;
|
|
||||||
_libraryManager = libraryManager;
|
|
||||||
_localization = localization;
|
|
||||||
_dtoService = dtoService;
|
|
||||||
_authContext = authContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
public object Get(GetResumeItems request)
|
|
||||||
{
|
|
||||||
var user = _userManager.GetUserById(request.UserId);
|
|
||||||
|
|
||||||
var parentIdGuid = string.IsNullOrWhiteSpace(request.ParentId) ? Guid.Empty : new Guid(request.ParentId);
|
|
||||||
|
|
||||||
var options = GetDtoOptions(_authContext, request);
|
|
||||||
|
|
||||||
var ancestorIds = Array.Empty<Guid>();
|
|
||||||
|
|
||||||
var excludeFolderIds = user.GetPreference(PreferenceKind.LatestItemExcludes);
|
|
||||||
if (parentIdGuid.Equals(Guid.Empty) && excludeFolderIds.Length > 0)
|
|
||||||
{
|
|
||||||
ancestorIds = _libraryManager.GetUserRootFolder().GetChildren(user, true)
|
|
||||||
.Where(i => i is Folder)
|
|
||||||
.Where(i => !excludeFolderIds.Contains(i.Id.ToString("N", CultureInfo.InvariantCulture)))
|
|
||||||
.Select(i => i.Id)
|
|
||||||
.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
var itemsResult = _libraryManager.GetItemsResult(new InternalItemsQuery(user)
|
|
||||||
{
|
|
||||||
OrderBy = new[] { (ItemSortBy.DatePlayed, SortOrder.Descending) },
|
|
||||||
IsResumable = true,
|
|
||||||
StartIndex = request.StartIndex,
|
|
||||||
Limit = request.Limit,
|
|
||||||
ParentId = parentIdGuid,
|
|
||||||
Recursive = true,
|
|
||||||
DtoOptions = options,
|
|
||||||
MediaTypes = request.GetMediaTypes(),
|
|
||||||
IsVirtualItem = false,
|
|
||||||
CollapseBoxSetItems = false,
|
|
||||||
EnableTotalRecordCount = request.EnableTotalRecordCount,
|
|
||||||
AncestorIds = ancestorIds,
|
|
||||||
IncludeItemTypes = request.GetIncludeItemTypes(),
|
|
||||||
ExcludeItemTypes = request.GetExcludeItemTypes(),
|
|
||||||
SearchTerm = request.SearchTerm
|
|
||||||
});
|
|
||||||
|
|
||||||
var returnItems = _dtoService.GetBaseItemDtos(itemsResult.Items, options, user);
|
|
||||||
|
|
||||||
var result = new QueryResult<BaseItemDto>
|
|
||||||
{
|
|
||||||
StartIndex = request.StartIndex.GetValueOrDefault(),
|
|
||||||
TotalRecordCount = itemsResult.TotalRecordCount,
|
|
||||||
Items = returnItems
|
|
||||||
};
|
|
||||||
|
|
||||||
return ToOptimizedResult(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the specified request.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The request.</param>
|
|
||||||
/// <returns>System.Object.</returns>
|
|
||||||
public object Get(GetItems request)
|
|
||||||
{
|
|
||||||
if (request == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(request));
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = GetItems(request);
|
|
||||||
|
|
||||||
return ToOptimizedResult(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the items.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The request.</param>
|
|
||||||
private QueryResult<BaseItemDto> GetItems(GetItems request)
|
|
||||||
{
|
|
||||||
var user = request.UserId == Guid.Empty ? null : _userManager.GetUserById(request.UserId);
|
|
||||||
|
|
||||||
var dtoOptions = GetDtoOptions(_authContext, request);
|
|
||||||
|
|
||||||
var result = GetQueryResult(request, dtoOptions, user);
|
|
||||||
|
|
||||||
if (result == null)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("GetItemsToSerialize returned null");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.Items == null)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("GetItemsToSerialize result.Items returned null");
|
|
||||||
}
|
|
||||||
|
|
||||||
var dtoList = _dtoService.GetBaseItemDtos(result.Items, dtoOptions, user);
|
|
||||||
|
|
||||||
return new QueryResult<BaseItemDto>
|
|
||||||
{
|
|
||||||
StartIndex = request.StartIndex.GetValueOrDefault(),
|
|
||||||
TotalRecordCount = result.TotalRecordCount,
|
|
||||||
Items = dtoList
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the items to serialize.
|
|
||||||
/// </summary>
|
|
||||||
private QueryResult<BaseItem> GetQueryResult(GetItems request, DtoOptions dtoOptions, User user)
|
|
||||||
{
|
|
||||||
if (string.Equals(request.IncludeItemTypes, "Playlist", StringComparison.OrdinalIgnoreCase)
|
|
||||||
|| string.Equals(request.IncludeItemTypes, "BoxSet", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
request.ParentId = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
BaseItem item = null;
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(request.ParentId))
|
|
||||||
{
|
|
||||||
item = _libraryManager.GetItemById(request.ParentId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item == null)
|
|
||||||
{
|
|
||||||
item = _libraryManager.GetUserRootFolder();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(item is Folder folder))
|
|
||||||
{
|
|
||||||
folder = _libraryManager.GetUserRootFolder();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (folder is IHasCollectionType hasCollectionType
|
|
||||||
&& string.Equals(hasCollectionType.CollectionType, CollectionType.Playlists, StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
request.Recursive = true;
|
|
||||||
request.IncludeItemTypes = "Playlist";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isInEnabledFolder = user.GetPreference(PreferenceKind.EnabledFolders).Any(i => new Guid(i) == item.Id)
|
|
||||||
// Assume all folders inside an EnabledChannel are enabled
|
|
||||||
|| user.GetPreference(PreferenceKind.EnabledChannels).Any(i => new Guid(i) == item.Id);
|
|
||||||
|
|
||||||
var collectionFolders = _libraryManager.GetCollectionFolders(item);
|
|
||||||
foreach (var collectionFolder in collectionFolders)
|
|
||||||
{
|
|
||||||
if (user.GetPreference(PreferenceKind.EnabledFolders).Contains(
|
|
||||||
collectionFolder.Id.ToString("N", CultureInfo.InvariantCulture),
|
|
||||||
StringComparer.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
isInEnabledFolder = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(item is UserRootFolder)
|
|
||||||
&& !isInEnabledFolder
|
|
||||||
&& !user.HasPermission(PermissionKind.EnableAllFolders)
|
|
||||||
&& !user.HasPermission(PermissionKind.EnableAllChannels))
|
|
||||||
{
|
|
||||||
Logger.LogWarning("{UserName} is not permitted to access Library {ItemName}.", user.Username, item.Name);
|
|
||||||
return new QueryResult<BaseItem>
|
|
||||||
{
|
|
||||||
Items = Array.Empty<BaseItem>(),
|
|
||||||
TotalRecordCount = 0,
|
|
||||||
StartIndex = 0
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request.Recursive || !string.IsNullOrEmpty(request.Ids) || !(item is UserRootFolder))
|
|
||||||
{
|
|
||||||
return folder.GetItems(GetItemsQuery(request, dtoOptions, user));
|
|
||||||
}
|
|
||||||
|
|
||||||
var itemsArray = folder.GetChildren(user, true);
|
|
||||||
return new QueryResult<BaseItem>
|
|
||||||
{
|
|
||||||
Items = itemsArray,
|
|
||||||
TotalRecordCount = itemsArray.Count,
|
|
||||||
StartIndex = 0
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private InternalItemsQuery GetItemsQuery(GetItems request, DtoOptions dtoOptions, User user)
|
|
||||||
{
|
|
||||||
var query = new InternalItemsQuery(user)
|
|
||||||
{
|
|
||||||
IsPlayed = request.IsPlayed,
|
|
||||||
MediaTypes = request.GetMediaTypes(),
|
|
||||||
IncludeItemTypes = request.GetIncludeItemTypes(),
|
|
||||||
ExcludeItemTypes = request.GetExcludeItemTypes(),
|
|
||||||
Recursive = request.Recursive,
|
|
||||||
OrderBy = request.GetOrderBy(),
|
|
||||||
|
|
||||||
IsFavorite = request.IsFavorite,
|
|
||||||
Limit = request.Limit,
|
|
||||||
StartIndex = request.StartIndex,
|
|
||||||
IsMissing = request.IsMissing,
|
|
||||||
IsUnaired = request.IsUnaired,
|
|
||||||
CollapseBoxSetItems = request.CollapseBoxSetItems,
|
|
||||||
NameLessThan = request.NameLessThan,
|
|
||||||
NameStartsWith = request.NameStartsWith,
|
|
||||||
NameStartsWithOrGreater = request.NameStartsWithOrGreater,
|
|
||||||
HasImdbId = request.HasImdbId,
|
|
||||||
IsPlaceHolder = request.IsPlaceHolder,
|
|
||||||
IsLocked = request.IsLocked,
|
|
||||||
MinWidth = request.MinWidth,
|
|
||||||
MinHeight = request.MinHeight,
|
|
||||||
MaxWidth = request.MaxWidth,
|
|
||||||
MaxHeight = request.MaxHeight,
|
|
||||||
Is3D = request.Is3D,
|
|
||||||
HasTvdbId = request.HasTvdbId,
|
|
||||||
HasTmdbId = request.HasTmdbId,
|
|
||||||
HasOverview = request.HasOverview,
|
|
||||||
HasOfficialRating = request.HasOfficialRating,
|
|
||||||
HasParentalRating = request.HasParentalRating,
|
|
||||||
HasSpecialFeature = request.HasSpecialFeature,
|
|
||||||
HasSubtitles = request.HasSubtitles,
|
|
||||||
HasThemeSong = request.HasThemeSong,
|
|
||||||
HasThemeVideo = request.HasThemeVideo,
|
|
||||||
HasTrailer = request.HasTrailer,
|
|
||||||
IsHD = request.IsHD,
|
|
||||||
Is4K = request.Is4K,
|
|
||||||
Tags = request.GetTags(),
|
|
||||||
OfficialRatings = request.GetOfficialRatings(),
|
|
||||||
Genres = request.GetGenres(),
|
|
||||||
ArtistIds = GetGuids(request.ArtistIds),
|
|
||||||
AlbumArtistIds = GetGuids(request.AlbumArtistIds),
|
|
||||||
ContributingArtistIds = GetGuids(request.ContributingArtistIds),
|
|
||||||
GenreIds = GetGuids(request.GenreIds),
|
|
||||||
StudioIds = GetGuids(request.StudioIds),
|
|
||||||
Person = request.Person,
|
|
||||||
PersonIds = GetGuids(request.PersonIds),
|
|
||||||
PersonTypes = request.GetPersonTypes(),
|
|
||||||
Years = request.GetYears(),
|
|
||||||
ImageTypes = request.GetImageTypes(),
|
|
||||||
VideoTypes = request.GetVideoTypes(),
|
|
||||||
AdjacentTo = request.AdjacentTo,
|
|
||||||
ItemIds = GetGuids(request.Ids),
|
|
||||||
MinCommunityRating = request.MinCommunityRating,
|
|
||||||
MinCriticRating = request.MinCriticRating,
|
|
||||||
ParentId = string.IsNullOrWhiteSpace(request.ParentId) ? Guid.Empty : new Guid(request.ParentId),
|
|
||||||
ParentIndexNumber = request.ParentIndexNumber,
|
|
||||||
EnableTotalRecordCount = request.EnableTotalRecordCount,
|
|
||||||
ExcludeItemIds = GetGuids(request.ExcludeItemIds),
|
|
||||||
DtoOptions = dtoOptions,
|
|
||||||
SearchTerm = request.SearchTerm
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(request.Ids) || !string.IsNullOrWhiteSpace(request.SearchTerm))
|
|
||||||
{
|
|
||||||
query.CollapseBoxSetItems = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var filter in request.GetFilters())
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(request.MinDateLastSaved))
|
|
||||||
{
|
|
||||||
query.MinDateLastSaved = DateTime.Parse(request.MinDateLastSaved, null, DateTimeStyles.RoundtripKind).ToUniversalTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(request.MinDateLastSavedForUser))
|
|
||||||
{
|
|
||||||
query.MinDateLastSavedForUser = DateTime.Parse(request.MinDateLastSavedForUser, null, DateTimeStyles.RoundtripKind).ToUniversalTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(request.MinPremiereDate))
|
|
||||||
{
|
|
||||||
query.MinPremiereDate = DateTime.Parse(request.MinPremiereDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(request.MaxPremiereDate))
|
|
||||||
{
|
|
||||||
query.MaxPremiereDate = DateTime.Parse(request.MaxPremiereDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter by Series Status
|
|
||||||
if (!string.IsNullOrEmpty(request.SeriesStatus))
|
|
||||||
{
|
|
||||||
query.SeriesStatuses = request.SeriesStatus.Split(',').Select(d => (SeriesStatus)Enum.Parse(typeof(SeriesStatus), d, true)).ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExcludeLocationTypes
|
|
||||||
if (!string.IsNullOrEmpty(request.ExcludeLocationTypes))
|
|
||||||
{
|
|
||||||
var excludeLocationTypes = request.ExcludeLocationTypes.Split(',').Select(d => (LocationType)Enum.Parse(typeof(LocationType), d, true)).ToArray();
|
|
||||||
if (excludeLocationTypes.Contains(LocationType.Virtual))
|
|
||||||
{
|
|
||||||
query.IsVirtualItem = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(request.LocationTypes))
|
|
||||||
{
|
|
||||||
var requestedLocationTypes =
|
|
||||||
request.LocationTypes.Split(',');
|
|
||||||
|
|
||||||
if (requestedLocationTypes.Length > 0 && requestedLocationTypes.Length < 4)
|
|
||||||
{
|
|
||||||
query.IsVirtualItem = requestedLocationTypes.Contains(LocationType.Virtual.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Min official rating
|
|
||||||
if (!string.IsNullOrWhiteSpace(request.MinOfficialRating))
|
|
||||||
{
|
|
||||||
query.MinParentalRating = _localization.GetRatingLevel(request.MinOfficialRating);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Max official rating
|
|
||||||
if (!string.IsNullOrWhiteSpace(request.MaxOfficialRating))
|
|
||||||
{
|
|
||||||
query.MaxParentalRating = _localization.GetRatingLevel(request.MaxOfficialRating);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Artists
|
|
||||||
if (!string.IsNullOrEmpty(request.Artists))
|
|
||||||
{
|
|
||||||
query.ArtistIds = request.Artists.Split('|').Select(i =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return _libraryManager.GetArtist(i, new DtoOptions(false));
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}).Where(i => i != null).Select(i => i.Id).ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExcludeArtistIds
|
|
||||||
if (!string.IsNullOrWhiteSpace(request.ExcludeArtistIds))
|
|
||||||
{
|
|
||||||
query.ExcludeArtistIds = GetGuids(request.ExcludeArtistIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(request.AlbumIds))
|
|
||||||
{
|
|
||||||
query.AlbumIds = GetGuids(request.AlbumIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Albums
|
|
||||||
if (!string.IsNullOrEmpty(request.Albums))
|
|
||||||
{
|
|
||||||
query.AlbumIds = request.Albums.Split('|').SelectMany(i =>
|
|
||||||
{
|
|
||||||
return _libraryManager.GetItemIds(new InternalItemsQuery
|
|
||||||
{
|
|
||||||
IncludeItemTypes = new[] { typeof(MusicAlbum).Name },
|
|
||||||
Name = i,
|
|
||||||
Limit = 1
|
|
||||||
});
|
|
||||||
}).ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Studios
|
|
||||||
if (!string.IsNullOrEmpty(request.Studios))
|
|
||||||
{
|
|
||||||
query.StudioIds = request.Studios.Split('|').Select(i =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return _libraryManager.GetStudio(i);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}).Where(i => i != null).Select(i => i.Id).ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply default sorting if none requested
|
|
||||||
if (query.OrderBy.Count == 0)
|
|
||||||
{
|
|
||||||
// Albums by artist
|
|
||||||
if (query.ArtistIds.Length > 0 && query.IncludeItemTypes.Length == 1 && string.Equals(query.IncludeItemTypes[0], "MusicAlbum", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
query.OrderBy = new[]
|
|
||||||
{
|
|
||||||
new ValueTuple<string, SortOrder>(ItemSortBy.ProductionYear, SortOrder.Descending),
|
|
||||||
new ValueTuple<string, SortOrder>(ItemSortBy.SortName, SortOrder.Ascending)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return query;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Class DateCreatedComparer
|
|
||||||
/// </summary>
|
|
||||||
public class DateCreatedComparer : IComparer<BaseItem>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Compares the specified x.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">The x.</param>
|
|
||||||
/// <param name="y">The y.</param>
|
|
||||||
/// <returns>System.Int32.</returns>
|
|
||||||
public int Compare(BaseItem x, BaseItem y)
|
|
||||||
{
|
|
||||||
return x.DateCreated.CompareTo(y.DateCreated);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue