mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-21 01:24:44 +01:00
add GenreItems property
This commit is contained in:
@@ -241,7 +241,6 @@ namespace Emby.Server.Implementations.Data
|
||||
AddColumn(db, "TypedBaseItems", "InheritedTags", "Text", existingColumnNames);
|
||||
AddColumn(db, "TypedBaseItems", "CleanName", "Text", existingColumnNames);
|
||||
AddColumn(db, "TypedBaseItems", "PresentationUniqueKey", "Text", existingColumnNames);
|
||||
AddColumn(db, "TypedBaseItems", "SlugName", "Text", existingColumnNames);
|
||||
AddColumn(db, "TypedBaseItems", "OriginalTitle", "Text", existingColumnNames);
|
||||
AddColumn(db, "TypedBaseItems", "PrimaryVersionId", "Text", existingColumnNames);
|
||||
AddColumn(db, "TypedBaseItems", "DateLastMediaAdded", "DATETIME", existingColumnNames);
|
||||
@@ -573,7 +572,6 @@ namespace Emby.Server.Implementations.Data
|
||||
"InheritedTags",
|
||||
"CleanName",
|
||||
"PresentationUniqueKey",
|
||||
"SlugName",
|
||||
"OriginalTitle",
|
||||
"PrimaryVersionId",
|
||||
"DateLastMediaAdded",
|
||||
@@ -950,7 +948,6 @@ namespace Emby.Server.Implementations.Data
|
||||
}
|
||||
|
||||
saveItemStatement.TryBind("@PresentationUniqueKey", item.PresentationUniqueKey);
|
||||
saveItemStatement.TryBind("@SlugName", item.SlugName);
|
||||
saveItemStatement.TryBind("@OriginalTitle", item.OriginalTitle);
|
||||
|
||||
var video = item as Video;
|
||||
@@ -3665,10 +3662,10 @@ namespace Emby.Server.Implementations.Data
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(query.SlugName))
|
||||
{
|
||||
whereClauses.Add("SlugName=@SlugName");
|
||||
whereClauses.Add("CleanName=@SlugName");
|
||||
if (statement != null)
|
||||
{
|
||||
statement.TryBind("@SlugName", query.SlugName);
|
||||
statement.TryBind("@SlugName", GetCleanValue(query.SlugName));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 = item.Studios
|
||||
.Where(i => !string.IsNullOrWhiteSpace(i))
|
||||
.Select(i => new NameIdPair
|
||||
{
|
||||
Name = i,
|
||||
Id = _libraryManager.GetStudioId(i).ToString("N")
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
dto.Studios = new StudioDto[studios.Count];
|
||||
private void AttachGenreItems(BaseItemDto dto, BaseItem item)
|
||||
{
|
||||
dto.GenreItems = item.Genres
|
||||
.Where(i => !string.IsNullOrWhiteSpace(i))
|
||||
.Select(i => new NameIdPair
|
||||
{
|
||||
Name = i,
|
||||
Id = GetStudioId(i, item)
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
var dictionary = studios.Distinct(StringComparer.OrdinalIgnoreCase).Select(name =>
|
||||
private string GetStudioId(string name, BaseItem owner)
|
||||
{
|
||||
if (owner is IHasMusicGenres)
|
||||
{
|
||||
try
|
||||
{
|
||||
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];
|
||||
|
||||
var studioDto = new StudioDto
|
||||
{
|
||||
Name = studio
|
||||
};
|
||||
|
||||
Studio entity;
|
||||
|
||||
if (dictionary.TryGetValue(studio, out entity))
|
||||
{
|
||||
studioDto.Id = entity.Id.ToString("N");
|
||||
studioDto.PrimaryImageTag = GetImageCacheTag(entity, ImageType.Primary);
|
||||
}
|
||||
|
||||
dto.Studios[i] = studioDto;
|
||||
return _libraryManager.GetGameGenreId(name).ToString("N");
|
||||
}
|
||||
|
||||
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>();
|
||||
|
||||
@@ -895,6 +895,26 @@ namespace Emby.Server.Implementations.Library
|
||||
return CreateItemByName<Studio>(Studio.GetPath, name);
|
||||
}
|
||||
|
||||
public Guid GetStudioId(string name)
|
||||
{
|
||||
return GetItemByNameId<Studio>(Studio.GetPath, name);
|
||||
}
|
||||
|
||||
public Guid GetGenreId(string name)
|
||||
{
|
||||
return GetItemByNameId<Genre>(Genre.GetPath, name);
|
||||
}
|
||||
|
||||
public Guid GetMusicGenreId(string name)
|
||||
{
|
||||
return GetItemByNameId<MusicGenre>(MusicGenre.GetPath, name);
|
||||
}
|
||||
|
||||
public Guid GetGameGenreId(string name)
|
||||
{
|
||||
return GetItemByNameId<GameGenre>(GameGenre.GetPath, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a Genre
|
||||
/// </summary>
|
||||
@@ -974,14 +994,13 @@ namespace Emby.Server.Implementations.Library
|
||||
}
|
||||
}
|
||||
|
||||
var path = getPathFn(name);
|
||||
var forceCaseInsensitiveId = ConfigurationManager.Configuration.EnableNormalizedItemByNameIds;
|
||||
var id = GetNewItemIdInternal(path, typeof(T), forceCaseInsensitiveId);
|
||||
var id = GetItemByNameId<T>(getPathFn, name);
|
||||
|
||||
var item = GetItemById(id) as T;
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
var path = getPathFn(name);
|
||||
item = new T
|
||||
{
|
||||
Name = name,
|
||||
@@ -998,6 +1017,14 @@ namespace Emby.Server.Implementations.Library
|
||||
return item;
|
||||
}
|
||||
|
||||
private Guid GetItemByNameId<T>(Func<string, string> getPathFn, string name)
|
||||
where T : BaseItem, new()
|
||||
{
|
||||
var path = getPathFn(name);
|
||||
var forceCaseInsensitiveId = ConfigurationManager.Configuration.EnableNormalizedItemByNameIds;
|
||||
return GetNewItemIdInternal(path, typeof(T), forceCaseInsensitiveId);
|
||||
}
|
||||
|
||||
public IEnumerable<MusicArtist> GetAlbumArtists(IEnumerable<IHasAlbumArtist> items)
|
||||
{
|
||||
var names = items
|
||||
|
||||
Reference in New Issue
Block a user