private void ItemUpdated(BaseItem item) { lock (_libraryChangedSyncLock) { if (WriteTimer == null) { WriteTimer = new Timer(TimerCallback, null, WriteDelay, Timeout.Infinite); } else { WriteTimer.Change(WriteDelay, Timeout.Infinite); } var itemRec = new ItemRec { Guid = item.Id, #if EMBY ItemId = item.GetClientId(), #endif Status = ItemStatus.Updated, Type = item.GetClientTypeName() }; _logger.LogDebug($"InfuseSync saving updated item {item.Id}"); _itemsUpdated.Add(itemRec); } }
/// <summary> Gets an episode. </summary> /// <param name="item"> The item. </param> /// <returns> The episode. </returns> protected string GetEpisode(BaseItem item) { if (item.GetClientTypeName() == ChannelMediaContentType.Episode.ToString() && item.ParentIndexNumber != null) { return("Season " + item.ParentIndexNumber); } else { return(item.Name); } }
private void ItemRemoved(BaseItem item) { lock (_libraryChangedSyncLock) { if (WriteTimer == null) { WriteTimer = new Timer(TimerCallback, null, WriteDelay, Timeout.Infinite); } else { WriteTimer.Change(WriteDelay, Timeout.Infinite); } #if EMBY long?seriesId; #else Guid?seriesId; #endif int?seasonNumber; if (item is Season season) { seriesId = season.SeriesId; seasonNumber = season.IndexNumber; } else { seriesId = null; seasonNumber = null; } var itemRec = new ItemRec { Guid = item.Id, #if EMBY ItemId = item.GetClientId(), #endif SeriesId = seriesId, Season = seasonNumber, Status = ItemStatus.Removed, Type = item.GetClientTypeName() }; _logger.LogDebug($"InfuseSync saving removed item {item.Id}"); _itemsRemoved.Add(itemRec); } }
/// <summary> Gets a row. </summary> /// <param name="item"> The item. </param> /// <returns> The row. </returns> private ReportRow GetRow(BaseItem item) { var video = item as Video; ReportRow rRow = new ReportRow { Id = item.Id.ToString("N"), HasLockData = item.IsLocked, HasLocalTrailer = item.GetExtras(new[] { ExtraType.Trailer }).Any(), HasImageTagsPrimary = item.ImageInfos != null && item.ImageInfos.Count(n => n.Type == ImageType.Primary) > 0, HasImageTagsBackdrop = item.ImageInfos != null && item.ImageInfos.Count(n => n.Type == ImageType.Backdrop) > 0, HasImageTagsLogo = item.ImageInfos != null && item.ImageInfos.Count(n => n.Type == ImageType.Logo) > 0, HasSpecials = item.GetDisplayExtras().Any(), HasSubtitles = video != null ? video.HasSubtitles : false, RowType = ReportHelper.GetRowType(item.GetClientTypeName()) }; return(rRow); }
/// <summary> Gets a row. </summary> /// <param name="item"> The item. </param> /// <returns> The row. </returns> private ReportRow GetRow(BaseItem item) { var hasTrailers = item as IHasTrailers; var hasSpecialFeatures = item as IHasSpecialFeatures; var video = item as Video; ReportRow rRow = new ReportRow { Id = item.Id.ToString("N"), HasLockData = item.IsLocked, HasLocalTrailer = hasTrailers != null?hasTrailers.GetTrailerIds().Count() > 0 : false, HasImageTagsPrimary = item.ImageInfos != null && item.ImageInfos.Count(n => n.Type == ImageType.Primary) > 0, HasImageTagsBackdrop = item.ImageInfos != null && item.ImageInfos.Count(n => n.Type == ImageType.Backdrop) > 0, HasImageTagsLogo = item.ImageInfos != null && item.ImageInfos.Count(n => n.Type == ImageType.Logo) > 0, HasSpecials = hasSpecialFeatures != null ? hasSpecialFeatures.SpecialFeatureIds.Length > 0 : false, HasSubtitles = video != null ? video.HasSubtitles : false, RowType = ReportHelper.GetRowType(item.GetClientTypeName()) }; return(rRow); }
/// <summary> /// Converts a BaseItem to a BaseItemInfo /// </summary> /// <param name="item">The item.</param> /// <returns>BaseItemInfo.</returns> /// <exception cref="System.ArgumentNullException">item</exception> public BaseItemInfo GetBaseItemInfo(BaseItem item) { if (item == null) { throw new ArgumentNullException("item"); } var info = new BaseItemInfo { Id = GetDtoId(item), Name = item.Name, MediaType = item.MediaType, Type = item.GetClientTypeName(), RunTimeTicks = item.RunTimeTicks }; info.PrimaryImageTag = GetImageCacheTag(item, ImageType.Primary); return(info); }
private static bool ShouldSyncItem(BaseItem item, Func <string, bool> typeCheck) { if (item.LocationType == MediaBrowser.Model.Entities.LocationType.Virtual) { return(false); } if (item.GetTopParent() is Channel) { return(false); } var typeName = item.GetClientTypeName(); if (string.IsNullOrEmpty(typeName)) { return(false); } return(typeCheck(typeName)); }
/// <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.DisplayMediaType)) { dto.DisplayMediaType = item.DisplayMediaType; } dto.IsUnidentified = item.IsUnidentified; if (fields.Contains(ItemFields.Settings)) { dto.LockedFields = item.LockedFields; dto.LockData = item.IsLocked; dto.ForcedSortName = item.ForcedSortName; } 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, string>(); // 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 != null) { dto.ImageTags[image.Type] = tag; } } 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 ICollectionFolder; if (collectionFolder != null) { dto.CollectionType = collectionFolder.CollectionType; } var userView = item as UserView; if (userView != null) { dto.CollectionType = userView.ViewType; } if (fields.Contains(ItemFields.RemoteTrailers)) { dto.RemoteTrailers = hasTrailers != null ? hasTrailers.RemoteTrailers : new List <MediaUrl>(); } dto.Name = item.Name; dto.OfficialRating = item.OfficialRating; if (fields.Contains(ItemFields.Overview)) { dto.Overview = item.Overview; } if (fields.Contains(ItemFields.ShortOverview)) { var hasShortOverview = item as IHasShortOverview; if (hasShortOverview != null) { dto.ShortOverview = hasShortOverview.ShortOverview; } } // 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)) { dto.Path = GetMappedPath(item); } 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); } dto.MediaSourceCount = 1; } 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.AlbumArtists.FirstOrDefault(); } // 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; dto.MediaSourceCount = video.MediaSourceCount; if (fields.Contains(ItemFields.Chapters)) { List <ChapterInfoDto> chapters; if (dto.MediaSources != null && dto.MediaSources.Count > 0) { chapters = _itemRepo.GetChapters(item.Id).Select(c => GetChapterInfoDto(c, item)).ToList(); } else { chapters = _itemRepo.GetChapters(video.Id) .Select(c => GetChapterInfoDto(c, item)) .ToList(); } dto.Chapters = chapters; } } if (fields.Contains(ItemFields.MediaStreams)) { // Add VideoInfo var iHasMediaSources = item as IHasMediaSources; if (iHasMediaSources != null) { List <MediaStream> mediaStreams; if (dto.MediaSources != null && dto.MediaSources.Count > 0) { mediaStreams = dto.MediaSources.Where(i => new Guid(i.Id) == item.Id) .SelectMany(i => i.MediaStreams) .ToList(); } else { mediaStreams = iHasMediaSources.GetMediaSources(true).First().MediaStreams; } dto.MediaStreams = mediaStreams; } } // 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 episodeSeason = episode.Season; if (episodeSeason != null) { dto.SeasonId = episodeSeason.Id.ToString("N"); dto.SeasonName = episodeSeason.Name; } } // 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 = episode.Series; if (series != null) { 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 = season.Series; if (series != null) { 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); } var photo = item as Photo; if (photo != null) { SetPhotoProperties(dto, photo); } var tvChannel = item as LiveTvChannel; if (tvChannel != null) { dto.MediaSources = tvChannel.GetMediaSources(true).ToList(); } var channelItem = item as IChannelItem; if (channelItem != null) { dto.ChannelId = channelItem.ChannelId; dto.ChannelName = _channelManagerFactory().GetChannel(channelItem.ChannelId).Name; } }
/// <summary> /// Converts a BaseItem to a BaseItemInfo /// </summary> /// <param name="item">The item.</param> /// <param name="runtimeTicks">The now playing runtime ticks.</param> /// <returns>BaseItemInfo.</returns> /// <exception cref="System.ArgumentNullException">item</exception> private BaseItemInfo GetItemInfo(BaseItem item, long?runtimeTicks) { if (item == null) { throw new ArgumentNullException("item"); } var info = new BaseItemInfo { Id = GetDtoId(item), Name = item.Name, MediaType = item.MediaType, Type = item.GetClientTypeName(), RunTimeTicks = runtimeTicks, IndexNumber = item.IndexNumber, ParentIndexNumber = item.ParentIndexNumber, PremiereDate = item.PremiereDate, ProductionYear = item.ProductionYear }; info.PrimaryImageTag = GetImageCacheTag(item, ImageType.Primary); if (info.PrimaryImageTag.HasValue) { info.PrimaryImageItemId = GetDtoId(item); } var episode = item as Episode; if (episode != null) { info.IndexNumberEnd = episode.IndexNumberEnd; } var hasSeries = item as IHasSeries; if (hasSeries != null) { info.SeriesName = hasSeries.SeriesName; } var recording = item as ILiveTvRecording; if (recording != null && recording.RecordingInfo != null) { if (recording.RecordingInfo.IsSeries) { info.Name = recording.RecordingInfo.EpisodeTitle; info.SeriesName = recording.RecordingInfo.Name; if (string.IsNullOrWhiteSpace(info.Name)) { info.Name = recording.RecordingInfo.Name; } } } var audio = item as Audio; if (audio != null) { info.Album = audio.Album; info.Artists = audio.Artists; if (!info.PrimaryImageTag.HasValue) { var album = audio.Parents.OfType <MusicAlbum>().FirstOrDefault(); if (album != null && album.HasImage(ImageType.Primary)) { info.PrimaryImageTag = GetImageCacheTag(album, ImageType.Primary); if (info.PrimaryImageTag.HasValue) { info.PrimaryImageItemId = GetDtoId(album); } } } } var musicVideo = item as MusicVideo; if (musicVideo != null) { info.Album = musicVideo.Album; if (!string.IsNullOrWhiteSpace(musicVideo.Artist)) { info.Artists.Add(musicVideo.Artist); } } var backropItem = item.HasImage(ImageType.Backdrop) ? item : null; var thumbItem = item.HasImage(ImageType.Thumb) ? item : null; var logoItem = item.HasImage(ImageType.Logo) ? item : null; if (thumbItem == null) { if (episode != null) { var series = episode.Series; if (series != null && series.HasImage(ImageType.Thumb)) { thumbItem = series; } } } if (backropItem == null) { if (episode != null) { var series = episode.Series; if (series != null && series.HasImage(ImageType.Backdrop)) { backropItem = series; } } } if (backropItem == null) { backropItem = item.Parents.FirstOrDefault(i => i.HasImage(ImageType.Backdrop)); } if (thumbItem == null) { thumbItem = item.Parents.FirstOrDefault(i => i.HasImage(ImageType.Thumb)); } if (logoItem == null) { logoItem = item.Parents.FirstOrDefault(i => i.HasImage(ImageType.Logo)); } if (thumbItem != null) { info.ThumbImageTag = GetImageCacheTag(thumbItem, ImageType.Thumb); info.ThumbItemId = GetDtoId(thumbItem); } if (backropItem != null) { info.BackdropImageTag = GetImageCacheTag(backropItem, ImageType.Backdrop); info.BackdropItemId = GetDtoId(backropItem); } if (logoItem != null) { info.LogoImageTag = GetImageCacheTag(logoItem, ImageType.Logo); info.LogoItemId = GetDtoId(logoItem); } return(info); }
/// <summary> /// Converts a BaseItem to a BaseItemInfo /// </summary> /// <param name="item">The item.</param> /// <param name="mediaSourceId">The media version identifier.</param> /// <param name="nowPlayingRuntimeTicks">The now playing runtime ticks.</param> /// <returns>BaseItemInfo.</returns> /// <exception cref="System.ArgumentNullException">item</exception> private BaseItemInfo GetNowPlayingInfo(BaseItem item, string mediaSourceId, long? nowPlayingRuntimeTicks) { if (item == null) { throw new ArgumentNullException("item"); } var info = new BaseItemInfo { Id = GetDtoId(item), Name = item.Name, MediaType = item.MediaType, Type = item.GetClientTypeName(), RunTimeTicks = nowPlayingRuntimeTicks, MediaSourceId = mediaSourceId }; info.PrimaryImageTag = GetImageCacheTag(item, ImageType.Primary); var backropItem = item.HasImage(ImageType.Backdrop) ? item : null; var thumbItem = item.HasImage(ImageType.Thumb) ? item : null; if (thumbItem == null) { var episode = item as Episode; if (episode != null) { var series = episode.Series; if (series != null && series.HasImage(ImageType.Thumb)) { thumbItem = series; } } } if (backropItem == null) { var episode = item as Episode; if (episode != null) { var series = episode.Series; if (series != null && series.HasImage(ImageType.Backdrop)) { backropItem = series; } } } if (thumbItem == null) { thumbItem = item.Parents.FirstOrDefault(i => i.HasImage(ImageType.Thumb)); } if (thumbItem != null) { info.ThumbImageTag = GetImageCacheTag(thumbItem, ImageType.Thumb); info.ThumbItemId = GetDtoId(thumbItem); } if (thumbItem != null) { info.BackdropImageTag = GetImageCacheTag(backropItem, ImageType.Backdrop); info.BackdropItemId = GetDtoId(backropItem); } return info; }
/// <summary> Gets a row. </summary> /// <param name="item"> The item. </param> /// <returns> The row. </returns> private ReportRow GetRow(BaseItem item) { var hasTrailers = item as IHasTrailers; var hasSpecialFeatures = item as IHasSpecialFeatures; var video = item as Video; ReportRow rRow = new ReportRow { Id = item.Id.ToString("N"), HasLockData = item.IsLocked, IsUnidentified = item.IsUnidentified, HasLocalTrailer = hasTrailers != null ? hasTrailers.GetTrailerIds().Count() > 0 : false, HasImageTagsPrimary = (item.ImageInfos != null && item.ImageInfos.Count(n => n.Type == ImageType.Primary) > 0), HasImageTagsBackdrop = (item.ImageInfos != null && item.ImageInfos.Count(n => n.Type == ImageType.Backdrop) > 0), HasImageTagsLogo = (item.ImageInfos != null && item.ImageInfos.Count(n => n.Type == ImageType.Logo) > 0), HasSpecials = hasSpecialFeatures != null ? hasSpecialFeatures.SpecialFeatureIds.Count > 0 : false, HasSubtitles = video != null ? video.HasSubtitles : false, RowType = ReportHelper.GetRowType(item.GetClientTypeName()) }; return rRow; }
/// <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.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.ProductionLocations)) { SetProductionLocations(item, dto); } var hasAspectRatio = item as IHasAspectRatio; if (hasAspectRatio != null) { dto.AspectRatio = hasAspectRatio.AspectRatio; } 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 hasLanguage = item as IHasLanguage; if (hasLanguage != null) { dto.Language = hasLanguage.Language; } 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; } 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.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 = GetDtoId(parentWithImage); dto.ParentArtImageTag = GetImageCacheTag(parentWithImage, ImageType.Art, parentWithImage.GetImage(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.GetImage(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.GetImage(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); } }
private bool FilterItem(BaseItem item, out int type) { type = -1; if (!Plugin.Instance.Configuration.IsEnabled) { return(false); } if (item.LocationType == LocationType.Virtual) { return(false); } if (item.SourceType != SourceType.Library) { return(false); } var typeName = item.GetClientTypeName(); if (string.IsNullOrEmpty(typeName)) { return(false); } switch (typeName) { case "Movie": if (!Plugin.Instance.Configuration.tkMovies) { return(false); } type = 0; break; case "BoxSet": if (!Plugin.Instance.Configuration.tkBoxSets) { return(false); } type = 4; break; case "Episode": if (!Plugin.Instance.Configuration.tkTVShows) { return(false); } type = 1; break; case "Audio": if (!Plugin.Instance.Configuration.tkMusic) { return(false); } type = 2; break; case "MusicVideo": if (!Plugin.Instance.Configuration.tkMusicVideos) { return(false); } type = 3; break; default: type = -1; _logger.LogDebug("Ingoring Type {TypeName}", typeName); return(false); } return(true); }
private bool FilterRemovedItem(BaseItem item, out int type) { type = -1; if (!Plugin.Instance.Configuration.IsEnabled) { return(false); } if (item.LocationType == LocationType.Virtual) { return(false); } if (item.GetTopParent() is Channel) { return(false); } var typeName = item.GetClientTypeName(); if (string.IsNullOrEmpty(typeName)) { return(false); } switch (typeName) { case "Movie": case "Folder": if (!Plugin.Instance.Configuration.tkMovies) { return(false); } type = 0; break; case "BoxSet": if (!Plugin.Instance.Configuration.tkBoxSets) { return(false); } type = 4; break; case "Series": case "Season": case "Episode": if (!Plugin.Instance.Configuration.tkTVShows) { return(false); } type = 1; break; case "Audio": case "MusicArtist": case "MusicAlbum": if (!Plugin.Instance.Configuration.tkMusic) { return(false); } type = 2; break; case "MusicVideo": if (!Plugin.Instance.Configuration.tkMusicVideos) { return(false); } type = 3; break; default: type = -1; _logger.LogDebug("Ingoring Type {TypeName}", typeName); return(false); } return(true); }
private bool FilterItem(BaseItem item, out int type) { type = -1; if (!Plugin.Instance.Configuration.IsEnabled) { return false; } if (item.LocationType == LocationType.Virtual) { return false; } if (item.SourceType != SourceType.Library) { return false; } var typeName = item.GetClientTypeName(); if (string.IsNullOrEmpty(typeName)) { return false; } switch (typeName) { //MOVIES case "Movie": if (!Plugin.Instance.Configuration.tkMovies) { return false; } type = 0; break; case "Boxset": if (!Plugin.Instance.Configuration.tkBoxSets) { return false; } type = 4; break; case "Series": case "Season": case "Episode": if (!Plugin.Instance.Configuration.tkTVShows) { return false; } type = 1; break; case "Audio": case "MusicArtist": case "MusicAlbum": if (!Plugin.Instance.Configuration.tkMusic) { return false; } type = 2; break; case "MusicVideo": if (!Plugin.Instance.Configuration.tkMusicVideos) { return false; } type = 3; break; default: type = -1; _logger.Debug(String.Format("Emby.Kodi.SyncQueue: Ingoring Type {0}", typeName)); return false; } return true; }
/// <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="options">The options.</param> private void AttachBasicFields(BaseItemDto dto, BaseItem item, BaseItem owner, DtoOptions options) { var fields = options.Fields; if (fields.Contains(ItemFields.DateCreated)) { dto.DateCreated = item.DateCreated; } if (fields.Contains(ItemFields.DisplayMediaType)) { dto.DisplayMediaType = item.DisplayMediaType; } if (fields.Contains(ItemFields.Settings)) { dto.LockedFields = item.LockedFields; dto.LockData = item.IsLocked; dto.ForcedSortName = item.ForcedSortName; } 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; } if (fields.Contains(ItemFields.Metascore)) { 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; } } var backdropLimit = options.GetImageLimit(ImageType.Backdrop); if (backdropLimit > 0) { dto.BackdropImageTags = GetBackdropImageTags(item, backdropLimit); } if (fields.Contains(ItemFields.ScreenshotImageTags)) { var screenshotLimit = options.GetImageLimit(ImageType.Screenshot); if (screenshotLimit > 0) { dto.ScreenshotImageTags = GetScreenshotImageTags(item, screenshotLimit); } } if (fields.Contains(ItemFields.Genres)) { dto.Genres = item.Genres; } dto.ImageTags = new Dictionary<ImageType, string>(); // Prevent implicitly captured closure var currentItem = item; foreach (var image in currentItem.ImageInfos.Where(i => !currentItem.AllowsMultipleImages(i.Type)) .ToList()) { if (options.GetImageLimit(image.Type) > 0) { var tag = GetImageCacheTag(item, image); if (tag != null) { dto.ImageTags[image.Type] = tag; } } } dto.Id = GetDtoId(item); dto.IndexNumber = item.IndexNumber; dto.IsFolder = item.IsFolder; dto.MediaType = item.MediaType; dto.LocationType = item.LocationType; dto.IsHD = item.IsHD; dto.PreferredMetadataCountryCode = item.PreferredMetadataCountryCode; dto.PreferredMetadataLanguage = item.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.GetTrailerIds().Count; } var hasDisplayOrder = item as IHasDisplayOrder; if (hasDisplayOrder != null) { dto.DisplayOrder = hasDisplayOrder.DisplayOrder; } var userView = item as UserView; if (userView != null) { dto.CollectionType = userView.ViewType; } if (fields.Contains(ItemFields.RemoteTrailers)) { dto.RemoteTrailers = hasTrailers != null ? hasTrailers.RemoteTrailers : new List<MediaUrl>(); } dto.Name = item.Name; dto.OfficialRating = item.OfficialRating; if (fields.Contains(ItemFields.Overview)) { dto.Overview = item.Overview; } if (fields.Contains(ItemFields.ShortOverview)) { var hasShortOverview = item as IHasShortOverview; if (hasShortOverview != null) { dto.ShortOverview = hasShortOverview.ShortOverview; } } // If there are no backdrops, indicate what parent has them in case the Ui wants to allow inheritance if (backdropLimit > 0 && dto.BackdropImageTags.Count == 0) { var parentWithBackdrop = GetParentBackdropItem(item, owner); if (parentWithBackdrop != null) { dto.ParentBackdropItemId = GetDtoId(parentWithBackdrop); dto.ParentBackdropImageTags = GetBackdropImageTags(parentWithBackdrop, backdropLimit); } } if (fields.Contains(ItemFields.ParentId)) { var displayParent = item.DisplayParent; if (displayParent != null) { dto.ParentId = GetDtoId(displayParent); } } 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 && options.GetImageLimit(ImageType.Logo) > 0) { 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 && options.GetImageLimit(ImageType.Art) > 0) { 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 && options.GetImageLimit(ImageType.Thumb) > 0) { 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)) { dto.Path = GetMappedPath(item); } 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; if (fields.Contains(ItemFields.VoteCount)) { 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; var albumParent = audio.AlbumEntity; if (albumParent != null) { dto.AlbumId = GetDtoId(albumParent); dto.AlbumPrimaryImageTag = GetImageCacheTag(albumParent, ImageType.Primary); } //if (fields.Contains(ItemFields.MediaSourceCount)) //{ // Songs always have one //} } var hasArtist = item as IHasArtist; if (hasArtist != null) { dto.Artists = hasArtist.Artists; dto.ArtistItems = hasArtist .Artists .Select(i => { try { var artist = _libraryManager.GetArtist(i); return new NameIdPair { Name = artist.Name, Id = artist.Id.ToString("N") }; } catch (Exception ex) { _logger.ErrorException("Error getting artist", ex); return null; } }) .Where(i => i != null) .ToList(); } var hasAlbumArtist = item as IHasAlbumArtist; if (hasAlbumArtist != null) { dto.AlbumArtist = hasAlbumArtist.AlbumArtists.FirstOrDefault(); dto.AlbumArtists = hasAlbumArtist .AlbumArtists .Select(i => { try { var artist = _libraryManager.GetArtist(i); return new NameIdPair { Name = artist.Name, Id = artist.Id.ToString("N") }; } catch (Exception ex) { _logger.ErrorException("Error getting album artist", ex); return null; } }) .Where(i => i != null) .ToList(); } // Add video info var video = item as Video; if (video != null) { dto.VideoType = video.VideoType; dto.Video3DFormat = video.Video3DFormat; dto.IsoType = video.IsoType; if (video.HasSubtitles) { dto.HasSubtitles = video.HasSubtitles; } if (video.AdditionalParts.Count != 0) { dto.PartCount = video.AdditionalParts.Count + 1; } if (fields.Contains(ItemFields.MediaSourceCount)) { if (video.MediaSourceCount != 1) { dto.MediaSourceCount = video.MediaSourceCount; } } if (fields.Contains(ItemFields.Chapters)) { dto.Chapters = GetChapterInfoDtos(item); } } if (fields.Contains(ItemFields.MediaStreams)) { // Add VideoInfo var iHasMediaSources = item as IHasMediaSources; if (iHasMediaSources != null) { List<MediaStream> mediaStreams; if (dto.MediaSources != null && dto.MediaSources.Count > 0) { mediaStreams = dto.MediaSources.Where(i => new Guid(i.Id) == item.Id) .SelectMany(i => i.MediaStreams) .ToList(); } else { mediaStreams = _mediaSourceManager().GetStaticMediaSources(iHasMediaSources, true).First().MediaStreams; } dto.MediaStreams = mediaStreams; } } // Add MovieInfo var movie = item as Movie; if (movie != null) { if (fields.Contains(ItemFields.TmdbCollectionName)) { dto.TmdbCollectionName = movie.TmdbCollectionName; } } var hasSpecialFeatures = item as IHasSpecialFeatures; if (hasSpecialFeatures != null) { var specialFeatureCount = hasSpecialFeatures.SpecialFeatureIds.Count; if (specialFeatureCount > 0) { dto.SpecialFeatureCount = specialFeatureCount; } } // Add EpisodeInfo var episode = item as Episode; if (episode != null) { dto.IndexNumberEnd = episode.IndexNumberEnd; if (fields.Contains(ItemFields.AlternateEpisodeNumbers)) { dto.DvdSeasonNumber = episode.DvdSeasonNumber; dto.DvdEpisodeNumber = episode.DvdEpisodeNumber; dto.AbsoluteEpisodeNumber = episode.AbsoluteEpisodeNumber; } if (fields.Contains(ItemFields.SpecialEpisodeNumbers)) { dto.AirsAfterSeasonNumber = episode.AirsAfterSeasonNumber; dto.AirsBeforeEpisodeNumber = episode.AirsBeforeEpisodeNumber; dto.AirsBeforeSeasonNumber = episode.AirsBeforeSeasonNumber; } var episodeSeason = episode.Season; if (episodeSeason != null) { dto.SeasonId = episodeSeason.Id.ToString("N"); if (fields.Contains(ItemFields.SeasonName)) { dto.SeasonName = episodeSeason.Name; } } if (fields.Contains(ItemFields.SeriesGenres)) { var episodeseries = episode.Series; if (episodeseries != null) { dto.SeriesGenres = episodeseries.Genres.ToList(); } } } // Add SeriesInfo var series = item as Series; if (series != null) { dto.AirDays = series.AirDays; dto.AirTime = series.AirTime; dto.SeriesStatus = series.Status; if (fields.Contains(ItemFields.Settings)) { dto.DisplaySpecialsWithSeasons = series.DisplaySpecialsWithSeasons; } dto.AnimeSeriesIndex = series.AnimeSeriesIndex; } if (episode != null) { series = episode.Series; if (series != null) { dto.SeriesId = GetDtoId(series); dto.SeriesName = series.Name; if (fields.Contains(ItemFields.AirTime)) { dto.AirTime = series.AirTime; } if (options.GetImageLimit(ImageType.Thumb) > 0) { dto.SeriesThumbImageTag = GetImageCacheTag(series, ImageType.Thumb); } if (options.GetImageLimit(ImageType.Primary) > 0) { dto.SeriesPrimaryImageTag = GetImageCacheTag(series, ImageType.Primary); } if (fields.Contains(ItemFields.SeriesStudio)) { dto.SeriesStudio = series.Studios.FirstOrDefault(); } } } // Add SeasonInfo var season = item as Season; if (season != null) { series = season.Series; if (series != null) { dto.SeriesId = GetDtoId(series); dto.SeriesName = series.Name; dto.AirTime = series.AirTime; dto.SeriesStudio = series.Studios.FirstOrDefault(); if (options.GetImageLimit(ImageType.Primary) > 0) { 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); } var photo = item as Photo; if (photo != null) { SetPhotoProperties(dto, photo); } dto.ChannelId = item.ChannelId; var channelItem = item as IChannelItem; if (channelItem != null) { dto.ChannelName = _channelManagerFactory().GetChannel(channelItem.ChannelId).Name; } var channelMediaItem = item as IChannelMediaItem; if (channelMediaItem != null) { dto.ExtraType = channelMediaItem.ExtraType; } }
/// <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="options">The options.</param> private void AttachBasicFields(BaseItemDto dto, BaseItem item, BaseItem owner, DtoOptions options) { var fields = options.Fields; if (fields.Contains(ItemFields.DateCreated)) { dto.DateCreated = item.DateCreated; } if (fields.Contains(ItemFields.DisplayMediaType)) { dto.DisplayMediaType = item.DisplayMediaType; } if (fields.Contains(ItemFields.Settings)) { dto.LockedFields = item.LockedFields; dto.LockData = item.IsLocked; dto.ForcedSortName = item.ForcedSortName; } dto.Container = item.Container; 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)) { dto.Tags = item.Tags; } if (fields.Contains(ItemFields.Keywords)) { dto.Keywords = item.Keywords; } var hasAspectRatio = item as IHasAspectRatio; if (hasAspectRatio != null) { dto.AspectRatio = hasAspectRatio.AspectRatio; } if (fields.Contains(ItemFields.Metascore)) { 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; } } var backdropLimit = options.GetImageLimit(ImageType.Backdrop); if (backdropLimit > 0) { dto.BackdropImageTags = GetImageTags(item, item.GetImages(ImageType.Backdrop).Take(backdropLimit).ToList()); } if (fields.Contains(ItemFields.ScreenshotImageTags)) { var screenshotLimit = options.GetImageLimit(ImageType.Screenshot); if (screenshotLimit > 0) { dto.ScreenshotImageTags = GetImageTags(item, item.GetImages(ImageType.Screenshot).Take(screenshotLimit).ToList()); } } if (fields.Contains(ItemFields.Genres)) { dto.Genres = item.Genres; } if (options.EnableImages) { dto.ImageTags = new Dictionary<ImageType, string>(); // Prevent implicitly captured closure var currentItem = item; foreach (var image in currentItem.ImageInfos.Where(i => !currentItem.AllowsMultipleImages(i.Type)) .ToList()) { if (options.GetImageLimit(image.Type) > 0) { var tag = GetImageCacheTag(item, image); if (tag != null) { dto.ImageTags[image.Type] = tag; } } } } dto.Id = GetDtoId(item); dto.IndexNumber = item.IndexNumber; dto.ParentIndexNumber = item.ParentIndexNumber; if (item.IsFolder) { dto.IsFolder = true; } else if (item is IHasMediaSources) { dto.IsFolder = false; } dto.MediaType = item.MediaType; dto.LocationType = item.LocationType; if (item.IsHD.HasValue && item.IsHD.Value) { dto.IsHD = item.IsHD; } dto.Audio = item.Audio; if (fields.Contains(ItemFields.Settings)) { dto.PreferredMetadataCountryCode = item.PreferredMetadataCountryCode; dto.PreferredMetadataLanguage = item.PreferredMetadataLanguage; } dto.CriticRating = item.CriticRating; if (fields.Contains(ItemFields.CriticRatingSummary)) { dto.CriticRatingSummary = item.CriticRatingSummary; } var hasTrailers = item as IHasTrailers; if (hasTrailers != null) { dto.LocalTrailerCount = hasTrailers.GetTrailerIds().Count; } var hasDisplayOrder = item as IHasDisplayOrder; if (hasDisplayOrder != null) { dto.DisplayOrder = hasDisplayOrder.DisplayOrder; } var userView = item as UserView; if (userView != null) { dto.CollectionType = userView.ViewType; } if (fields.Contains(ItemFields.RemoteTrailers)) { dto.RemoteTrailers = hasTrailers != null ? hasTrailers.RemoteTrailers : new List<MediaUrl>(); } dto.Name = item.Name; dto.OfficialRating = item.OfficialRating; if (fields.Contains(ItemFields.Overview)) { dto.Overview = item.Overview; } if (fields.Contains(ItemFields.OriginalTitle)) { dto.OriginalTitle = item.OriginalTitle; } if (fields.Contains(ItemFields.ShortOverview)) { dto.ShortOverview = item.ShortOverview; } if (fields.Contains(ItemFields.ParentId)) { var displayParentId = item.DisplayParentId; if (displayParentId.HasValue) { dto.ParentId = displayParentId.Value.ToString("N"); } } AddInheritedImages(dto, item, options, owner); if (fields.Contains(ItemFields.Path)) { dto.Path = GetMappedPath(item); } 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)) { if (!string.IsNullOrWhiteSpace(item.Tagline)) { dto.Taglines = new List<string> { item.Tagline }; } if (dto.Taglines == null) { dto.Taglines = new List<string>(); } } dto.Type = item.GetClientTypeName(); dto.CommunityRating = item.CommunityRating; if (fields.Contains(ItemFields.VoteCount)) { 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.ExtraType = audio.ExtraType; var albumParent = audio.AlbumEntity; if (albumParent != null) { dto.AlbumId = GetDtoId(albumParent); dto.AlbumPrimaryImageTag = GetImageCacheTag(albumParent, ImageType.Primary); } //if (fields.Contains(ItemFields.MediaSourceCount)) //{ // Songs always have one //} } var hasArtist = item as IHasArtist; if (hasArtist != null) { dto.Artists = hasArtist.Artists; var artistItems = _libraryManager.GetArtists(new InternalItemsQuery { EnableTotalRecordCount = false, ItemIds = new[] { item.Id.ToString("N") } }); dto.ArtistItems = artistItems.Items .Select(i => { var artist = i.Item1; return new NameIdPair { Name = artist.Name, Id = artist.Id.ToString("N") }; }) .ToList(); // Include artists that are not in the database yet, e.g., just added via metadata editor var foundArtists = artistItems.Items.Select(i => i.Item1.Name).ToList(); dto.ArtistItems.AddRange(hasArtist.Artists .Except(foundArtists, new DistinctNameComparer()) .Select(i => { // This should not be necessary but we're seeing some cases of it if (string.IsNullOrWhiteSpace(i)) { return null; } var artist = _libraryManager.GetArtist(i); if (artist != null) { return new NameIdPair { Name = artist.Name, Id = artist.Id.ToString("N") }; } return null; }).Where(i => i != null)); } var hasAlbumArtist = item as IHasAlbumArtist; if (hasAlbumArtist != null) { dto.AlbumArtist = hasAlbumArtist.AlbumArtists.FirstOrDefault(); var artistItems = _libraryManager.GetAlbumArtists(new InternalItemsQuery { EnableTotalRecordCount = false, ItemIds = new[] { item.Id.ToString("N") } }); dto.AlbumArtists = artistItems.Items .Select(i => { var artist = i.Item1; return new NameIdPair { Name = artist.Name, Id = artist.Id.ToString("N") }; }) .ToList(); } // Add video info var video = item as Video; if (video != null) { dto.VideoType = video.VideoType; dto.Video3DFormat = video.Video3DFormat; dto.IsoType = video.IsoType; if (video.HasSubtitles) { dto.HasSubtitles = video.HasSubtitles; } if (video.AdditionalParts.Count != 0) { dto.PartCount = video.AdditionalParts.Count + 1; } if (fields.Contains(ItemFields.MediaSourceCount)) { var mediaSourceCount = video.MediaSourceCount; if (mediaSourceCount != 1) { dto.MediaSourceCount = mediaSourceCount; } } if (fields.Contains(ItemFields.Chapters)) { dto.Chapters = GetChapterInfoDtos(item); } dto.ExtraType = video.ExtraType; } if (fields.Contains(ItemFields.MediaStreams)) { // Add VideoInfo var iHasMediaSources = item as IHasMediaSources; if (iHasMediaSources != null) { List<MediaStream> mediaStreams; if (dto.MediaSources != null && dto.MediaSources.Count > 0) { mediaStreams = dto.MediaSources.Where(i => new Guid(i.Id) == item.Id) .SelectMany(i => i.MediaStreams) .ToList(); } else { mediaStreams = _mediaSourceManager().GetStaticMediaSources(iHasMediaSources, true).First().MediaStreams; } dto.MediaStreams = mediaStreams; } } var hasSpecialFeatures = item as IHasSpecialFeatures; if (hasSpecialFeatures != null) { var specialFeatureCount = hasSpecialFeatures.SpecialFeatureIds.Count; if (specialFeatureCount > 0) { dto.SpecialFeatureCount = specialFeatureCount; } } // Add EpisodeInfo var episode = item as Episode; if (episode != null) { dto.IndexNumberEnd = episode.IndexNumberEnd; dto.SeriesName = episode.SeriesName; if (fields.Contains(ItemFields.AlternateEpisodeNumbers)) { dto.DvdSeasonNumber = episode.DvdSeasonNumber; dto.DvdEpisodeNumber = episode.DvdEpisodeNumber; dto.AbsoluteEpisodeNumber = episode.AbsoluteEpisodeNumber; } if (fields.Contains(ItemFields.SpecialEpisodeNumbers)) { dto.AirsAfterSeasonNumber = episode.AirsAfterSeasonNumber; dto.AirsBeforeEpisodeNumber = episode.AirsBeforeEpisodeNumber; dto.AirsBeforeSeasonNumber = episode.AirsBeforeSeasonNumber; } var seasonId = episode.SeasonId; if (seasonId.HasValue) { dto.SeasonId = seasonId.Value.ToString("N"); } dto.SeasonName = episode.SeasonName; var seriesId = episode.SeriesId; if (seriesId.HasValue) { dto.SeriesId = seriesId.Value.ToString("N"); } Series episodeSeries = null; if (fields.Contains(ItemFields.SeriesGenres)) { episodeSeries = episodeSeries ?? episode.Series; if (episodeSeries != null) { dto.SeriesGenres = episodeSeries.Genres.ToList(); } } //if (fields.Contains(ItemFields.SeriesPrimaryImage)) { episodeSeries = episodeSeries ?? episode.Series; if (episodeSeries != null) { dto.SeriesPrimaryImageTag = GetImageCacheTag(episodeSeries, ImageType.Primary); } } if (fields.Contains(ItemFields.SeriesStudio)) { episodeSeries = episodeSeries ?? episode.Series; if (episodeSeries != null) { dto.SeriesStudio = episodeSeries.Studios.FirstOrDefault(); } } } // Add SeriesInfo var series = item as Series; if (series != null) { dto.AirDays = series.AirDays; dto.AirTime = series.AirTime; dto.SeriesStatus = series.Status; dto.AnimeSeriesIndex = series.AnimeSeriesIndex; } // Add SeasonInfo var season = item as Season; if (season != null) { dto.SeriesName = season.SeriesName; var seriesId = season.SeriesId; if (seriesId.HasValue) { dto.SeriesId = seriesId.Value.ToString("N"); } series = null; if (fields.Contains(ItemFields.SeriesStudio)) { series = series ?? season.Series; if (series != null) { dto.SeriesStudio = series.Studios.FirstOrDefault(); } } if (fields.Contains(ItemFields.SeriesPrimaryImage)) { series = series ?? season.Series; if (series != null) { 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); } if (item.ProductionLocations.Count > 0 || item is Movie) { dto.ProductionLocations = item.ProductionLocations.ToArray(); } var photo = item as Photo; if (photo != null) { SetPhotoProperties(dto, photo); } dto.ChannelId = item.ChannelId; if (item.SourceType == SourceType.Channel && !string.IsNullOrWhiteSpace(item.ChannelId)) { var channel = _libraryManager.GetItemById(item.ChannelId); if (channel != null) { dto.ChannelName = channel.Name; } } }
/// <summary> /// Converts a BaseItem to a BaseItemInfo /// </summary> /// <param name="item">The item.</param> /// <param name="runtimeTicks">The now playing runtime ticks.</param> /// <returns>BaseItemInfo.</returns> /// <exception cref="System.ArgumentNullException">item</exception> private BaseItemInfo GetItemInfo(BaseItem item, long? runtimeTicks) { if (item == null) { throw new ArgumentNullException("item"); } var info = new BaseItemInfo { Id = GetDtoId(item), Name = item.Name, MediaType = item.MediaType, Type = item.GetClientTypeName(), RunTimeTicks = runtimeTicks, IndexNumber = item.IndexNumber, ParentIndexNumber = item.ParentIndexNumber, PremiereDate = item.PremiereDate, ProductionYear = item.ProductionYear }; info.PrimaryImageTag = GetImageCacheTag(item, ImageType.Primary); if (info.PrimaryImageTag.HasValue) { info.PrimaryImageItemId = GetDtoId(item); } var episode = item as Episode; if (episode != null) { info.IndexNumberEnd = episode.IndexNumberEnd; } var hasSeries = item as IHasSeries; if (hasSeries != null) { info.SeriesName = hasSeries.SeriesName; } var recording = item as ILiveTvRecording; if (recording != null && recording.RecordingInfo != null) { if (recording.RecordingInfo.IsSeries) { info.Name = recording.RecordingInfo.EpisodeTitle; info.SeriesName = recording.RecordingInfo.Name; if (string.IsNullOrWhiteSpace(info.Name)) { info.Name = recording.RecordingInfo.Name; } } } var audio = item as Audio; if (audio != null) { info.Album = audio.Album; info.Artists = audio.Artists; if (!info.PrimaryImageTag.HasValue) { var album = audio.Parents.OfType<MusicAlbum>().FirstOrDefault(); if (album != null && album.HasImage(ImageType.Primary)) { info.PrimaryImageTag = GetImageCacheTag(album, ImageType.Primary); if (info.PrimaryImageTag.HasValue) { info.PrimaryImageItemId = GetDtoId(album); } } } } var musicVideo = item as MusicVideo; if (musicVideo != null) { info.Album = musicVideo.Album; if (!string.IsNullOrWhiteSpace(musicVideo.Artist)) { info.Artists.Add(musicVideo.Artist); } } var backropItem = item.HasImage(ImageType.Backdrop) ? item : null; var thumbItem = item.HasImage(ImageType.Thumb) ? item : null; var logoItem = item.HasImage(ImageType.Logo) ? item : null; if (thumbItem == null) { if (episode != null) { var series = episode.Series; if (series != null && series.HasImage(ImageType.Thumb)) { thumbItem = series; } } } if (backropItem == null) { if (episode != null) { var series = episode.Series; if (series != null && series.HasImage(ImageType.Backdrop)) { backropItem = series; } } } if (backropItem == null) { backropItem = item.Parents.FirstOrDefault(i => i.HasImage(ImageType.Backdrop)); } if (thumbItem == null) { thumbItem = item.Parents.FirstOrDefault(i => i.HasImage(ImageType.Thumb)); } if (logoItem == null) { logoItem = item.Parents.FirstOrDefault(i => i.HasImage(ImageType.Logo)); } if (thumbItem != null) { info.ThumbImageTag = GetImageCacheTag(thumbItem, ImageType.Thumb); info.ThumbItemId = GetDtoId(thumbItem); } if (backropItem != null) { info.BackdropImageTag = GetImageCacheTag(backropItem, ImageType.Backdrop); info.BackdropItemId = GetDtoId(backropItem); } if (logoItem != null) { info.LogoImageTag = GetImageCacheTag(logoItem, ImageType.Logo); info.LogoItemId = GetDtoId(logoItem); } return info; }
/// <summary> /// Converts a BaseItem to a BaseItemInfo /// </summary> /// <param name="item">The item.</param> /// <param name="chapterOwner">The chapter owner.</param> /// <param name="mediaSourceId">The media source identifier.</param> /// <returns>BaseItemInfo.</returns> /// <exception cref="System.ArgumentNullException">item</exception> private BaseItemInfo GetItemInfo(BaseItem item, BaseItem chapterOwner, string mediaSourceId) { if (item == null) { throw new ArgumentNullException("item"); } var info = new BaseItemInfo { Id = GetDtoId(item), Name = item.Name, MediaType = item.MediaType, Type = item.GetClientTypeName(), RunTimeTicks = item.RunTimeTicks, IndexNumber = item.IndexNumber, ParentIndexNumber = item.ParentIndexNumber, PremiereDate = item.PremiereDate, ProductionYear = item.ProductionYear }; info.PrimaryImageTag = GetImageCacheTag(item, ImageType.Primary); if (info.PrimaryImageTag != null) { info.PrimaryImageItemId = GetDtoId(item); } var episode = item as Episode; if (episode != null) { info.IndexNumberEnd = episode.IndexNumberEnd; } var hasSeries = item as IHasSeries; if (hasSeries != null) { info.SeriesName = hasSeries.SeriesName; } var recording = item as ILiveTvRecording; if (recording != null && recording.RecordingInfo != null) { if (recording.RecordingInfo.IsSeries) { info.Name = recording.RecordingInfo.EpisodeTitle; info.SeriesName = recording.RecordingInfo.Name; if (string.IsNullOrWhiteSpace(info.Name)) { info.Name = recording.RecordingInfo.Name; } } } var audio = item as Audio; if (audio != null) { info.Album = audio.Album; info.Artists = audio.Artists; if (info.PrimaryImageTag == null) { var album = audio.Parents.OfType<MusicAlbum>().FirstOrDefault(); if (album != null && album.HasImage(ImageType.Primary)) { info.PrimaryImageTag = GetImageCacheTag(album, ImageType.Primary); if (info.PrimaryImageTag != null) { info.PrimaryImageItemId = GetDtoId(album); } } } } var musicVideo = item as MusicVideo; if (musicVideo != null) { info.Album = musicVideo.Album; if (!string.IsNullOrWhiteSpace(musicVideo.Artist)) { info.Artists.Add(musicVideo.Artist); } } var backropItem = item.HasImage(ImageType.Backdrop) ? item : null; var thumbItem = item.HasImage(ImageType.Thumb) ? item : null; var logoItem = item.HasImage(ImageType.Logo) ? item : null; if (thumbItem == null) { if (episode != null) { var series = episode.Series; if (series != null && series.HasImage(ImageType.Thumb)) { thumbItem = series; } } } if (backropItem == null) { if (episode != null) { var series = episode.Series; if (series != null && series.HasImage(ImageType.Backdrop)) { backropItem = series; } } } if (backropItem == null) { backropItem = item.Parents.FirstOrDefault(i => i.HasImage(ImageType.Backdrop)); } if (thumbItem == null) { thumbItem = item.Parents.FirstOrDefault(i => i.HasImage(ImageType.Thumb)); } if (logoItem == null) { logoItem = item.Parents.FirstOrDefault(i => i.HasImage(ImageType.Logo)); } if (thumbItem != null) { info.ThumbImageTag = GetImageCacheTag(thumbItem, ImageType.Thumb); info.ThumbItemId = GetDtoId(thumbItem); } if (backropItem != null) { info.BackdropImageTag = GetImageCacheTag(backropItem, ImageType.Backdrop); info.BackdropItemId = GetDtoId(backropItem); } if (logoItem != null) { info.LogoImageTag = GetImageCacheTag(logoItem, ImageType.Logo); info.LogoItemId = GetDtoId(logoItem); } if (chapterOwner != null) { info.ChapterImagesItemId = chapterOwner.Id.ToString("N"); info.Chapters = _itemRepo.GetChapters(chapterOwner.Id).Select(i => _dtoService.GetChapterInfoDto(i, chapterOwner)).ToList(); } if (!string.IsNullOrWhiteSpace(mediaSourceId)) { info.MediaStreams = _itemRepo.GetMediaStreams(new MediaStreamQuery { ItemId = new Guid(mediaSourceId) }).ToList(); } return info; }
public static bool FilterAndGetMediaType(BaseItem item, out MediaType type) { type = MediaType.None; if (!Plugin.Instance.Configuration.IsEnabled || item.LocationType == LocationType.Virtual || item.SourceType != SourceType.Library) { return(false); } var typeName = item.GetClientTypeName(); if (string.IsNullOrEmpty(typeName)) { return(false); } switch (typeName) { case "Movie": if (!Plugin.Instance.Configuration.tkMovies) { return(false); } type = MediaType.Movies; break; case "BoxSet": if (!Plugin.Instance.Configuration.tkBoxSets) { return(false); } type = MediaType.BoxSets; break; case "Series": case "Season": case "Episode": if (!Plugin.Instance.Configuration.tkTVShows) { return(false); } type = MediaType.TvShows; break; case "Audio": case "MusicArtist": case "MusicAlbum": if (!Plugin.Instance.Configuration.tkMusic) { return(false); } type = MediaType.Music; break; case "MusicVideo": if (!Plugin.Instance.Configuration.tkMusicVideos) { return(false); } type = MediaType.MusicVideos; break; default: return(false); } return(true); }
/// <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="options">The options.</param> private void AttachBasicFields(BaseItemDto dto, BaseItem item, BaseItem owner, DtoOptions options) { if (options.ContainsField(ItemFields.DateCreated)) { dto.DateCreated = item.DateCreated; } if (options.ContainsField(ItemFields.Settings)) { dto.LockedFields = item.LockedFields; dto.LockData = item.IsLocked; dto.ForcedSortName = item.ForcedSortName; } dto.Container = item.Container; dto.EndDate = item.EndDate; if (options.ContainsField(ItemFields.ExternalUrls)) { dto.ExternalUrls = _providerManager.GetExternalUrls(item).ToArray(); } if (options.ContainsField(ItemFields.Tags)) { dto.Tags = item.Tags; } var hasAspectRatio = item as IHasAspectRatio; if (hasAspectRatio != null) { dto.AspectRatio = hasAspectRatio.AspectRatio; } var backdropLimit = options.GetImageLimit(ImageType.Backdrop); if (backdropLimit > 0) { dto.BackdropImageTags = GetImageTags(item, item.GetImages(ImageType.Backdrop).Take(backdropLimit).ToList()); } if (options.ContainsField(ItemFields.ScreenshotImageTags)) { var screenshotLimit = options.GetImageLimit(ImageType.Screenshot); if (screenshotLimit > 0) { dto.ScreenshotImageTags = GetImageTags(item, item.GetImages(ImageType.Screenshot).Take(screenshotLimit).ToList()); } } if (options.ContainsField(ItemFields.Genres)) { dto.Genres = item.Genres; AttachGenreItems(dto, item); } if (options.EnableImages) { dto.ImageTags = new Dictionary <ImageType, string>(); // Prevent implicitly captured closure var currentItem = item; foreach (var image in currentItem.ImageInfos.Where(i => !currentItem.AllowsMultipleImages(i.Type)) .ToList()) { if (options.GetImageLimit(image.Type) > 0) { var tag = GetImageCacheTag(item, image); if (tag != null) { dto.ImageTags[image.Type] = tag; } } } } dto.Id = item.Id; dto.IndexNumber = item.IndexNumber; dto.ParentIndexNumber = item.ParentIndexNumber; if (item.IsFolder) { dto.IsFolder = true; } else if (item is IHasMediaSources) { dto.IsFolder = false; } dto.MediaType = item.MediaType; if (!(item is LiveTvProgram)) { dto.LocationType = item.LocationType; } dto.Audio = item.Audio; if (options.ContainsField(ItemFields.Settings)) { dto.PreferredMetadataCountryCode = item.PreferredMetadataCountryCode; dto.PreferredMetadataLanguage = item.PreferredMetadataLanguage; } dto.CriticRating = item.CriticRating; var hasDisplayOrder = item as IHasDisplayOrder; if (hasDisplayOrder != null) { dto.DisplayOrder = hasDisplayOrder.DisplayOrder; } var hasCollectionType = item as IHasCollectionType; if (hasCollectionType != null) { dto.CollectionType = hasCollectionType.CollectionType; } if (options.ContainsField(ItemFields.RemoteTrailers)) { dto.RemoteTrailers = item.RemoteTrailers; } dto.Name = item.Name; dto.OfficialRating = item.OfficialRating; if (options.ContainsField(ItemFields.Overview)) { dto.Overview = item.Overview; } if (options.ContainsField(ItemFields.OriginalTitle)) { dto.OriginalTitle = item.OriginalTitle; } if (options.ContainsField(ItemFields.ParentId)) { dto.ParentId = item.DisplayParentId; } AddInheritedImages(dto, item, options, owner); if (options.ContainsField(ItemFields.Path)) { dto.Path = GetMappedPath(item, owner); } if (options.ContainsField(ItemFields.EnableMediaSourceDisplay)) { dto.EnableMediaSourceDisplay = item.EnableMediaSourceDisplay; } dto.PremiereDate = item.PremiereDate; dto.ProductionYear = item.ProductionYear; if (options.ContainsField(ItemFields.ProviderIds)) { dto.ProviderIds = item.ProviderIds; } dto.RunTimeTicks = item.RunTimeTicks; if (options.ContainsField(ItemFields.SortName)) { dto.SortName = item.SortName; } if (options.ContainsField(ItemFields.CustomRating)) { dto.CustomRating = item.CustomRating; } if (options.ContainsField(ItemFields.Taglines)) { if (!string.IsNullOrEmpty(item.Tagline)) { dto.Taglines = new string[] { item.Tagline }; } if (dto.Taglines == null) { dto.Taglines = Array.Empty <string>(); } } dto.Type = item.GetClientTypeName(); if ((item.CommunityRating ?? 0) > 0) { dto.CommunityRating = item.CommunityRating; } var supportsPlaceHolders = item as ISupportsPlaceHolders; if (supportsPlaceHolders != null && supportsPlaceHolders.IsPlaceHolder) { dto.IsPlaceHolder = supportsPlaceHolders.IsPlaceHolder; } // Add audio info var audio = item as Audio; if (audio != null) { dto.Album = audio.Album; if (audio.ExtraType.HasValue) { dto.ExtraType = audio.ExtraType.Value.ToString(); } var albumParent = audio.AlbumEntity; if (albumParent != null) { dto.AlbumId = albumParent.Id; dto.AlbumPrimaryImageTag = GetImageCacheTag(albumParent, ImageType.Primary); } //if (options.ContainsField(ItemFields.MediaSourceCount)) //{ // Songs always have one //} } var hasArtist = item as IHasArtist; if (hasArtist != null) { dto.Artists = hasArtist.Artists; //var artistItems = _libraryManager.GetArtists(new InternalItemsQuery //{ // EnableTotalRecordCount = false, // ItemIds = new[] { item.Id.ToString("N") } //}); //dto.ArtistItems = artistItems.Items // .Select(i => // { // var artist = i.Item1; // return new NameIdPair // { // Name = artist.Name, // Id = artist.Id.ToString("N") // }; // }) // .ToList(); // Include artists that are not in the database yet, e.g., just added via metadata editor //var foundArtists = artistItems.Items.Select(i => i.Item1.Name).ToList(); dto.ArtistItems = hasArtist.Artists //.Except(foundArtists, new DistinctNameComparer()) .Select(i => { // This should not be necessary but we're seeing some cases of it if (string.IsNullOrEmpty(i)) { return(null); } var artist = _libraryManager.GetArtist(i, new DtoOptions(false) { EnableImages = false }); if (artist != null) { return(new NameGuidPair { Name = artist.Name, Id = artist.Id }); } return(null); }).Where(i => i != null).ToArray(); } var hasAlbumArtist = item as IHasAlbumArtist; if (hasAlbumArtist != null) { dto.AlbumArtist = hasAlbumArtist.AlbumArtists.FirstOrDefault(); //var artistItems = _libraryManager.GetAlbumArtists(new InternalItemsQuery //{ // EnableTotalRecordCount = false, // ItemIds = new[] { item.Id.ToString("N") } //}); //dto.AlbumArtists = artistItems.Items // .Select(i => // { // var artist = i.Item1; // return new NameIdPair // { // Name = artist.Name, // Id = artist.Id.ToString("N") // }; // }) // .ToList(); dto.AlbumArtists = hasAlbumArtist.AlbumArtists //.Except(foundArtists, new DistinctNameComparer()) .Select(i => { // This should not be necessary but we're seeing some cases of it if (string.IsNullOrEmpty(i)) { return(null); } var artist = _libraryManager.GetArtist(i, new DtoOptions(false) { EnableImages = false }); if (artist != null) { return(new NameGuidPair { Name = artist.Name, Id = artist.Id }); } return(null); }).Where(i => i != null).ToArray(); } // Add video info var video = item as Video; if (video != null) { dto.VideoType = video.VideoType; dto.Video3DFormat = video.Video3DFormat; dto.IsoType = video.IsoType; if (video.HasSubtitles) { dto.HasSubtitles = video.HasSubtitles; } if (video.AdditionalParts.Length != 0) { dto.PartCount = video.AdditionalParts.Length + 1; } if (options.ContainsField(ItemFields.MediaSourceCount)) { var mediaSourceCount = video.MediaSourceCount; if (mediaSourceCount != 1) { dto.MediaSourceCount = mediaSourceCount; } } if (options.ContainsField(ItemFields.Chapters)) { dto.Chapters = _itemRepo.GetChapters(item); } if (video.ExtraType.HasValue) { dto.ExtraType = video.ExtraType.Value.ToString(); } } if (options.ContainsField(ItemFields.MediaStreams)) { // Add VideoInfo var iHasMediaSources = item as IHasMediaSources; if (iHasMediaSources != null) { MediaStream[] mediaStreams; if (dto.MediaSources != null && dto.MediaSources.Length > 0) { if (item.SourceType == SourceType.Channel) { mediaStreams = dto.MediaSources[0].MediaStreams.ToArray(); } else { mediaStreams = dto.MediaSources.Where(i => string.Equals(i.Id, item.Id.ToString("N"), StringComparison.OrdinalIgnoreCase)) .SelectMany(i => i.MediaStreams) .ToArray(); } } else { mediaStreams = _mediaSourceManager().GetStaticMediaSources(item, true).First().MediaStreams.ToArray(); } dto.MediaStreams = mediaStreams; } } BaseItem[] allExtras = null; if (options.ContainsField(ItemFields.SpecialFeatureCount)) { if (allExtras == null) { allExtras = item.GetExtras().ToArray(); } dto.SpecialFeatureCount = allExtras.Count(i => i.ExtraType.HasValue && BaseItem.DisplayExtraTypes.Contains(i.ExtraType.Value)); } if (options.ContainsField(ItemFields.LocalTrailerCount)) { if (allExtras == null) { allExtras = item.GetExtras().ToArray(); } dto.LocalTrailerCount = allExtras.Count(i => i.ExtraType.HasValue && i.ExtraType.Value == ExtraType.Trailer); } // Add EpisodeInfo var episode = item as Episode; if (episode != null) { dto.IndexNumberEnd = episode.IndexNumberEnd; dto.SeriesName = episode.SeriesName; if (options.ContainsField(ItemFields.SpecialEpisodeNumbers)) { dto.AirsAfterSeasonNumber = episode.AirsAfterSeasonNumber; dto.AirsBeforeEpisodeNumber = episode.AirsBeforeEpisodeNumber; dto.AirsBeforeSeasonNumber = episode.AirsBeforeSeasonNumber; } dto.SeasonName = episode.SeasonName; dto.SeasonId = episode.SeasonId; dto.SeriesId = episode.SeriesId; Series episodeSeries = null; //if (options.ContainsField(ItemFields.SeriesPrimaryImage)) { episodeSeries = episodeSeries ?? episode.Series; if (episodeSeries != null) { dto.SeriesPrimaryImageTag = GetImageCacheTag(episodeSeries, ImageType.Primary); } } if (options.ContainsField(ItemFields.SeriesStudio)) { episodeSeries = episodeSeries ?? episode.Series; if (episodeSeries != null) { dto.SeriesStudio = episodeSeries.Studios.FirstOrDefault(); } } } // Add SeriesInfo var series = item as Series; if (series != null) { dto.AirDays = series.AirDays; dto.AirTime = series.AirTime; dto.Status = series.Status.HasValue ? series.Status.Value.ToString() : null; } // Add SeasonInfo var season = item as Season; if (season != null) { dto.SeriesName = season.SeriesName; dto.SeriesId = season.SeriesId; series = null; if (options.ContainsField(ItemFields.SeriesStudio)) { series = series ?? season.Series; if (series != null) { dto.SeriesStudio = series.Studios.FirstOrDefault(); } } //if (options.ContainsField(ItemFields.SeriesPrimaryImage)) { series = series ?? season.Series; if (series != null) { dto.SeriesPrimaryImageTag = GetImageCacheTag(series, ImageType.Primary); } } } var musicVideo = item as MusicVideo; if (musicVideo != null) { SetMusicVideoProperties(dto, musicVideo); } var book = item as Book; if (book != null) { SetBookProperties(dto, book); } if (options.ContainsField(ItemFields.ProductionLocations)) { if (item.ProductionLocations.Length > 0 || item is Movie) { dto.ProductionLocations = item.ProductionLocations; } } if (options.ContainsField(ItemFields.Width)) { var width = item.Width; if (width > 0) { dto.Width = width; } } if (options.ContainsField(ItemFields.Height)) { var height = item.Height; if (height > 0) { dto.Height = height; } } if (options.ContainsField(ItemFields.IsHD)) { // Compatibility if (item.IsHD) { dto.IsHD = true; } } var photo = item as Photo; if (photo != null) { SetPhotoProperties(dto, photo); } dto.ChannelId = item.ChannelId; if (item.SourceType == SourceType.Channel) { var channel = _libraryManager.GetItemById(item.ChannelId); if (channel != null) { dto.ChannelName = channel.Name; } } }
/// <summary> /// Converts a BaseItem to a BaseItemInfo /// </summary> /// <param name="item">The item.</param> /// <returns>BaseItemInfo.</returns> /// <exception cref="System.ArgumentNullException">item</exception> public BaseItemInfo GetBaseItemInfo(BaseItem item) { if (item == null) { throw new ArgumentNullException("item"); } var info = new BaseItemInfo { Id = GetDtoId(item), Name = item.Name, MediaType = item.MediaType, Type = item.GetClientTypeName(), RunTimeTicks = item.RunTimeTicks }; var imagePath = item.PrimaryImagePath; if (!string.IsNullOrEmpty(imagePath)) { info.PrimaryImageTag = GetImageCacheTag(item, ImageType.Primary, imagePath); } return info; }