diff options
Diffstat (limited to 'Emby.Server.Implementations/Dto/DtoService.cs')
| -rw-r--r-- | Emby.Server.Implementations/Dto/DtoService.cs | 115 |
1 files changed, 84 insertions, 31 deletions
diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.cs index c49c318ee..a0e994d88 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 Task<BaseItemDto[]> GetBaseItemDtos(List<BaseItem> items, DtoOptions options, User user = null, BaseItem owner = null) + { + return GetBaseItemDtos(items, items.Count, options, user, owner); + } + + public Task<BaseItemDto[]> GetBaseItemDtos(BaseItem[] items, DtoOptions options, User user = null, BaseItem owner = null) + { + return GetBaseItemDtos(items, items.Length, options, user, owner); + } + + public async Task<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,7 +151,8 @@ namespace Emby.Server.Implementations.Dto FillSyncInfo(dto, item, options, user, syncDictionary); - list.Add(dto); + returnItems[index] = dto; + index++; } if (programTuples.Count > 0) @@ -157,18 +165,14 @@ namespace Emby.Server.Implementations.Dto await _livetvManager().AddChannelInfo(channelTuples, options, user).ConfigureAwait(false); } - 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) { @@ -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; @@ -365,6 +369,8 @@ namespace Emby.Server.Implementations.Dto { dto.MediaSources = _mediaSourceManager().GetStaticMediaSources(hasMediaSources, true, user); } + + NormalizeMediaSourceContainers(dto); } } @@ -400,25 +406,72 @@ 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; + 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)) { @@ -992,7 +1045,7 @@ namespace Emby.Server.Implementations.Dto { dto.RemoteTrailers = hasTrailers != null ? hasTrailers.RemoteTrailers : - new MediaUrl[] {}; + new MediaUrl[] { }; } dto.Name = item.Name; @@ -1053,7 +1106,7 @@ namespace Emby.Server.Implementations.Dto if (dto.Taglines == null) { - dto.Taglines = new string[]{}; + dto.Taglines = new string[] { }; } } @@ -1243,17 +1296,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; @@ -1564,7 +1617,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; |
