diff options
Diffstat (limited to 'Emby.Server.Implementations/Dto/DtoService.cs')
| -rw-r--r-- | Emby.Server.Implementations/Dto/DtoService.cs | 211 |
1 files changed, 115 insertions, 96 deletions
diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.cs index a57ee0b9b..a0bbd171f 100644 --- a/Emby.Server.Implementations/Dto/DtoService.cs +++ b/Emby.Server.Implementations/Dto/DtoService.cs @@ -77,7 +77,7 @@ namespace Emby.Server.Implementations.Dto /// <param name="owner">The owner.</param> /// <returns>Task{DtoBaseItem}.</returns> /// <exception cref="System.ArgumentNullException">item</exception> - public BaseItemDto GetBaseItemDto(BaseItem item, List<ItemFields> fields, User user = null, BaseItem owner = null) + public BaseItemDto GetBaseItemDto(BaseItem item, ItemFields[] fields, User user = null, BaseItem owner = null) { var options = new DtoOptions { @@ -87,7 +87,17 @@ namespace Emby.Server.Implementations.Dto return GetBaseItemDto(item, options, user, owner); } - public async Task<List<BaseItemDto>> GetBaseItemDtos(IEnumerable<BaseItem> items, DtoOptions options, User user = null, BaseItem owner = null) + public BaseItemDto[] GetBaseItemDtos(List<BaseItem> items, DtoOptions options, User user = null, BaseItem owner = null) + { + return GetBaseItemDtos(items, items.Count, options, user, owner); + } + + public BaseItemDto[] GetBaseItemDtos(BaseItem[] items, DtoOptions options, User user = null, BaseItem owner = null) + { + return GetBaseItemDtos(items, items.Length, options, user, owner); + } + + public BaseItemDto[] GetBaseItemDtos(IEnumerable<BaseItem> items, int itemCount, DtoOptions options, User user = null, BaseItem owner = null) { if (items == null) { @@ -101,17 +111,14 @@ namespace Emby.Server.Implementations.Dto var syncDictionary = GetSyncedItemProgress(options); - var list = new List<BaseItemDto>(); + var returnItems = new BaseItemDto[itemCount]; var programTuples = new List<Tuple<BaseItem, BaseItemDto>>(); var channelTuples = new List<Tuple<BaseItemDto, LiveTvChannel>>(); - var refreshQueue = options.Fields.Contains(ItemFields.RefreshState) - ? _providerManager.GetRefreshQueue() - : null; - + var index = 0; foreach (var item in items) { - var dto = GetBaseItemDtoInternal(item, options, refreshQueue, user, owner); + var dto = GetBaseItemDtoInternal(item, options, user, owner); var tvChannel = item as LiveTvChannel; if (tvChannel != null) @@ -144,37 +151,34 @@ namespace Emby.Server.Implementations.Dto FillSyncInfo(dto, item, options, user, syncDictionary); - list.Add(dto); + returnItems[index] = dto; + index++; } if (programTuples.Count > 0) { - await _livetvManager().AddInfoToProgramDto(programTuples, options.Fields, user).ConfigureAwait(false); + var task = _livetvManager().AddInfoToProgramDto(programTuples, options.Fields, user); + Task.WaitAll(task); } if (channelTuples.Count > 0) { - await _livetvManager().AddChannelInfo(channelTuples, options, user).ConfigureAwait(false); + _livetvManager().AddChannelInfo(channelTuples, options, user); } - return list; + return returnItems; } public BaseItemDto GetBaseItemDto(BaseItem item, DtoOptions options, User user = null, BaseItem owner = null) { var syncDictionary = GetSyncedItemProgress(options); - var refreshQueue = options.Fields.Contains(ItemFields.RefreshState) - ? _providerManager.GetRefreshQueue() - : null; - - var dto = GetBaseItemDtoInternal(item, options, refreshQueue, user, owner); + var dto = GetBaseItemDtoInternal(item, options, user, owner); var tvChannel = item as LiveTvChannel; if (tvChannel != null) { var list = new List<Tuple<BaseItemDto, LiveTvChannel>> { new Tuple<BaseItemDto, LiveTvChannel>(dto, tvChannel) }; - var task = _livetvManager().AddChannelInfo(list, options, user); - Task.WaitAll(task); + _livetvManager().AddChannelInfo(list, options, user); } else if (item is LiveTvProgram) { @@ -300,7 +304,7 @@ namespace Emby.Server.Implementations.Dto } } - private BaseItemDto GetBaseItemDtoInternal(BaseItem item, DtoOptions options, Dictionary<Guid, Guid> currentRefreshQueue, User user = null, BaseItem owner = null) + private BaseItemDto GetBaseItemDtoInternal(BaseItem item, DtoOptions options, User user = null, BaseItem owner = null) { var fields = options.Fields; @@ -359,12 +363,14 @@ namespace Emby.Server.Implementations.Dto { if (user == null) { - dto.MediaSources = _mediaSourceManager().GetStaticMediaSources(hasMediaSources, true).ToList(); + dto.MediaSources = _mediaSourceManager().GetStaticMediaSources(hasMediaSources, true); } else { - dto.MediaSources = _mediaSourceManager().GetStaticMediaSources(hasMediaSources, true, user).ToList(); + dto.MediaSources = _mediaSourceManager().GetStaticMediaSources(hasMediaSources, true, user); } + + NormalizeMediaSourceContainers(dto); } } @@ -400,25 +406,74 @@ namespace Emby.Server.Implementations.Dto dto.Etag = item.GetEtag(user); } - if (currentRefreshQueue != null) + var liveTvManager = _livetvManager(); + if (item is ILiveTvRecording) { - //dto.RefreshState = item.GetRefreshState(currentRefreshQueue); + liveTvManager.AddInfoToRecordingDto(item, dto, user); } - - if (item is ILiveTvRecording) + else { - _livetvManager().AddInfoToRecordingDto(item, dto, user); + var activeRecording = liveTvManager.GetActiveRecordingInfo(item.Path); + if (activeRecording != null) + { + dto.Type = "Recording"; + dto.CanDownload = false; + dto.RunTimeTicks = null; + + if (!string.IsNullOrWhiteSpace(dto.SeriesName)) + { + dto.EpisodeTitle = dto.Name; + dto.Name = dto.SeriesName; + } + liveTvManager.AddInfoToRecordingDto(item, dto, activeRecording, user); + } } return dto; } + private void NormalizeMediaSourceContainers(BaseItemDto dto) + { + foreach (var mediaSource in dto.MediaSources) + { + var container = mediaSource.Container; + if (string.IsNullOrWhiteSpace(container)) + { + continue; + } + var containers = container.Split(new[] { ',' }); + if (containers.Length < 2) + { + continue; + } + + var path = mediaSource.Path; + string fileExtensionContainer = null; + + if (!string.IsNullOrWhiteSpace(path)) + { + path = Path.GetExtension(path); + if (!string.IsNullOrWhiteSpace(path)) + { + path = Path.GetExtension(path); + if (!string.IsNullOrWhiteSpace(path)) + { + path = path.TrimStart('.'); + } + if (!string.IsNullOrWhiteSpace(path) && containers.Contains(path, StringComparer.OrdinalIgnoreCase)) + { + fileExtensionContainer = path; + } + } + } + + mediaSource.Container = fileExtensionContainer ?? containers[0]; + } + } + public BaseItemDto GetItemByNameDto(BaseItem item, DtoOptions options, List<BaseItem> taggedItems, Dictionary<string, SyncedItemProgress> syncProgress, User user = null) { - var refreshQueue = options.Fields.Contains(ItemFields.RefreshState) - ? _providerManager.GetRefreshQueue() - : null; - var dto = GetBaseItemDtoInternal(item, options, refreshQueue, user); + var dto = GetBaseItemDtoInternal(item, options, user); if (taggedItems != null && options.Fields.Contains(ItemFields.ItemCounts)) { @@ -517,7 +572,7 @@ namespace Emby.Server.Implementations.Dto } } - if (!(item is LiveTvProgram) || fields.Contains(ItemFields.PlayAccess)) + if (/*!(item is LiveTvProgram) ||*/ fields.Contains(ItemFields.PlayAccess)) { dto.PlayAccess = item.GetPlayAccess(user); } @@ -639,7 +694,6 @@ namespace Emby.Server.Implementations.Dto private void SetGameProperties(BaseItemDto dto, Game item) { - dto.Players = item.PlayersSupported; dto.GameSystem = item.GameSystem; dto.MultiPartGameFiles = item.MultiPartGameFiles; } @@ -649,12 +703,12 @@ namespace Emby.Server.Implementations.Dto dto.GameSystem = item.GameSystemName; } - private List<string> GetImageTags(BaseItem item, List<ItemImageInfo> images) + private string[] GetImageTags(BaseItem item, List<ItemImageInfo> images) { return images .Select(p => GetImageCacheTag(item, p)) .Where(i => i != null) - .ToList(); + .ToArray(); } private string GetImageCacheTag(BaseItem item, ImageType type) @@ -766,7 +820,7 @@ namespace Emby.Server.Implementations.Dto } } - dto.People = list.ToArray(); + dto.People = list.ToArray(list.Count); } /// <summary> @@ -864,11 +918,6 @@ namespace Emby.Server.Implementations.Dto dto.DateCreated = item.DateCreated; } - if (fields.Contains(ItemFields.DisplayMediaType)) - { - dto.DisplayMediaType = item.DisplayMediaType; - } - if (fields.Contains(ItemFields.Settings)) { dto.LockedFields = item.LockedFields; @@ -998,7 +1047,7 @@ namespace Emby.Server.Implementations.Dto { dto.RemoteTrailers = hasTrailers != null ? hasTrailers.RemoteTrailers : - new List<MediaUrl>(); + new MediaUrl[] { }; } dto.Name = item.Name; @@ -1054,12 +1103,12 @@ namespace Emby.Server.Implementations.Dto { if (!string.IsNullOrWhiteSpace(item.Tagline)) { - dto.Taglines = new List<string> { item.Tagline }; + dto.Taglines = new string[] { item.Tagline }; } if (dto.Taglines == null) { - dto.Taglines = new List<string>(); + dto.Taglines = new string[] { }; } } @@ -1125,8 +1174,7 @@ namespace Emby.Server.Implementations.Dto // 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 = new List<NameIdPair>(); - dto.ArtistItems.AddRange(hasArtist.Artists + dto.ArtistItems = hasArtist.Artists //.Except(foundArtists, new DistinctNameComparer()) .Select(i => { @@ -1151,7 +1199,7 @@ namespace Emby.Server.Implementations.Dto return null; - }).Where(i => i != null)); + }).Where(i => i != null).ToArray(); } var hasAlbumArtist = item as IHasAlbumArtist; @@ -1177,8 +1225,7 @@ namespace Emby.Server.Implementations.Dto // }) // .ToList(); - dto.AlbumArtists = new List<NameIdPair>(); - dto.AlbumArtists.AddRange(hasAlbumArtist.AlbumArtists + dto.AlbumArtists = hasAlbumArtist.AlbumArtists //.Except(foundArtists, new DistinctNameComparer()) .Select(i => { @@ -1203,7 +1250,7 @@ namespace Emby.Server.Implementations.Dto return null; - }).Where(i => i != null)); + }).Where(i => i != null).ToArray(); } // Add video info @@ -1219,9 +1266,9 @@ namespace Emby.Server.Implementations.Dto dto.HasSubtitles = video.HasSubtitles; } - if (video.AdditionalParts.Count != 0) + if (video.AdditionalParts.Length != 0) { - dto.PartCount = video.AdditionalParts.Count + 1; + dto.PartCount = video.AdditionalParts.Length + 1; } if (fields.Contains(ItemFields.MediaSourceCount)) @@ -1251,17 +1298,17 @@ namespace Emby.Server.Implementations.Dto if (iHasMediaSources != null) { - List<MediaStream> mediaStreams; + 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(); + .ToArray(); } else { - mediaStreams = _mediaSourceManager().GetStaticMediaSources(iHasMediaSources, true).First().MediaStreams; + mediaStreams = _mediaSourceManager().GetStaticMediaSources(iHasMediaSources, true).First().MediaStreams.ToArray(); } dto.MediaStreams = mediaStreams; @@ -1271,7 +1318,7 @@ namespace Emby.Server.Implementations.Dto var hasSpecialFeatures = item as IHasSpecialFeatures; if (hasSpecialFeatures != null) { - var specialFeatureCount = hasSpecialFeatures.SpecialFeatureIds.Count; + var specialFeatureCount = hasSpecialFeatures.SpecialFeatureIds.Length; if (specialFeatureCount > 0) { @@ -1316,15 +1363,6 @@ namespace Emby.Server.Implementations.Dto 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; @@ -1340,27 +1378,6 @@ namespace Emby.Server.Implementations.Dto if (episodeSeries != null) { dto.SeriesStudio = episodeSeries.Studios.FirstOrDefault(); - if (!string.IsNullOrWhiteSpace(dto.SeriesStudio)) - { - try - { - var studio = _libraryManager.GetStudio(dto.SeriesStudio); - - if (studio != null) - { - dto.SeriesStudioInfo = new StudioDto - { - Name = dto.SeriesStudio, - Id = studio.Id.ToString("N"), - PrimaryImageTag = GetImageCacheTag(studio, ImageType.Primary) - }; - } - } - catch (Exception ex) - { - - } - } } } } @@ -1435,9 +1452,9 @@ namespace Emby.Server.Implementations.Dto if (fields.Contains(ItemFields.ProductionLocations)) { - if (item.ProductionLocations.Count > 0 || item is Movie) + if (item.ProductionLocations.Length > 0 || item is Movie) { - dto.ProductionLocations = item.ProductionLocations.ToArray(); + dto.ProductionLocations = item.ProductionLocations; } } @@ -1504,7 +1521,9 @@ namespace Emby.Server.Implementations.Dto BaseItem parent = null; var isFirst = true; - while (((!dto.HasLogo && logoLimit > 0) || (!dto.HasArtImage && artLimit > 0) || (!dto.HasThumb && thumbLimit > 0) || parent is Series) && + var imageTags = dto.ImageTags; + + while (((!(imageTags != null && imageTags.ContainsKey(ImageType.Logo)) && logoLimit > 0) || (!(imageTags != null && imageTags.ContainsKey(ImageType.Art)) && artLimit > 0) || (!(imageTags != null && imageTags.ContainsKey(ImageType.Thumb)) && thumbLimit > 0) || parent is Series) && (parent = parent ?? (isFirst ? GetImageDisplayParent(item, item) ?? owner : parent)) != null) { if (parent == null) @@ -1514,7 +1533,7 @@ namespace Emby.Server.Implementations.Dto var allImages = parent.ImageInfos; - if (logoLimit > 0 && !dto.HasLogo && dto.ParentLogoItemId == null) + if (logoLimit > 0 && !(imageTags != null && imageTags.ContainsKey(ImageType.Logo)) && dto.ParentLogoItemId == null) { var image = allImages.FirstOrDefault(i => i.Type == ImageType.Logo); @@ -1524,7 +1543,7 @@ namespace Emby.Server.Implementations.Dto dto.ParentLogoImageTag = GetImageCacheTag(parent, image); } } - if (artLimit > 0 && !dto.HasArtImage && dto.ParentArtItemId == null) + if (artLimit > 0 && !(imageTags != null && imageTags.ContainsKey(ImageType.Art)) && dto.ParentArtItemId == null) { var image = allImages.FirstOrDefault(i => i.Type == ImageType.Art); @@ -1534,7 +1553,7 @@ namespace Emby.Server.Implementations.Dto dto.ParentArtImageTag = GetImageCacheTag(parent, image); } } - if (thumbLimit > 0 && !dto.HasThumb && (dto.ParentThumbItemId == null || parent is Series) && !(parent is ICollectionFolder) && !(parent is UserView)) + if (thumbLimit > 0 && !(imageTags != null && imageTags.ContainsKey(ImageType.Thumb)) && (dto.ParentThumbItemId == null || parent is Series) && !(parent is ICollectionFolder) && !(parent is UserView)) { var image = allImages.FirstOrDefault(i => i.Type == ImageType.Thumb); @@ -1544,7 +1563,7 @@ namespace Emby.Server.Implementations.Dto dto.ParentThumbImageTag = GetImageCacheTag(parent, image); } } - if (backdropLimit > 0 && !dto.HasBackdrop) + if (backdropLimit > 0 && !((dto.BackdropImageTags != null && dto.BackdropImageTags.Length > 0) || (dto.ParentBackdropImageTags != null && dto.ParentBackdropImageTags.Length > 0))) { var images = allImages.Where(i => i.Type == ImageType.Backdrop).Take(backdropLimit).ToList(); @@ -1586,12 +1605,12 @@ namespace Emby.Server.Implementations.Dto /// <param name="dto">The dto.</param> /// <param name="item">The item.</param> /// <returns>Task.</returns> - public void AttachPrimaryImageAspectRatio(IItemDto dto, IHasImages item) + public void AttachPrimaryImageAspectRatio(IItemDto dto, IHasMetadata item) { dto.PrimaryImageAspectRatio = GetPrimaryImageAspectRatio(item); } - public double? GetPrimaryImageAspectRatio(IHasImages item) + public double? GetPrimaryImageAspectRatio(IHasMetadata item) { var imageInfo = item.GetImageInfo(ImageType.Primary, 0); @@ -1600,7 +1619,7 @@ namespace Emby.Server.Implementations.Dto return null; } - var supportedEnhancers = _imageProcessor.GetSupportedEnhancers(item, ImageType.Primary).ToList(); + var supportedEnhancers = _imageProcessor.GetSupportedEnhancers(item, ImageType.Primary); ImageSize size; |
