public ActionResult AddToPlaylist( [FromRoute] string?playlistId, [FromQuery] string?ids, [FromQuery] Guid?userId) { _playlistManager.AddToPlaylist(playlistId, RequestHelpers.GetGuids(ids), userId ?? Guid.Empty); return(NoContent()); }
public async Task <ActionResult> AddToPlaylist( [FromRoute, Required] Guid playlistId, [FromQuery] string?ids, [FromQuery] Guid?userId) { await _playlistManager.AddToPlaylistAsync(playlistId, RequestHelpers.GetGuids(ids), userId ?? Guid.Empty).ConfigureAwait(false); return(NoContent()); }
public async Task <ActionResult <PlaylistCreationResult> > CreatePlaylist( [FromBody, Required] CreatePlaylistDto createPlaylistRequest) { Guid[] idGuidArray = RequestHelpers.GetGuids(createPlaylistRequest.Ids); var result = await _playlistManager.CreatePlaylist(new PlaylistCreationRequest { Name = createPlaylistRequest.Name, ItemIdList = idGuidArray, UserId = createPlaylistRequest.UserId, MediaType = createPlaylistRequest.MediaType }).ConfigureAwait(false); return(result); }
public ActionResult Play( [FromRoute, Required] string sessionId, [FromQuery, Required] PlayCommand playCommand, [FromQuery, Required] string itemIds, [FromQuery] long?startPositionTicks) { var playRequest = new PlayRequest { ItemIds = RequestHelpers.GetGuids(itemIds), StartPositionTicks = startPositionTicks, PlayCommand = playCommand }; _sessionManager.SendPlayCommand( RequestHelpers.GetSession(_sessionManager, _authContext, Request).Id, sessionId, playRequest, CancellationToken.None); return(NoContent()); }
public ActionResult <QueryResult <BaseItemDto> > GetPersons( [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.HasValue && !userId.Equals(Guid.Empty)) { user = _userManager.GetUserById(userId.Value); parentItem = string.IsNullOrEmpty(parentId) ? _libraryManager.GetUserRootFolder() : _libraryManager.GetItemById(parentId); } else { parentItem = string.IsNullOrEmpty(parentId) ? _libraryManager.RootFolder : _libraryManager.GetItemById(parentId); } var query = new InternalItemsQuery(user) { ExcludeItemTypes = RequestHelpers.Split(excludeItemTypes, ',', true), IncludeItemTypes = RequestHelpers.Split(includeItemTypes, ',', true), MediaTypes = RequestHelpers.Split(mediaTypes, ',', true), 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(y => Convert.ToInt32(y, CultureInfo.InvariantCulture)).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 = new QueryResult <(BaseItem, ItemCounts)>(); var dtos = result.Items.Select(i => { var(baseItem, counts) = i; var dto = _dtoService.GetItemByNameDto(baseItem, dtoOptions, null, user); if (!string.IsNullOrWhiteSpace(includeItemTypes)) { dto.ChildCount = counts.ItemCount; dto.ProgramCount = counts.ProgramCount; dto.SeriesCount = counts.SeriesCount; dto.EpisodeCount = counts.EpisodeCount; dto.MovieCount = counts.MovieCount; dto.TrailerCount = counts.TrailerCount; dto.AlbumCount = counts.AlbumCount; dto.SongCount = counts.SongCount; dto.ArtistCount = counts.ArtistCount; } return(dto); }); return(new QueryResult <BaseItemDto> { Items = dtos.ToArray(), TotalRecordCount = result.TotalRecordCount }); }
private QueryResult <BaseItemDto> GetSimilarItemsResult( BaseItem item, string?excludeArtistIds, Guid?userId, int?limit, string?fields, string[] includeItemTypes, bool isMovie) { var user = userId.HasValue && !userId.Equals(Guid.Empty) ? _userManager.GetUserById(userId.Value) : null; var dtoOptions = new DtoOptions() .AddItemFields(fields) .AddClientFields(Request); var query = new InternalItemsQuery(user) { Limit = limit, IncludeItemTypes = includeItemTypes, IsMovie = isMovie, SimilarTo = item, DtoOptions = dtoOptions, EnableTotalRecordCount = !isMovie, EnableGroupByMetadataKey = isMovie }; // ExcludeArtistIds if (!string.IsNullOrEmpty(excludeArtistIds)) { query.ExcludeArtistIds = RequestHelpers.GetGuids(excludeArtistIds); } List <BaseItem> itemsResult; if (isMovie) { var itemTypes = new List <string> { nameof(MediaBrowser.Controller.Entities.Movies.Movie) }; if (_serverConfigurationManager.Configuration.EnableExternalContentInSuggestions) { itemTypes.Add(nameof(Trailer)); itemTypes.Add(nameof(LiveTvProgram)); } query.IncludeItemTypes = itemTypes.ToArray(); itemsResult = _libraryManager.GetArtists(query).Items.Select(i => i.Item1).ToList(); } else if (item is MusicArtist) { query.IncludeItemTypes = Array.Empty <string>(); itemsResult = _libraryManager.GetArtists(query).Items.Select(i => i.Item1).ToList(); } else { itemsResult = _libraryManager.GetItemList(query); } var returnList = _dtoService.GetBaseItemDtos(itemsResult, dtoOptions, user); var result = new QueryResult <BaseItemDto> { Items = returnList, TotalRecordCount = itemsResult.Count }; return(result); }
public async Task <ActionResult> AddToCollection([FromRoute, Required] Guid collectionId, [FromQuery, Required] string itemIds) { await _collectionManager.AddToCollectionAsync(collectionId, RequestHelpers.GetGuids(itemIds)).ConfigureAwait(true); return(NoContent()); }
public async Task <ActionResult> RemoveFromCollection([FromRoute, Required] Guid collectionId, [FromQuery, Required] string ids) { await _collectionManager.RemoveFromCollectionAsync(collectionId, RequestHelpers.GetGuids(ids)).ConfigureAwait(false); return(NoContent()); }
public ActionResult <QueryResult <BaseItemDto> > GetItems( [FromRoute, Required] Guid?uId, [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?includeItemTypes, [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) { // use user id route parameter over query parameter userId = uId ?? userId; var user = userId.HasValue && !userId.Equals(Guid.Empty) ? _userManager.GetUserById(userId.Value) : null; var dtoOptions = new DtoOptions() .AddItemFields(fields) .AddClientFields(Request) .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes); if (string.Equals(includeItemTypes, "Playlist", StringComparison.OrdinalIgnoreCase) || string.Equals(includeItemTypes, "BoxSet", StringComparison.OrdinalIgnoreCase)) { parentId = null; } BaseItem?item = null; QueryResult <BaseItem> result; if (!string.IsNullOrEmpty(parentId)) { item = _libraryManager.GetItemById(parentId); } item ??= _libraryManager.GetUserRootFolder(); if (!(item is Folder folder)) { folder = _libraryManager.GetUserRootFolder(); } if (folder is IHasCollectionType hasCollectionType && string.Equals(hasCollectionType.CollectionType, CollectionType.Playlists, StringComparison.OrdinalIgnoreCase)) { recursive = true; 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) // Assume all items inside an EnabledChannel are enabled || user.GetPreference(PreferenceKind.EnabledChannels).Any(i => new Guid(i) == item.ChannelId); 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(Unauthorized($"{user.Username} is not permitted to access Library {item.Name}.")); } if ((recursive.HasValue && recursive.Value) || !string.IsNullOrEmpty(ids) || !(item is UserRootFolder)) { var query = new InternalItemsQuery(user !) { IsPlayed = isPlayed, MediaTypes = RequestHelpers.Split(mediaTypes, ',', true), IncludeItemTypes = RequestHelpers.Split(includeItemTypes, ',', true), ExcludeItemTypes = RequestHelpers.Split(excludeItemTypes, ',', true), Recursive = recursive ?? false, OrderBy = RequestHelpers.GetOrderBy(sortBy, sortOrder), IsFavorite = isFavorite, Limit = limit, StartIndex = startIndex, IsMissing = isMissing, IsUnaired = isUnaired, CollapseBoxSetItems = collapseBoxSetItems, NameLessThan = nameLessThan, NameStartsWith = nameStartsWith, NameStartsWithOrGreater = nameStartsWithOrGreater, HasImdbId = hasImdbId, IsPlaceHolder = isPlaceHolder, IsLocked = isLocked, MinWidth = minWidth, MinHeight = minHeight, MaxWidth = maxWidth, MaxHeight = maxHeight, Is3D = is3D, HasTvdbId = hasTvdbId, HasTmdbId = hasTmdbId, HasOverview = hasOverview, HasOfficialRating = hasOfficialRating, HasParentalRating = hasParentalRating, HasSpecialFeature = hasSpecialFeature, HasSubtitles = hasSubtitles, HasThemeSong = hasThemeSong, HasThemeVideo = hasThemeVideo, HasTrailer = hasTrailer, IsHD = isHd, Is4K = is4K, Tags = RequestHelpers.Split(tags, '|', true), OfficialRatings = RequestHelpers.Split(officialRatings, '|', true), Genres = RequestHelpers.Split(genres, '|', true), ArtistIds = RequestHelpers.GetGuids(artistIds), AlbumArtistIds = RequestHelpers.GetGuids(albumArtistIds), ContributingArtistIds = RequestHelpers.GetGuids(contributingArtistIds), 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(), ImageTypes = RequestHelpers.Split(imageTypes, ',', true).Select(v => Enum.Parse <ImageType>(v, true)).ToArray(), VideoTypes = RequestHelpers.Split(videoTypes, ',', true).Select(v => Enum.Parse <VideoType>(v, true)).ToArray(), AdjacentTo = adjacentTo, ItemIds = RequestHelpers.GetGuids(ids), MinCommunityRating = minCommunityRating, MinCriticRating = minCriticRating, ParentId = string.IsNullOrWhiteSpace(parentId) ? Guid.Empty : new Guid(parentId), ParentIndexNumber = parentIndexNumber, EnableTotalRecordCount = enableTotalRecordCount, ExcludeItemIds = RequestHelpers.GetGuids(excludeItemIds), DtoOptions = dtoOptions, SearchTerm = searchTerm, MinDateLastSaved = minDateLastSaved?.ToUniversalTime(), MinDateLastSavedForUser = minDateLastSavedForUser?.ToUniversalTime(), MinPremiereDate = minPremiereDate?.ToUniversalTime(), MaxPremiereDate = maxPremiereDate?.ToUniversalTime(), }; if (!string.IsNullOrWhiteSpace(ids) || !string.IsNullOrWhiteSpace(searchTerm)) { query.CollapseBoxSetItems = false; } 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; } } // Filter by Series Status if (!string.IsNullOrEmpty(seriesStatus)) { query.SeriesStatuses = seriesStatus.Split(',').Select(d => (SeriesStatus)Enum.Parse(typeof(SeriesStatus), d, true)).ToArray(); } // ExcludeLocationTypes if (!string.IsNullOrEmpty(excludeLocationTypes)) { if (excludeLocationTypes.Split(',').Select(d => (LocationType)Enum.Parse(typeof(LocationType), d, true)).ToArray().Contains(LocationType.Virtual)) { query.IsVirtualItem = false; } } if (!string.IsNullOrEmpty(locationTypes)) { var requestedLocationTypes = locationTypes.Split(','); if (requestedLocationTypes.Length > 0 && requestedLocationTypes.Length < 4) { query.IsVirtualItem = requestedLocationTypes.Contains(LocationType.Virtual.ToString()); } } // Min official rating if (!string.IsNullOrWhiteSpace(minOfficialRating)) { query.MinParentalRating = _localization.GetRatingLevel(minOfficialRating); } // Max official rating if (!string.IsNullOrWhiteSpace(maxOfficialRating)) { query.MaxParentalRating = _localization.GetRatingLevel(maxOfficialRating); } // Artists if (!string.IsNullOrEmpty(artists)) { query.ArtistIds = 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(excludeArtistIds)) { query.ExcludeArtistIds = RequestHelpers.GetGuids(excludeArtistIds); } if (!string.IsNullOrWhiteSpace(albumIds)) { query.AlbumIds = RequestHelpers.GetGuids(albumIds); } // Albums if (!string.IsNullOrEmpty(albums)) { query.AlbumIds = albums.Split('|').SelectMany(i => { return(_libraryManager.GetItemIds(new InternalItemsQuery { IncludeItemTypes = new[] { nameof(MusicAlbum) }, Name = i, Limit = 1 })); }).ToArray(); } // 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(); } // 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) }; } } result = folder.GetItems(query); } else { var itemsArray = folder.GetChildren(user, true); result = new QueryResult <BaseItem> { Items = itemsArray, TotalRecordCount = itemsArray.Count, StartIndex = 0 }; } return(new QueryResult <BaseItemDto> { StartIndex = startIndex.GetValueOrDefault(), TotalRecordCount = result.TotalRecordCount, Items = _dtoService.GetBaseItemDtos(result.Items, dtoOptions, user) }); }
public ActionResult <QueryResult <BaseItemDto> > GetSimilarItems( [FromRoute, Required] Guid itemId, [FromQuery] string?excludeArtistIds, [FromQuery] Guid?userId, [FromQuery] int?limit, [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields[] fields) { var item = itemId.Equals(Guid.Empty) ? (!userId.Equals(Guid.Empty) ? _libraryManager.GetUserRootFolder() : _libraryManager.RootFolder) : _libraryManager.GetItemById(itemId); if (item is Episode || (item is IItemByName && !(item is MusicArtist))) { return(new QueryResult <BaseItemDto>()); } var user = userId.HasValue && !userId.Equals(Guid.Empty) ? _userManager.GetUserById(userId.Value) : null; var dtoOptions = new DtoOptions { Fields = fields } .AddClientFields(Request); var program = item as IHasProgramAttributes; bool?isMovie = item is Movie || (program != null && program.IsMovie) || item is Trailer; bool?isSeries = item is Series || (program != null && program.IsSeries); var includeItemTypes = new List <string>(); if (isMovie.Value) { includeItemTypes.Add(nameof(Movie)); if (_serverConfigurationManager.Configuration.EnableExternalContentInSuggestions) { includeItemTypes.Add(nameof(Trailer)); includeItemTypes.Add(nameof(LiveTvProgram)); } } else if (isSeries.Value) { includeItemTypes.Add(nameof(Series)); } else { // For non series and movie types these columns are typically null isSeries = null; isMovie = null; includeItemTypes.Add(item.GetType().Name); } var query = new InternalItemsQuery(user) { Limit = limit, IncludeItemTypes = includeItemTypes.ToArray(), IsMovie = isMovie, IsSeries = isSeries, SimilarTo = item, DtoOptions = dtoOptions, EnableTotalRecordCount = !isMovie ?? true, EnableGroupByMetadataKey = isMovie ?? false, MinSimilarityScore = 2 // A remnant from album/artist scoring }; // ExcludeArtistIds if (!string.IsNullOrEmpty(excludeArtistIds)) { query.ExcludeArtistIds = RequestHelpers.GetGuids(excludeArtistIds); } List <BaseItem> itemsResult = _libraryManager.GetItemList(query); var returnList = _dtoService.GetBaseItemDtos(itemsResult, dtoOptions, user); return(new QueryResult <BaseItemDto> { Items = returnList, TotalRecordCount = itemsResult.Count }); }