diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-05-03 23:13:28 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-05-03 23:13:28 -0400 |
| commit | 163a1bdbcb4db04d97925aed496746ce5ef52580 (patch) | |
| tree | a1995a80c23854f64158e1698250ae71c9282cd5 /MediaBrowser.Controller | |
| parent | 8290f04e0f030e6ab17104c9a629132c7dac2881 (diff) | |
added studio dto
Diffstat (limited to 'MediaBrowser.Controller')
| -rw-r--r-- | MediaBrowser.Controller/Dto/DtoBuilder.cs | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/MediaBrowser.Controller/Dto/DtoBuilder.cs b/MediaBrowser.Controller/Dto/DtoBuilder.cs index 7af9cb496..39b139f02 100644 --- a/MediaBrowser.Controller/Dto/DtoBuilder.cs +++ b/MediaBrowser.Controller/Dto/DtoBuilder.cs @@ -63,7 +63,7 @@ namespace MediaBrowser.Controller.Dto if (fields.Contains(ItemFields.Studios)) { - dto.Studios = item.Studios; + tasks.Add(AttachStudios(dto, item)); } if (fields.Contains(ItemFields.People)) @@ -124,7 +124,7 @@ namespace MediaBrowser.Controller.Dto if (fields.Contains(ItemFields.Studios)) { - dto.Studios = item.Studios; + tasks.Add(AttachStudios(dto, item)); } if (fields.Contains(ItemFields.People)) @@ -645,6 +645,67 @@ namespace MediaBrowser.Controller.Dto } /// <summary> + /// Attaches the studios. + /// </summary> + /// <param name="dto">The dto.</param> + /// <param name="item">The item.</param> + /// <returns>Task.</returns> + private async Task AttachStudios(BaseItemDto dto, BaseItem item) + { + if (item.Studios == null) + { + return; + } + + var studios = item.Studios.ToList(); + + dto.Studios = new StudioDto[studios.Count]; + + var entities = await Task.WhenAll(studios.Distinct(StringComparer.OrdinalIgnoreCase).Select(c => + + Task.Run(async () => + { + try + { + return await _libraryManager.GetStudio(c).ConfigureAwait(false); + } + catch (IOException ex) + { + _logger.ErrorException("Error getting studio {0}", ex, c); + return null; + } + }) + + )).ConfigureAwait(false); + + var dictionary = entities.ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase); + + for (var i = 0; i < studios.Count; i++) + { + var studio = studios[i]; + + var studioDto = new StudioDto + { + Name = studio + }; + + Studio entity; + + if (dictionary.TryGetValue(studio, out entity)) + { + var primaryImagePath = entity.PrimaryImagePath; + + if (!string.IsNullOrEmpty(primaryImagePath)) + { + studioDto.PrimaryImageTag = Kernel.Instance.ImageManager.GetImageCacheTag(entity, ImageType.Primary, primaryImagePath); + } + } + + dto.Studios[i] = studioDto; + } + } + + /// <summary> /// If an item does not any backdrops, this can be used to find the first parent that does have one /// </summary> /// <param name="item">The item.</param> |
