/// <summary> /// Gets the value. /// </summary> /// <param name="x">The x.</param> /// <returns>System.String.</returns> private DateTime GetValue(BaseItem x) { var series = (x as Series) ?? x.FindParent<Series>(); DateTime result; if (series != null && DateTime.TryParse(series.AirTime, out result)) { return result; } return DateTime.MinValue; }
/// <summary> /// Gets the value. /// </summary> /// <param name="x">The x.</param> /// <returns>System.String.</returns> private DateTime GetValue(BaseItem x) { var series = (x as Series) ?? x.FindParent <Series>(); DateTime result; if (series != null && DateTime.TryParse(series.AirTime, out result)) { return(result); } return(DateTime.MinValue); }
/// <summary> /// Sets simple property values on a DTOBaseItem /// </summary> /// <param name="dto">The dto.</param> /// <param name="item">The item.</param> /// <param name="owner">The owner.</param> /// <param name="fields">The fields.</param> private void AttachBasicFields(BaseItemDto dto, BaseItem item, BaseItem owner, List<ItemFields> fields) { if (fields.Contains(ItemFields.DateCreated)) { dto.DateCreated = item.DateCreated; } if (fields.Contains(ItemFields.OriginalRunTimeTicks)) { dto.OriginalRunTimeTicks = item.OriginalRunTimeTicks; } dto.DisplayMediaType = item.DisplayMediaType; if (fields.Contains(ItemFields.MetadataSettings)) { dto.LockedFields = item.LockedFields; dto.EnableInternetProviders = !item.DontFetchMeta; } if (fields.Contains(ItemFields.Budget)) { dto.Budget = item.Budget; } if (fields.Contains(ItemFields.Revenue)) { dto.Revenue = item.Revenue; } dto.EndDate = item.EndDate; if (fields.Contains(ItemFields.HomePageUrl)) { dto.HomePageUrl = item.HomePageUrl; } if (fields.Contains(ItemFields.Tags)) { dto.Tags = item.Tags; } if (fields.Contains(ItemFields.ProductionLocations)) { dto.ProductionLocations = item.ProductionLocations; } dto.AspectRatio = item.AspectRatio; dto.BackdropImageTags = GetBackdropImageTags(item); dto.ScreenshotImageTags = GetScreenshotImageTags(item); if (fields.Contains(ItemFields.Genres)) { dto.Genres = item.Genres; } dto.ImageTags = new Dictionary<ImageType, Guid>(); foreach (var image in item.Images) { var type = image.Key; var tag = GetImageCacheTag(item, type, image.Value); if (tag.HasValue) { dto.ImageTags[type] = tag.Value; } } dto.Id = GetClientItemId(item); dto.IndexNumber = item.IndexNumber; dto.IsFolder = item.IsFolder; dto.Language = item.Language; dto.MediaType = item.MediaType; dto.LocationType = item.LocationType; dto.CriticRating = item.CriticRating; if (fields.Contains(ItemFields.CriticRatingSummary)) { dto.CriticRatingSummary = item.CriticRatingSummary; } var localTrailerCount = item.LocalTrailerIds.Count; if (localTrailerCount > 0) { dto.LocalTrailerCount = localTrailerCount; } dto.Name = item.Name; dto.OfficialRating = item.OfficialRating; var hasOverview = fields.Contains(ItemFields.Overview); var hasHtmlOverview = fields.Contains(ItemFields.OverviewHtml); if (hasOverview || hasHtmlOverview) { var strippedOverview = string.IsNullOrEmpty(item.Overview) ? item.Overview : item.Overview.StripHtml(); if (hasOverview) { dto.Overview = strippedOverview; } // Only supply the html version if there was actually html content if (hasHtmlOverview) { dto.OverviewHtml = item.Overview; } } // If there are no backdrops, indicate what parent has them in case the Ui wants to allow inheritance if (dto.BackdropImageTags.Count == 0) { var parentWithBackdrop = GetParentBackdropItem(item, owner); if (parentWithBackdrop != null) { dto.ParentBackdropItemId = GetClientItemId(parentWithBackdrop); dto.ParentBackdropImageTags = GetBackdropImageTags(parentWithBackdrop); } } if (item.Parent != null && fields.Contains(ItemFields.ParentId)) { dto.ParentId = GetClientItemId(item.Parent); } dto.ParentIndexNumber = item.ParentIndexNumber; // If there is no logo, indicate what parent has one in case the Ui wants to allow inheritance if (!dto.HasLogo) { var parentWithLogo = GetParentImageItem(item, ImageType.Logo, owner); if (parentWithLogo != null) { dto.ParentLogoItemId = GetClientItemId(parentWithLogo); dto.ParentLogoImageTag = GetImageCacheTag(parentWithLogo, ImageType.Logo, parentWithLogo.GetImage(ImageType.Logo)); } } // If there is no art, indicate what parent has one in case the Ui wants to allow inheritance if (!dto.HasArtImage) { var parentWithImage = GetParentImageItem(item, ImageType.Art, owner); if (parentWithImage != null) { dto.ParentArtItemId = GetClientItemId(parentWithImage); dto.ParentArtImageTag = GetImageCacheTag(parentWithImage, ImageType.Art, parentWithImage.GetImage(ImageType.Art)); } } if (fields.Contains(ItemFields.Path)) { dto.Path = item.Path; } dto.PremiereDate = item.PremiereDate; dto.ProductionYear = item.ProductionYear; if (fields.Contains(ItemFields.ProviderIds)) { dto.ProviderIds = item.ProviderIds; } dto.RunTimeTicks = item.RunTimeTicks; if (fields.Contains(ItemFields.SortName)) { dto.SortName = item.SortName; } if (fields.Contains(ItemFields.CustomRating)) { dto.CustomRating = item.CustomRating; } if (fields.Contains(ItemFields.Taglines)) { dto.Taglines = item.Taglines; } if (fields.Contains(ItemFields.RemoteTrailers)) { dto.RemoteTrailers = item.RemoteTrailers; } dto.Type = item.GetType().Name; dto.CommunityRating = item.CommunityRating; if (item.IsFolder) { var folder = (Folder)item; if (fields.Contains(ItemFields.IndexOptions)) { dto.IndexOptions = folder.IndexByOptionStrings.ToArray(); } } // Add audio info var audio = item as Audio; if (audio != null) { dto.Album = audio.Album; dto.AlbumArtist = audio.AlbumArtist; dto.Artists = new[] { audio.Artist }; var albumParent = audio.FindParent<MusicAlbum>(); if (albumParent != null) { dto.AlbumId = GetClientItemId(albumParent); var imagePath = albumParent.PrimaryImagePath; if (!string.IsNullOrEmpty(imagePath)) { dto.AlbumPrimaryImageTag = GetImageCacheTag(albumParent, ImageType.Primary, imagePath); } } } var album = item as MusicAlbum; if (album != null) { var songs = album.RecursiveChildren.OfType<Audio>().ToList(); dto.AlbumArtist = songs.Select(i => i.AlbumArtist).FirstOrDefault(i => !string.IsNullOrEmpty(i)); dto.Artists = songs.Select(i => i.Artist ?? string.Empty) .Where(i => !string.IsNullOrEmpty(i)) .Distinct(StringComparer.OrdinalIgnoreCase) .ToArray(); } // Add video info var video = item as Video; if (video != null) { dto.VideoType = video.VideoType; dto.Video3DFormat = video.Video3DFormat; dto.IsoType = video.IsoType; dto.PartCount = video.AdditionalPartIds.Count + 1; if (fields.Contains(ItemFields.Chapters)) { dto.Chapters = _itemRepo.GetChapters(video.Id).Select(c => GetChapterInfoDto(c, item)).ToList(); } } if (fields.Contains(ItemFields.MediaStreams)) { // Add VideoInfo var iHasMediaStreams = item as IHasMediaStreams; if (iHasMediaStreams != null) { dto.MediaStreams = iHasMediaStreams.MediaStreams; } } // Add MovieInfo var movie = item as Movie; if (movie != null) { var specialFeatureCount = movie.SpecialFeatureIds.Count; if (specialFeatureCount > 0) { dto.SpecialFeatureCount = specialFeatureCount; } } // Add EpisodeInfo var episode = item as Episode; if (episode != null) { dto.IndexNumberEnd = episode.IndexNumberEnd; } // Add SeriesInfo var series = item as Series; if (series != null) { dto.AirDays = series.AirDays; dto.AirTime = series.AirTime; dto.Status = series.Status; } if (episode != null) { series = item.FindParent<Series>(); dto.SeriesId = GetClientItemId(series); dto.SeriesName = series.Name; } // Add SeasonInfo var season = item as Season; if (season != null) { series = item.FindParent<Series>(); dto.SeriesId = GetClientItemId(series); dto.SeriesName = series.Name; } var game = item as Game; if (game != null) { SetGameProperties(dto, game); } var musicVideo = item as MusicVideo; if (musicVideo != null) { SetMusicVideoProperties(dto, musicVideo); } }
/// <summary> /// Sets simple property values on a DTOBaseItem /// </summary> /// <param name="dto">The dto.</param> /// <param name="item">The item.</param> /// <param name="owner">The owner.</param> /// <param name="fields">The fields.</param> private void AttachBasicFields(BaseItemDto dto, BaseItem item, BaseItem owner, List <ItemFields> fields) { if (fields.Contains(ItemFields.DateCreated)) { dto.DateCreated = item.DateCreated; } if (fields.Contains(ItemFields.OriginalRunTimeTicks)) { dto.OriginalRunTimeTicks = item.OriginalRunTimeTicks; } dto.DisplayMediaType = item.DisplayMediaType; if (fields.Contains(ItemFields.MetadataSettings)) { dto.LockedFields = item.LockedFields; dto.EnableInternetProviders = !item.DontFetchMeta; } if (fields.Contains(ItemFields.Budget)) { dto.Budget = item.Budget; } if (fields.Contains(ItemFields.Revenue)) { dto.Revenue = item.Revenue; } dto.EndDate = item.EndDate; if (fields.Contains(ItemFields.HomePageUrl)) { dto.HomePageUrl = item.HomePageUrl; } if (fields.Contains(ItemFields.Tags)) { dto.Tags = item.Tags; } if (fields.Contains(ItemFields.ProductionLocations)) { dto.ProductionLocations = item.ProductionLocations; } dto.AspectRatio = item.AspectRatio; dto.BackdropImageTags = GetBackdropImageTags(item); dto.ScreenshotImageTags = GetScreenshotImageTags(item); if (fields.Contains(ItemFields.Genres)) { dto.Genres = item.Genres; } dto.ImageTags = new Dictionary <ImageType, Guid>(); foreach (var image in item.Images) { var type = image.Key; var tag = GetImageCacheTag(item, type, image.Value); if (tag.HasValue) { dto.ImageTags[type] = tag.Value; } } dto.Id = GetClientItemId(item); dto.IndexNumber = item.IndexNumber; dto.IsFolder = item.IsFolder; dto.Language = item.Language; dto.MediaType = item.MediaType; dto.LocationType = item.LocationType; dto.CriticRating = item.CriticRating; if (fields.Contains(ItemFields.CriticRatingSummary)) { dto.CriticRatingSummary = item.CriticRatingSummary; } var localTrailerCount = item.LocalTrailerIds.Count; if (localTrailerCount > 0) { dto.LocalTrailerCount = localTrailerCount; } dto.Name = item.Name; dto.OfficialRating = item.OfficialRating; var hasOverview = fields.Contains(ItemFields.Overview); var hasHtmlOverview = fields.Contains(ItemFields.OverviewHtml); if (hasOverview || hasHtmlOverview) { var strippedOverview = string.IsNullOrEmpty(item.Overview) ? item.Overview : item.Overview.StripHtml(); if (hasOverview) { dto.Overview = strippedOverview; } // Only supply the html version if there was actually html content if (hasHtmlOverview) { dto.OverviewHtml = item.Overview; } } // If there are no backdrops, indicate what parent has them in case the Ui wants to allow inheritance if (dto.BackdropImageTags.Count == 0) { var parentWithBackdrop = GetParentBackdropItem(item, owner); if (parentWithBackdrop != null) { dto.ParentBackdropItemId = GetClientItemId(parentWithBackdrop); dto.ParentBackdropImageTags = GetBackdropImageTags(parentWithBackdrop); } } if (item.Parent != null && fields.Contains(ItemFields.ParentId)) { dto.ParentId = GetClientItemId(item.Parent); } dto.ParentIndexNumber = item.ParentIndexNumber; // If there is no logo, indicate what parent has one in case the Ui wants to allow inheritance if (!dto.HasLogo) { var parentWithLogo = GetParentImageItem(item, ImageType.Logo, owner); if (parentWithLogo != null) { dto.ParentLogoItemId = GetClientItemId(parentWithLogo); dto.ParentLogoImageTag = GetImageCacheTag(parentWithLogo, ImageType.Logo, parentWithLogo.GetImage(ImageType.Logo)); } } // If there is no art, indicate what parent has one in case the Ui wants to allow inheritance if (!dto.HasArtImage) { var parentWithImage = GetParentImageItem(item, ImageType.Art, owner); if (parentWithImage != null) { dto.ParentArtItemId = GetClientItemId(parentWithImage); dto.ParentArtImageTag = GetImageCacheTag(parentWithImage, ImageType.Art, parentWithImage.GetImage(ImageType.Art)); } } if (fields.Contains(ItemFields.Path)) { dto.Path = item.Path; } dto.PremiereDate = item.PremiereDate; dto.ProductionYear = item.ProductionYear; if (fields.Contains(ItemFields.ProviderIds)) { dto.ProviderIds = item.ProviderIds; } dto.RunTimeTicks = item.RunTimeTicks; if (fields.Contains(ItemFields.SortName)) { dto.SortName = item.SortName; } if (fields.Contains(ItemFields.CustomRating)) { dto.CustomRating = item.CustomRating; } if (fields.Contains(ItemFields.Taglines)) { dto.Taglines = item.Taglines; } if (fields.Contains(ItemFields.RemoteTrailers)) { dto.RemoteTrailers = item.RemoteTrailers; } dto.Type = item.GetType().Name; dto.CommunityRating = item.CommunityRating; if (item.IsFolder) { var folder = (Folder)item; if (fields.Contains(ItemFields.IndexOptions)) { dto.IndexOptions = folder.IndexByOptionStrings.ToArray(); } } // Add audio info var audio = item as Audio; if (audio != null) { dto.Album = audio.Album; dto.AlbumArtist = audio.AlbumArtist; dto.Artists = new[] { audio.Artist }; var albumParent = audio.FindParent <MusicAlbum>(); if (albumParent != null) { dto.AlbumId = GetClientItemId(albumParent); var imagePath = albumParent.PrimaryImagePath; if (!string.IsNullOrEmpty(imagePath)) { dto.AlbumPrimaryImageTag = GetImageCacheTag(albumParent, ImageType.Primary, imagePath); } } } var album = item as MusicAlbum; if (album != null) { var songs = album.RecursiveChildren.OfType <Audio>().ToList(); dto.AlbumArtist = songs.Select(i => i.AlbumArtist).FirstOrDefault(i => !string.IsNullOrEmpty(i)); dto.Artists = songs.Select(i => i.Artist ?? string.Empty) .Where(i => !string.IsNullOrEmpty(i)) .Distinct(StringComparer.OrdinalIgnoreCase) .ToArray(); } // Add video info var video = item as Video; if (video != null) { dto.VideoType = video.VideoType; dto.Video3DFormat = video.Video3DFormat; dto.IsoType = video.IsoType; dto.PartCount = video.AdditionalPartIds.Count + 1; if (fields.Contains(ItemFields.Chapters)) { dto.Chapters = _itemRepo.GetChapters(video.Id).Select(c => GetChapterInfoDto(c, item)).ToList(); } } if (fields.Contains(ItemFields.MediaStreams)) { // Add VideoInfo var iHasMediaStreams = item as IHasMediaStreams; if (iHasMediaStreams != null) { dto.MediaStreams = iHasMediaStreams.MediaStreams; } } // Add MovieInfo var movie = item as Movie; if (movie != null) { var specialFeatureCount = movie.SpecialFeatureIds.Count; if (specialFeatureCount > 0) { dto.SpecialFeatureCount = specialFeatureCount; } } // Add EpisodeInfo var episode = item as Episode; if (episode != null) { dto.IndexNumberEnd = episode.IndexNumberEnd; } // Add SeriesInfo var series = item as Series; if (series != null) { dto.AirDays = series.AirDays; dto.AirTime = series.AirTime; dto.Status = series.Status; } if (episode != null) { series = item.FindParent <Series>(); dto.SeriesId = GetClientItemId(series); dto.SeriesName = series.Name; } // Add SeasonInfo var season = item as Season; if (season != null) { series = item.FindParent <Series>(); dto.SeriesId = GetClientItemId(series); dto.SeriesName = series.Name; } var game = item as Game; if (game != null) { SetGameProperties(dto, game); } var musicVideo = item as MusicVideo; if (musicVideo != null) { SetMusicVideoProperties(dto, musicVideo); } }
/// <summary> /// Sets simple property values on a DTOBaseItem /// </summary> /// <param name="dto">The dto.</param> /// <param name="item">The item.</param> /// <param name="owner">The owner.</param> /// <param name="fields">The fields.</param> private void AttachBasicFields(BaseItemDto dto, BaseItem item, BaseItem owner, List <ItemFields> fields) { if (fields.Contains(ItemFields.DateCreated)) { dto.DateCreated = item.DateCreated; } dto.DisplayMediaType = item.DisplayMediaType; dto.IsUnidentified = item.IsUnidentified; if (fields.Contains(ItemFields.Settings)) { dto.LockedFields = item.LockedFields; dto.LockData = item.DontFetchMeta; } var hasBudget = item as IHasBudget; if (hasBudget != null) { if (fields.Contains(ItemFields.Budget)) { dto.Budget = hasBudget.Budget; } if (fields.Contains(ItemFields.Revenue)) { dto.Revenue = hasBudget.Revenue; } } dto.EndDate = item.EndDate; if (fields.Contains(ItemFields.HomePageUrl)) { dto.HomePageUrl = item.HomePageUrl; } if (fields.Contains(ItemFields.ExternalUrls)) { dto.ExternalUrls = _providerManager.GetExternalUrls(item).ToArray(); } if (fields.Contains(ItemFields.Tags)) { var hasTags = item as IHasTags; if (hasTags != null) { dto.Tags = hasTags.Tags; } if (dto.Tags == null) { dto.Tags = new List <string>(); } } if (fields.Contains(ItemFields.Keywords)) { var hasTags = item as IHasKeywords; if (hasTags != null) { dto.Keywords = hasTags.Keywords; } if (dto.Keywords == null) { dto.Keywords = new List <string>(); } } if (fields.Contains(ItemFields.ProductionLocations)) { SetProductionLocations(item, dto); } var hasAspectRatio = item as IHasAspectRatio; if (hasAspectRatio != null) { dto.AspectRatio = hasAspectRatio.AspectRatio; } var hasMetascore = item as IHasMetascore; if (hasMetascore != null) { dto.Metascore = hasMetascore.Metascore; } if (fields.Contains(ItemFields.AwardSummary)) { var hasAwards = item as IHasAwards; if (hasAwards != null) { dto.AwardSummary = hasAwards.AwardSummary; } } dto.BackdropImageTags = GetBackdropImageTags(item); if (fields.Contains(ItemFields.ScreenshotImageTags)) { dto.ScreenshotImageTags = GetScreenshotImageTags(item); } if (fields.Contains(ItemFields.Genres)) { dto.Genres = item.Genres; } dto.ImageTags = new Dictionary <ImageType, Guid>(); // Prevent implicitly captured closure var currentItem = item; foreach (var image in currentItem.ImageInfos.Where(i => !currentItem.AllowsMultipleImages(i.Type))) { var tag = GetImageCacheTag(item, image); if (tag.HasValue) { dto.ImageTags[image.Type] = tag.Value; } } dto.Id = GetDtoId(item); dto.IndexNumber = item.IndexNumber; dto.IsFolder = item.IsFolder; dto.MediaType = item.MediaType; dto.LocationType = item.LocationType; var hasLang = item as IHasPreferredMetadataLanguage; if (hasLang != null) { dto.PreferredMetadataCountryCode = hasLang.PreferredMetadataCountryCode; dto.PreferredMetadataLanguage = hasLang.PreferredMetadataLanguage; } var hasCriticRating = item as IHasCriticRating; if (hasCriticRating != null) { dto.CriticRating = hasCriticRating.CriticRating; if (fields.Contains(ItemFields.CriticRatingSummary)) { dto.CriticRatingSummary = hasCriticRating.CriticRatingSummary; } } var hasTrailers = item as IHasTrailers; if (hasTrailers != null) { dto.LocalTrailerCount = hasTrailers.LocalTrailerIds.Count; } var hasDisplayOrder = item as IHasDisplayOrder; if (hasDisplayOrder != null) { dto.DisplayOrder = hasDisplayOrder.DisplayOrder; } var collectionFolder = item as CollectionFolder; if (collectionFolder != null) { dto.CollectionType = collectionFolder.CollectionType; } if (fields.Contains(ItemFields.RemoteTrailers)) { dto.RemoteTrailers = hasTrailers != null ? hasTrailers.RemoteTrailers : new List <MediaUrl>(); } dto.Name = item.Name; dto.OfficialRating = item.OfficialRating; var hasOverview = fields.Contains(ItemFields.Overview); var hasHtmlOverview = fields.Contains(ItemFields.OverviewHtml); if (hasOverview || hasHtmlOverview) { var strippedOverview = string.IsNullOrEmpty(item.Overview) ? item.Overview : item.Overview.StripHtml(); if (hasOverview) { dto.Overview = strippedOverview; } // Only supply the html version if there was actually html content if (hasHtmlOverview) { dto.OverviewHtml = item.Overview; } } // If there are no backdrops, indicate what parent has them in case the Ui wants to allow inheritance if (dto.BackdropImageTags.Count == 0) { var parentWithBackdrop = GetParentBackdropItem(item, owner); if (parentWithBackdrop != null) { dto.ParentBackdropItemId = GetDtoId(parentWithBackdrop); dto.ParentBackdropImageTags = GetBackdropImageTags(parentWithBackdrop); } } if (item.Parent != null && fields.Contains(ItemFields.ParentId)) { dto.ParentId = GetDtoId(item.Parent); } dto.ParentIndexNumber = item.ParentIndexNumber; // If there is no logo, indicate what parent has one in case the Ui wants to allow inheritance if (!dto.HasLogo) { var parentWithLogo = GetParentImageItem(item, ImageType.Logo, owner); if (parentWithLogo != null) { dto.ParentLogoItemId = GetDtoId(parentWithLogo); dto.ParentLogoImageTag = GetImageCacheTag(parentWithLogo, ImageType.Logo); } } // If there is no art, indicate what parent has one in case the Ui wants to allow inheritance if (!dto.HasArtImage) { var parentWithImage = GetParentImageItem(item, ImageType.Art, owner); if (parentWithImage != null) { dto.ParentArtItemId = GetDtoId(parentWithImage); dto.ParentArtImageTag = GetImageCacheTag(parentWithImage, ImageType.Art); } } // If there is no thumb, indicate what parent has one in case the Ui wants to allow inheritance if (!dto.HasThumb) { var parentWithImage = GetParentImageItem(item, ImageType.Thumb, owner); if (parentWithImage != null) { dto.ParentThumbItemId = GetDtoId(parentWithImage); dto.ParentThumbImageTag = GetImageCacheTag(parentWithImage, ImageType.Thumb); } } if (fields.Contains(ItemFields.Path)) { var locationType = item.LocationType; if (locationType != LocationType.Remote && locationType != LocationType.Virtual) { dto.Path = GetMappedPath(item.Path); } else { dto.Path = item.Path; } } dto.PremiereDate = item.PremiereDate; dto.ProductionYear = item.ProductionYear; if (fields.Contains(ItemFields.ProviderIds)) { dto.ProviderIds = item.ProviderIds; } dto.RunTimeTicks = item.RunTimeTicks; if (fields.Contains(ItemFields.SortName)) { dto.SortName = item.SortName; } if (fields.Contains(ItemFields.CustomRating)) { dto.CustomRating = item.CustomRating; } if (fields.Contains(ItemFields.Taglines)) { var hasTagline = item as IHasTaglines; if (hasTagline != null) { dto.Taglines = hasTagline.Taglines; } if (dto.Taglines == null) { dto.Taglines = new List <string>(); } } dto.Type = item.GetClientTypeName(); dto.CommunityRating = item.CommunityRating; dto.VoteCount = item.VoteCount; if (item.IsFolder) { var folder = (Folder)item; if (fields.Contains(ItemFields.IndexOptions)) { dto.IndexOptions = folder.IndexByOptionStrings.ToArray(); } } var supportsPlaceHolders = item as ISupportsPlaceHolders; if (supportsPlaceHolders != null) { dto.IsPlaceHolder = supportsPlaceHolders.IsPlaceHolder; } // Add audio info var audio = item as Audio; if (audio != null) { dto.Album = audio.Album; dto.Artists = audio.Artists; var albumParent = audio.FindParent <MusicAlbum>(); if (albumParent != null) { dto.AlbumId = GetDtoId(albumParent); dto.AlbumPrimaryImageTag = GetImageCacheTag(albumParent, ImageType.Primary); } } var album = item as MusicAlbum; if (album != null) { dto.Artists = album.Artists; dto.SoundtrackIds = album.SoundtrackIds .Select(i => i.ToString("N")) .ToArray(); } var hasAlbumArtist = item as IHasAlbumArtist; if (hasAlbumArtist != null) { dto.AlbumArtist = hasAlbumArtist.AlbumArtist; } // Add video info var video = item as Video; if (video != null) { dto.VideoType = video.VideoType; dto.Video3DFormat = video.Video3DFormat; dto.IsoType = video.IsoType; dto.IsHD = video.IsHD; dto.PartCount = video.AdditionalPartIds.Count + 1; if (fields.Contains(ItemFields.Chapters)) { dto.Chapters = _itemRepo.GetChapters(video.Id).Select(c => GetChapterInfoDto(c, item)).ToList(); } } if (fields.Contains(ItemFields.MediaStreams)) { // Add VideoInfo var iHasMediaStreams = item as IHasMediaStreams; if (iHasMediaStreams != null) { dto.MediaStreams = _itemRepo.GetMediaStreams(new MediaStreamQuery { ItemId = item.Id }).ToList(); } } // Add MovieInfo var movie = item as Movie; if (movie != null) { var specialFeatureCount = movie.SpecialFeatureIds.Count; if (specialFeatureCount > 0) { dto.SpecialFeatureCount = specialFeatureCount; } if (fields.Contains(ItemFields.TmdbCollectionName)) { dto.TmdbCollectionName = movie.TmdbCollectionName; } } // Add EpisodeInfo var episode = item as Episode; if (episode != null) { dto.IndexNumberEnd = episode.IndexNumberEnd; dto.DvdSeasonNumber = episode.DvdSeasonNumber; dto.DvdEpisodeNumber = episode.DvdEpisodeNumber; dto.AirsAfterSeasonNumber = episode.AirsAfterSeasonNumber; dto.AirsBeforeEpisodeNumber = episode.AirsBeforeEpisodeNumber; dto.AirsBeforeSeasonNumber = episode.AirsBeforeSeasonNumber; dto.AbsoluteEpisodeNumber = episode.AbsoluteEpisodeNumber; var seasonId = episode.SeasonId; if (seasonId.HasValue) { dto.SeasonId = seasonId.Value.ToString("N"); } } // Add SeriesInfo var series = item as Series; if (series != null) { dto.AirDays = series.AirDays; dto.AirTime = series.AirTime; dto.Status = series.Status; dto.SpecialFeatureCount = series.SpecialFeatureIds.Count; dto.SeasonCount = series.SeasonCount; if (fields.Contains(ItemFields.Settings)) { dto.DisplaySpecialsWithSeasons = series.DisplaySpecialsWithSeasons; } dto.AnimeSeriesIndex = series.AnimeSeriesIndex; } if (episode != null) { series = item.FindParent <Series>(); dto.SeriesId = GetDtoId(series); dto.SeriesName = series.Name; dto.AirTime = series.AirTime; dto.SeriesStudio = series.Studios.FirstOrDefault(); dto.SeriesThumbImageTag = GetImageCacheTag(series, ImageType.Thumb); dto.SeriesPrimaryImageTag = GetImageCacheTag(series, ImageType.Primary); } // Add SeasonInfo var season = item as Season; if (season != null) { series = item.FindParent <Series>(); dto.SeriesId = GetDtoId(series); dto.SeriesName = series.Name; dto.AirTime = series.AirTime; dto.SeriesStudio = series.Studios.FirstOrDefault(); dto.SeriesPrimaryImageTag = GetImageCacheTag(series, ImageType.Primary); } var game = item as Game; if (game != null) { SetGameProperties(dto, game); } var gameSystem = item as GameSystem; if (gameSystem != null) { SetGameSystemProperties(dto, gameSystem); } var musicVideo = item as MusicVideo; if (musicVideo != null) { SetMusicVideoProperties(dto, musicVideo); } var book = item as Book; if (book != null) { SetBookProperties(dto, book); } }
/// <summary> /// Sets simple property values on a DTOBaseItem /// </summary> /// <param name="dto">The dto.</param> /// <param name="item">The item.</param> /// <param name="owner">The owner.</param> /// <param name="fields">The fields.</param> private void AttachBasicFields(BaseItemDto dto, BaseItem item, BaseItem owner, List<ItemFields> fields) { if (fields.Contains(ItemFields.DateCreated)) { dto.DateCreated = item.DateCreated; } dto.DisplayMediaType = item.DisplayMediaType; if (fields.Contains(ItemFields.Settings)) { dto.LockedFields = item.LockedFields; dto.EnableInternetProviders = !item.DontFetchMeta; } var hasBudget = item as IHasBudget; if (hasBudget != null) { if (fields.Contains(ItemFields.Budget)) { dto.Budget = hasBudget.Budget; } if (fields.Contains(ItemFields.Revenue)) { dto.Revenue = hasBudget.Revenue; } } dto.EndDate = item.EndDate; if (fields.Contains(ItemFields.HomePageUrl)) { dto.HomePageUrl = item.HomePageUrl; } if (fields.Contains(ItemFields.Tags)) { var hasTags = item as IHasTags; if (hasTags != null) { dto.Tags = hasTags.Tags; } if (dto.Tags == null) { dto.Tags = new List<string>(); } } if (fields.Contains(ItemFields.Keywords)) { var hasTags = item as IHasKeywords; if (hasTags != null) { dto.Keywords = hasTags.Keywords; } if (dto.Keywords == null) { dto.Keywords = new List<string>(); } } if (fields.Contains(ItemFields.ProductionLocations)) { SetProductionLocations(item, dto); } var hasAspectRatio = item as IHasAspectRatio; if (hasAspectRatio != null) { dto.AspectRatio = hasAspectRatio.AspectRatio; } var hasMetascore = item as IHasMetascore; if (hasMetascore != null) { dto.Metascore = hasMetascore.Metascore; } if (fields.Contains(ItemFields.AwardSummary)) { var hasAwards = item as IHasAwards; if (hasAwards != null) { dto.AwardSummary = hasAwards.AwardSummary; } } dto.BackdropImageTags = GetBackdropImageTags(item); if (fields.Contains(ItemFields.ScreenshotImageTags)) { dto.ScreenshotImageTags = GetScreenshotImageTags(item); } if (fields.Contains(ItemFields.Genres)) { dto.Genres = item.Genres; } dto.ImageTags = new Dictionary<ImageType, Guid>(); foreach (var image in item.Images) { var type = image.Key; var tag = GetImageCacheTag(item, type, image.Value); if (tag.HasValue) { dto.ImageTags[type] = tag.Value; } } dto.Id = GetDtoId(item); dto.IndexNumber = item.IndexNumber; dto.IsFolder = item.IsFolder; dto.MediaType = item.MediaType; dto.LocationType = item.LocationType; var hasLang = item as IHasPreferredMetadataLanguage; if (hasLang != null) { dto.PreferredMetadataCountryCode = hasLang.PreferredMetadataCountryCode; dto.PreferredMetadataLanguage = hasLang.PreferredMetadataLanguage; } var hasCriticRating = item as IHasCriticRating; if (hasCriticRating != null) { dto.CriticRating = hasCriticRating.CriticRating; if (fields.Contains(ItemFields.CriticRatingSummary)) { dto.CriticRatingSummary = hasCriticRating.CriticRatingSummary; } } var hasTrailers = item as IHasTrailers; if (hasTrailers != null) { dto.LocalTrailerCount = hasTrailers.LocalTrailerIds.Count; } var hasDisplayOrder = item as IHasDisplayOrder; if (hasDisplayOrder != null) { dto.DisplayOrder = hasDisplayOrder.DisplayOrder; } var collectionFolder = item as CollectionFolder; if (collectionFolder != null) { dto.CollectionType = collectionFolder.CollectionType; } if (fields.Contains(ItemFields.RemoteTrailers)) { dto.RemoteTrailers = hasTrailers != null ? hasTrailers.RemoteTrailers : new List<MediaUrl>(); } dto.Name = item.Name; dto.OfficialRating = item.OfficialRating; var hasOverview = fields.Contains(ItemFields.Overview); var hasHtmlOverview = fields.Contains(ItemFields.OverviewHtml); if (hasOverview || hasHtmlOverview) { var strippedOverview = string.IsNullOrEmpty(item.Overview) ? item.Overview : item.Overview.StripHtml(); if (hasOverview) { dto.Overview = strippedOverview; } // Only supply the html version if there was actually html content if (hasHtmlOverview) { dto.OverviewHtml = item.Overview; } } // If there are no backdrops, indicate what parent has them in case the Ui wants to allow inheritance if (dto.BackdropImageTags.Count == 0) { var parentWithBackdrop = GetParentBackdropItem(item, owner); if (parentWithBackdrop != null) { dto.ParentBackdropItemId = GetDtoId(parentWithBackdrop); dto.ParentBackdropImageTags = GetBackdropImageTags(parentWithBackdrop); } } if (item.Parent != null && fields.Contains(ItemFields.ParentId)) { dto.ParentId = GetDtoId(item.Parent); } dto.ParentIndexNumber = item.ParentIndexNumber; // If there is no logo, indicate what parent has one in case the Ui wants to allow inheritance if (!dto.HasLogo) { var parentWithLogo = GetParentImageItem(item, ImageType.Logo, owner); if (parentWithLogo != null) { dto.ParentLogoItemId = GetDtoId(parentWithLogo); dto.ParentLogoImageTag = GetImageCacheTag(parentWithLogo, ImageType.Logo, parentWithLogo.GetImagePath(ImageType.Logo)); } } // If there is no art, indicate what parent has one in case the Ui wants to allow inheritance if (!dto.HasArtImage) { var parentWithImage = GetParentImageItem(item, ImageType.Art, owner); if (parentWithImage != null) { dto.ParentArtItemId = GetDtoId(parentWithImage); dto.ParentArtImageTag = GetImageCacheTag(parentWithImage, ImageType.Art, parentWithImage.GetImagePath(ImageType.Art)); } } // If there is no thumb, indicate what parent has one in case the Ui wants to allow inheritance if (!dto.HasThumb) { var parentWithImage = GetParentImageItem(item, ImageType.Thumb, owner); if (parentWithImage != null) { dto.ParentThumbItemId = GetDtoId(parentWithImage); dto.ParentThumbImageTag = GetImageCacheTag(parentWithImage, ImageType.Thumb, parentWithImage.GetImagePath(ImageType.Thumb)); } } if (fields.Contains(ItemFields.Path)) { dto.Path = item.Path; } dto.PremiereDate = item.PremiereDate; dto.ProductionYear = item.ProductionYear; if (fields.Contains(ItemFields.ProviderIds)) { dto.ProviderIds = item.ProviderIds; } dto.RunTimeTicks = item.RunTimeTicks; if (fields.Contains(ItemFields.SortName)) { dto.SortName = item.SortName; } if (fields.Contains(ItemFields.CustomRating)) { dto.CustomRating = item.CustomRating; } if (fields.Contains(ItemFields.Taglines)) { var hasTagline = item as IHasTaglines; if (hasTagline != null) { dto.Taglines = hasTagline.Taglines; } if (dto.Taglines == null) { dto.Taglines = new List<string>(); } } dto.Type = item.GetClientTypeName(); dto.CommunityRating = item.CommunityRating; dto.VoteCount = item.VoteCount; if (item.IsFolder) { var folder = (Folder)item; if (fields.Contains(ItemFields.IndexOptions)) { dto.IndexOptions = folder.IndexByOptionStrings.ToArray(); } } // Add audio info var audio = item as Audio; if (audio != null) { dto.Album = audio.Album; dto.Artists = audio.Artists; var albumParent = audio.FindParent<MusicAlbum>(); if (albumParent != null) { dto.AlbumId = GetDtoId(albumParent); var imagePath = albumParent.PrimaryImagePath; if (!string.IsNullOrEmpty(imagePath)) { dto.AlbumPrimaryImageTag = GetImageCacheTag(albumParent, ImageType.Primary, imagePath); } } } var album = item as MusicAlbum; if (album != null) { dto.Artists = album.Artists; dto.SoundtrackIds = album.SoundtrackIds .Select(i => i.ToString("N")) .ToArray(); } var hasAlbumArtist = item as IHasAlbumArtist; if (hasAlbumArtist != null) { dto.AlbumArtist = hasAlbumArtist.AlbumArtist; } // Add video info var video = item as Video; if (video != null) { dto.VideoType = video.VideoType; dto.Video3DFormat = video.Video3DFormat; dto.IsoType = video.IsoType; dto.IsHD = video.IsHD; dto.PartCount = video.AdditionalPartIds.Count + 1; if (fields.Contains(ItemFields.Chapters)) { dto.Chapters = _itemRepo.GetChapters(video.Id).Select(c => GetChapterInfoDto(c, item)).ToList(); } } if (fields.Contains(ItemFields.MediaStreams)) { // Add VideoInfo var iHasMediaStreams = item as IHasMediaStreams; if (iHasMediaStreams != null) { dto.MediaStreams = _itemRepo.GetMediaStreams(new MediaStreamQuery { ItemId = item.Id }).ToList(); } } // Add MovieInfo var movie = item as Movie; if (movie != null) { var specialFeatureCount = movie.SpecialFeatureIds.Count; if (specialFeatureCount > 0) { dto.SpecialFeatureCount = specialFeatureCount; } } // Add EpisodeInfo var episode = item as Episode; if (episode != null) { dto.IndexNumberEnd = episode.IndexNumberEnd; dto.DvdSeasonNumber = episode.DvdSeasonNumber; dto.DvdEpisodeNumber = episode.DvdEpisodeNumber; dto.AirsAfterSeasonNumber = episode.AirsAfterSeasonNumber; dto.AirsBeforeEpisodeNumber = episode.AirsBeforeEpisodeNumber; dto.AirsBeforeSeasonNumber = episode.AirsBeforeSeasonNumber; dto.AbsoluteEpisodeNumber = episode.AbsoluteEpisodeNumber; var seasonId = episode.SeasonId; if (seasonId.HasValue) { dto.SeasonId = seasonId.Value.ToString("N"); } } // Add SeriesInfo var series = item as Series; if (series != null) { dto.AirDays = series.AirDays; dto.AirTime = series.AirTime; dto.Status = series.Status; dto.SpecialFeatureCount = series.SpecialFeatureIds.Count; dto.SeasonCount = series.SeasonCount; if (fields.Contains(ItemFields.Settings)) { dto.DisplaySpecialsWithSeasons = series.DisplaySpecialsWithSeasons; } } if (episode != null) { series = item.FindParent<Series>(); dto.SeriesId = GetDtoId(series); dto.SeriesName = series.Name; dto.AirTime = series.AirTime; dto.SeriesStudio = series.Studios.FirstOrDefault(); if (series.HasImage(ImageType.Thumb)) { dto.SeriesThumbImageTag = GetImageCacheTag(series, ImageType.Thumb, series.GetImagePath(ImageType.Thumb)); } var imagePath = series.PrimaryImagePath; if (!string.IsNullOrEmpty(imagePath)) { dto.SeriesPrimaryImageTag = GetImageCacheTag(series, ImageType.Primary, imagePath); } } // Add SeasonInfo var season = item as Season; if (season != null) { series = item.FindParent<Series>(); dto.SeriesId = GetDtoId(series); dto.SeriesName = series.Name; dto.AirTime = series.AirTime; dto.SeriesStudio = series.Studios.FirstOrDefault(); var imagePath = series.PrimaryImagePath; if (!string.IsNullOrEmpty(imagePath)) { dto.SeriesPrimaryImageTag = GetImageCacheTag(series, ImageType.Primary, imagePath); } } var game = item as Game; if (game != null) { SetGameProperties(dto, game); } var gameSystem = item as GameSystem; if (gameSystem != null) { SetGameSystemProperties(dto, gameSystem); } var musicVideo = item as MusicVideo; if (musicVideo != null) { SetMusicVideoProperties(dto, musicVideo); } var book = item as Book; if (book != null) { SetBookProperties(dto, book); } }
/// <summary> /// Sets simple property values on a DTOBaseItem /// </summary> /// <param name="dto">The dto.</param> /// <param name="item">The item.</param> /// <param name="fields">The fields.</param> private void AttachBasicFields(BaseItemDto dto, BaseItem item, List <ItemFields> fields) { if (fields.Contains(ItemFields.DateCreated)) { dto.DateCreated = item.DateCreated; } if (fields.Contains(ItemFields.DisplayMediaType)) { dto.DisplayMediaType = item.DisplayMediaType; } dto.AspectRatio = item.AspectRatio; dto.BackdropImageTags = GetBackdropImageTags(item); if (fields.Contains(ItemFields.Genres)) { dto.Genres = item.Genres; } if (item.Images != null) { dto.ImageTags = new Dictionary <ImageType, Guid>(); foreach (var image in item.Images) { ImageType type; if (Enum.TryParse(image.Key, true, out type)) { dto.ImageTags[type] = Kernel.Instance.ImageManager.GetImageCacheTag(item, type, image.Value); } } } dto.Id = GetClientItemId(item); dto.IndexNumber = item.IndexNumber; dto.IsFolder = item.IsFolder; dto.Language = item.Language; dto.MediaType = item.MediaType; dto.LocationType = item.LocationType; var localTrailerCount = item.LocalTrailers == null ? 0 : item.LocalTrailers.Count; if (localTrailerCount > 0) { dto.LocalTrailerCount = localTrailerCount; } dto.Name = item.Name; dto.OfficialRating = item.OfficialRating; var hasOverview = fields.Contains(ItemFields.Overview); var hasHtmlOverview = fields.Contains(ItemFields.OverviewHtml); if (hasOverview || hasHtmlOverview) { var strippedOverview = string.IsNullOrEmpty(item.Overview) ? item.Overview : item.Overview.StripHtml(); if (hasOverview) { dto.Overview = strippedOverview; } // Only supply the html version if there was actually html content if (hasHtmlOverview) { dto.OverviewHtml = item.Overview; } } // If there are no backdrops, indicate what parent has them in case the Ui wants to allow inheritance if (dto.BackdropImageTags.Count == 0) { var parentWithBackdrop = GetParentBackdropItem(item); if (parentWithBackdrop != null) { dto.ParentBackdropItemId = GetClientItemId(parentWithBackdrop); dto.ParentBackdropImageTags = GetBackdropImageTags(parentWithBackdrop); } } if (item.Parent != null && fields.Contains(ItemFields.ParentId)) { dto.ParentId = GetClientItemId(item.Parent); } dto.ParentIndexNumber = item.ParentIndexNumber; // If there is no logo, indicate what parent has one in case the Ui wants to allow inheritance if (!dto.HasLogo) { var parentWithLogo = GetParentLogoItem(item); if (parentWithLogo != null) { dto.ParentLogoItemId = GetClientItemId(parentWithLogo); dto.ParentLogoImageTag = Kernel.Instance.ImageManager.GetImageCacheTag(parentWithLogo, ImageType.Logo, parentWithLogo.GetImage(ImageType.Logo)); } } if (fields.Contains(ItemFields.Path)) { dto.Path = item.Path; } dto.PremiereDate = item.PremiereDate; dto.ProductionYear = item.ProductionYear; if (fields.Contains(ItemFields.ProviderIds)) { dto.ProviderIds = item.ProviderIds; } dto.RunTimeTicks = item.RunTimeTicks; if (fields.Contains(ItemFields.SortName)) { dto.SortName = item.SortName; } if (fields.Contains(ItemFields.Taglines)) { dto.Taglines = item.Taglines; } if (fields.Contains(ItemFields.TrailerUrls)) { dto.TrailerUrls = item.TrailerUrls; } dto.Type = item.GetType().Name; dto.CommunityRating = item.CommunityRating; if (item.IsFolder) { var folder = (Folder)item; if (fields.Contains(ItemFields.IndexOptions)) { dto.IndexOptions = folder.IndexByOptionStrings.ToArray(); } } // Add audio info var audio = item as Audio; if (audio != null) { if (fields.Contains(ItemFields.AudioInfo)) { dto.Album = audio.Album; dto.AlbumArtist = audio.AlbumArtist; dto.Artist = audio.Artist; } } // Add video info var video = item as Video; if (video != null) { dto.VideoType = video.VideoType; dto.VideoFormat = video.VideoFormat; dto.IsoType = video.IsoType; if (fields.Contains(ItemFields.Chapters) && video.Chapters != null) { dto.Chapters = video.Chapters.Select(c => GetChapterInfoDto(c, item)).ToList(); } } if (fields.Contains(ItemFields.MediaStreams)) { // Add VideoInfo var iHasMediaStreams = item as IHasMediaStreams; if (iHasMediaStreams != null) { dto.MediaStreams = iHasMediaStreams.MediaStreams; } } // Add MovieInfo var movie = item as Movie; if (movie != null) { var specialFeatureCount = movie.SpecialFeatures == null ? 0 : movie.SpecialFeatures.Count; if (specialFeatureCount > 0) { dto.SpecialFeatureCount = specialFeatureCount; } } if (fields.Contains(ItemFields.SeriesInfo)) { // Add SeriesInfo var series = item as Series; if (series != null) { dto.AirDays = series.AirDays; dto.AirTime = series.AirTime; dto.Status = series.Status; } // Add EpisodeInfo var episode = item as Episode; if (episode != null) { series = item.FindParent <Series>(); dto.SeriesId = GetClientItemId(series); dto.SeriesName = series.Name; } // Add SeasonInfo var season = item as Season; if (season != null) { series = item.FindParent <Series>(); dto.SeriesId = GetClientItemId(series); dto.SeriesName = series.Name; } } }