private ThemeMediaResult GetThemeSongs(GetThemeSongs request) { var user = request.UserId.HasValue ? _userManager.GetUserById(request.UserId.Value) : null; var item = string.IsNullOrEmpty(request.Id) ? (request.UserId.HasValue ? user.RootFolder : (Folder)_libraryManager.RootFolder) : _dtoService.GetItemByDtoId(request.Id, request.UserId); while (item.ThemeSongIds.Count == 0 && request.InheritFromParent && item.Parent != null) { item = item.Parent; } // Get everything var fields = Enum.GetNames(typeof(ItemFields)) .Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)) .ToList(); var dtos = item.ThemeSongIds.Select(_libraryManager.GetItemById) .OrderBy(i => i.SortName) .Select(i => _dtoService.GetBaseItemDto(i, fields, user, item)); var items = dtos.ToArray(); return(new ThemeMediaResult { Items = items, TotalRecordCount = items.Length, OwnerId = _dtoService.GetDtoId(item) }); }
private ThemeMediaResult GetThemeSongs(GetThemeSongs request) { var user = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null; var item = string.IsNullOrEmpty(request.Id) ? (!string.IsNullOrWhiteSpace(request.UserId) ? user.RootFolder : (Folder)_libraryManager.RootFolder) : _libraryManager.GetItemById(request.Id); while (GetThemeSongIds(item).Count == 0 && request.InheritFromParent && item.GetParent() != null) { item = item.GetParent(); } var dtoOptions = GetDtoOptions(request); var dtos = GetThemeSongIds(item).Select(_libraryManager.GetItemById) .OrderBy(i => i.SortName) .Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, item)); var items = dtos.ToArray(); return(new ThemeMediaResult { Items = items, TotalRecordCount = items.Length, OwnerId = _dtoService.GetDtoId(item) }); }
private ThemeMediaResult GetThemeSongs(GetThemeSongs request) { var user = request.UserId.HasValue ? _userManager.GetUserById(request.UserId.Value) : null; var item = string.IsNullOrEmpty(request.Id) ? (request.UserId.HasValue ? user.RootFolder : (Folder)_libraryManager.RootFolder) : _dtoService.GetItemByDtoId(request.Id, request.UserId); var originalItem = item; while (GetThemeSongIds(item).Count == 0 && request.InheritFromParent && item.Parent != null) { item = item.Parent; } // Get everything var fields = Enum.GetNames(typeof(ItemFields)) .Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)) .ToList(); var themeSongIds = GetThemeSongIds(item); if (themeSongIds.Count == 0 && request.InheritFromParent) { var album = originalItem as MusicAlbum; if (album != null) { var linkedItemWithThemes = album.SoundtrackIds .Select(i => _libraryManager.GetItemById(i)) .FirstOrDefault(i => GetThemeSongIds(i).Count > 0); if (linkedItemWithThemes != null) { themeSongIds = GetThemeSongIds(linkedItemWithThemes); item = linkedItemWithThemes; } } } var dtos = themeSongIds.Select(_libraryManager.GetItemById) .OrderBy(i => i.SortName) .Select(i => _dtoService.GetBaseItemDto(i, fields, user, item)); var items = dtos.ToArray(); return(new ThemeMediaResult { Items = items, TotalRecordCount = items.Length, OwnerId = _dtoService.GetDtoId(item) }); }
private ItemStub GetItemStub(BaseItem item, ImageType imageType) { var stub = new ItemStub { Id = _dtoService.GetDtoId(item), Name = item.Name, ImageType = imageType }; try { var tag = _imageProcessor.GetImageCacheTag(item, imageType); if (tag != null) { stub.ImageTag = tag; } } catch (Exception ex) { _logger.ErrorException("Error getting image tag for {0}", ex, item.Path); return(null); } return(stub); }
private ThemeMediaResult GetThemeSongs(GetThemeSongs request) { var user = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null; var item = string.IsNullOrEmpty(request.Id) ? (!string.IsNullOrWhiteSpace(request.UserId) ? _libraryManager.GetUserRootFolder() : (Folder)_libraryManager.RootFolder) : _libraryManager.GetItemById(request.Id); if (item == null) { throw new ResourceNotFoundException("Item not found."); } if (request.InheritFromParent) { while (item.ThemeSongIds.Length == 0) { var parent = item.GetParent(); if (parent == null) { break; } item = parent; } } var dtoOptions = GetDtoOptions(_authContext, request); var dtos = item.ThemeSongIds.Select(_libraryManager.GetItemById) .Where(i => i != null) .OrderBy(i => i.SortName) .Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, item)); var items = dtos.ToArray(); return(new ThemeMediaResult { Items = items, TotalRecordCount = items.Length, OwnerId = _dtoService.GetDtoId(item) }); }
private ItemStub GetItemStub(BaseItem item, ImageType imageType) { var stub = new ItemStub { Id = _dtoService.GetDtoId(item), Name = item.Name }; var imageManager = Kernel.Instance.ImageManager; try { var imagePath = imageManager.GetImagePath(item, imageType, 0); stub.ImageTag = imageManager.GetImageCacheTag(item, imageType, imagePath); } catch (Exception ex) { _logger.ErrorException("Error getting image tag for {0}", ex, item.Path); return(null); } return(stub); }
/// <summary> /// Gets the search hint result. /// </summary> /// <param name="hintInfo">The hint info.</param> /// <returns>SearchHintResult.</returns> private SearchHint GetSearchHintResult(SearchHintInfo hintInfo) { var item = hintInfo.Item; var result = new SearchHint { Name = item.Name, IndexNumber = item.IndexNumber, ParentIndexNumber = item.ParentIndexNumber, ItemId = _dtoService.GetDtoId(item), Type = item.GetClientTypeName(), MediaType = item.MediaType, MatchedTerm = hintInfo.MatchedTerm, DisplayMediaType = item.DisplayMediaType, RunTimeTicks = item.RunTimeTicks, ProductionYear = item.ProductionYear }; var primaryImageTag = _imageProcessor.GetImageCacheTag(item, ImageType.Primary); if (primaryImageTag.HasValue) { result.PrimaryImageTag = primaryImageTag.Value; } SetThumbImageInfo(result, item); SetBackdropImageInfo(result, item); var episode = item as Episode; if (episode != null) { result.Series = episode.Series.Name; } var season = item as Season; if (season != null) { result.Series = season.Series.Name; result.EpisodeCount = season.GetRecursiveChildren(i => i is Episode).Count; } var series = item as Series; if (series != null) { result.EpisodeCount = series.GetRecursiveChildren(i => i is Episode).Count; } var album = item as MusicAlbum; if (album != null) { var songs = album.GetRecursiveChildren().OfType <Audio>().ToList(); result.SongCount = songs.Count; result.Artists = songs.SelectMany(i => i.AllArtists) .Distinct(StringComparer.OrdinalIgnoreCase) .ToArray(); result.AlbumArtist = songs.Select(i => i.AlbumArtist).FirstOrDefault(i => !string.IsNullOrEmpty(i)); } var song = item as Audio; if (song != null) { result.Album = song.Album; result.AlbumArtist = song.AlbumArtist; result.Artists = song.Artists.ToArray(); } return(result); }
private string GetDtoId(BaseItem item) { return(_dtoService.GetDtoId(item)); }
/// <summary> /// Gets the search hint result. /// </summary> /// <param name="hintInfo">The hint info.</param> /// <returns>SearchHintResult.</returns> private SearchHint GetSearchHintResult(SearchHintInfo hintInfo) { var item = hintInfo.Item; var result = new SearchHint { Name = item.Name, IndexNumber = item.IndexNumber, ParentIndexNumber = item.ParentIndexNumber, ItemId = _dtoService.GetDtoId(item), Type = item.GetClientTypeName(), MediaType = item.MediaType, MatchedTerm = hintInfo.MatchedTerm, DisplayMediaType = item.DisplayMediaType, RunTimeTicks = item.RunTimeTicks, ProductionYear = item.ProductionYear }; result.ChannelId = item.ChannelId; var primaryImageTag = _imageProcessor.GetImageCacheTag(item, ImageType.Primary); if (primaryImageTag != null) { result.PrimaryImageTag = primaryImageTag; result.PrimaryImageAspectRatio = _dtoService.GetPrimaryImageAspectRatio(item); } SetThumbImageInfo(result, item); SetBackdropImageInfo(result, item); var hasSeries = item as IHasSeries; if (hasSeries != null) { result.Series = hasSeries.SeriesName; } var season = item as Season; if (season != null) { result.EpisodeCount = season.GetRecursiveChildren(i => i is Episode).Count; } var series = item as Series; if (series != null) { result.EpisodeCount = series.GetRecursiveChildren(i => i is Episode).Count; } var album = item as MusicAlbum; if (album != null) { result.SongCount = album.Tracks.Count(); result.Artists = album.Artists.ToArray(); result.AlbumArtist = album.AlbumArtist; } var song = item as Audio; if (song != null) { result.Album = song.Album; result.AlbumArtist = song.AlbumArtists.FirstOrDefault(); result.Artists = song.Artists.ToArray(); } if (!string.IsNullOrWhiteSpace(item.ChannelId)) { var channel = _libraryManager.GetItemById(item.ChannelId); result.ChannelName = channel == null ? null : channel.Name; } return(result); }
/// <summary> /// Gets the search hint result. /// </summary> /// <param name="hintInfo">The hint info.</param> /// <returns>SearchHintResult.</returns> private SearchHint GetSearchHintResult(SearchHintInfo hintInfo) { var item = hintInfo.Item; var result = new SearchHint { Name = item.Name, IndexNumber = item.IndexNumber, ParentIndexNumber = item.ParentIndexNumber, ItemId = _dtoService.GetDtoId(item), Type = item.GetClientTypeName(), MediaType = item.MediaType, MatchedTerm = hintInfo.MatchedTerm, RunTimeTicks = item.RunTimeTicks, ProductionYear = item.ProductionYear, ChannelId = item.ChannelId, EndDate = item.EndDate }; var primaryImageTag = _imageProcessor.GetImageCacheTag(item, ImageType.Primary); if (primaryImageTag != null) { result.PrimaryImageTag = primaryImageTag; result.PrimaryImageAspectRatio = _dtoService.GetPrimaryImageAspectRatio(item); } SetThumbImageInfo(result, item); SetBackdropImageInfo(result, item); var program = item as LiveTvProgram; if (program != null) { result.StartDate = program.StartDate; } var hasSeries = item as IHasSeries; if (hasSeries != null) { result.Series = hasSeries.SeriesName; } var series = item as Series; if (series != null) { if (series.Status.HasValue) { result.Status = series.Status.Value.ToString(); } } var album = item as MusicAlbum; if (album != null) { result.Artists = album.Artists; result.AlbumArtist = album.AlbumArtist; } var song = item as Audio; if (song != null) { result.Album = song.Album; result.AlbumArtist = song.AlbumArtists.FirstOrDefault(); result.Artists = song.Artists; } if (!string.IsNullOrWhiteSpace(item.ChannelId)) { var channel = _libraryManager.GetItemById(item.ChannelId); result.ChannelName = channel == null ? null : channel.Name; } return(result); }
/// <summary> /// Gets the search hint result. /// </summary> /// <param name="hintInfo">The hint info.</param> /// <returns>SearchHintResult.</returns> private SearchHint GetSearchHintResult(SearchHintInfo hintInfo) { var item = hintInfo.Item; var result = new SearchHint { Name = item.Name, IndexNumber = item.IndexNumber, ParentIndexNumber = item.ParentIndexNumber, ItemId = _dtoService.GetDtoId(item), Type = item.GetType().Name, MediaType = item.MediaType, MatchedTerm = hintInfo.MatchedTerm, DisplayMediaType = item.DisplayMediaType, RunTimeTicks = item.RunTimeTicks }; if (item.HasImage(ImageType.Primary)) { result.PrimaryImageTag = Kernel.Instance.ImageManager.GetImageCacheTag(item, ImageType.Primary, item.GetImage(ImageType.Primary)); } var episode = item as Episode; if (episode != null) { result.Series = episode.Series.Name; } var season = item as Season; if (season != null) { result.Series = season.Series.Name; result.EpisodeCount = season.RecursiveChildren.OfType <Episode>().Count(); } var series = item as Series; if (series != null) { result.EpisodeCount = series.RecursiveChildren.OfType <Episode>().Count(); } var album = item as MusicAlbum; if (album != null) { var songs = album.RecursiveChildren.OfType <Audio>().ToList(); result.SongCount = songs.Count; result.Artists = songs .SelectMany(i => i.Artists) .Distinct(StringComparer.OrdinalIgnoreCase) .ToArray(); result.AlbumArtist = songs.Select(i => i.AlbumArtist).FirstOrDefault(i => !string.IsNullOrEmpty(i)); } var song = item as Audio; if (song != null) { result.Album = song.Album; result.AlbumArtist = song.AlbumArtist; result.Artists = song.Artists.ToArray(); } return(result); }