aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Dto
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2017-05-18 17:05:47 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2017-05-18 17:05:47 -0400
commit47fc7c6aeeb6d4304a03d1ec83489f9702feea51 (patch)
treea132c28dc295eaa4bc11a60b6845a39ed5d6a85f /Emby.Server.Implementations/Dto
parent72f120d8549ca02e7fd77591ea1c90379e2d1976 (diff)
add GenreItems property
Diffstat (limited to 'Emby.Server.Implementations/Dto')
-rw-r--r--Emby.Server.Implementations/Dto/DtoService.cs67
1 files changed, 34 insertions, 33 deletions
diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.cs
index 0b66a8e1f0..fe5642f1d3 100644
--- a/Emby.Server.Implementations/Dto/DtoService.cs
+++ b/Emby.Server.Implementations/Dto/DtoService.cs
@@ -751,45 +751,41 @@ namespace Emby.Server.Implementations.Dto
/// <returns>Task.</returns>
private void AttachStudios(BaseItemDto dto, BaseItem item)
{
- var studios = item.Studios.ToList();
-
- dto.Studios = new StudioDto[studios.Count];
-
- var dictionary = studios.Distinct(StringComparer.OrdinalIgnoreCase).Select(name =>
- {
- try
+ dto.Studios = item.Studios
+ .Where(i => !string.IsNullOrWhiteSpace(i))
+ .Select(i => new NameIdPair
{
- return _libraryManager.GetStudio(name);
- }
- catch (IOException ex)
- {
- _logger.ErrorException("Error getting studio {0}", ex, name);
- return null;
- }
- })
- .Where(i => i != null)
- .DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
- .ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase);
-
- for (var i = 0; i < studios.Count; i++)
- {
- var studio = studios[i];
+ Name = i,
+ Id = _libraryManager.GetStudioId(i).ToString("N")
+ })
+ .ToArray();
+ }
- var studioDto = new StudioDto
+ private void AttachGenreItems(BaseItemDto dto, BaseItem item)
+ {
+ dto.GenreItems = item.Genres
+ .Where(i => !string.IsNullOrWhiteSpace(i))
+ .Select(i => new NameIdPair
{
- Name = studio
- };
-
- Studio entity;
+ Name = i,
+ Id = GetStudioId(i, item)
+ })
+ .ToArray();
+ }
- if (dictionary.TryGetValue(studio, out entity))
- {
- studioDto.Id = entity.Id.ToString("N");
- studioDto.PrimaryImageTag = GetImageCacheTag(entity, ImageType.Primary);
- }
+ private string GetStudioId(string name, BaseItem owner)
+ {
+ if (owner is IHasMusicGenres)
+ {
+ return _libraryManager.GetGameGenreId(name).ToString("N");
+ }
- dto.Studios[i] = studioDto;
+ if (owner is Game || owner is GameSystem)
+ {
+ return _libraryManager.GetGameGenreId(name).ToString("N");
}
+
+ return _libraryManager.GetGenreId(name).ToString("N");
}
/// <summary>
@@ -903,6 +899,11 @@ namespace Emby.Server.Implementations.Dto
dto.Genres = item.Genres;
}
+ if (fields.Contains(ItemFields.GenreItems))
+ {
+ AttachGenreItems(dto, item);
+ }
+
if (options.EnableImages)
{
dto.ImageTags = new Dictionary<ImageType, string>();