added GameGenre

This commit is contained in:
Luke Pulverenti 2013-07-01 13:17:33 -04:00
parent 1d7c83bfc6
commit 57449f62c1
15 changed files with 503 additions and 3 deletions

View File

@ -115,6 +115,11 @@ namespace MediaBrowser.Api
return libraryManager.GetMusicGenre(DeSlugGenreName(name, libraryManager));
}
protected Task<GameGenre> GetGameGenre(string name, ILibraryManager libraryManager)
{
return libraryManager.GetGameGenre(DeSlugGenreName(name, libraryManager));
}
protected Task<Person> GetPerson(string name, ILibraryManager libraryManager)
{
return libraryManager.GetPerson(DeSlugPersonName(name, libraryManager));

View File

@ -180,7 +180,20 @@ namespace MediaBrowser.Api.Images
[ApiMember(Name = "Name", Description = "Genre name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Name { get; set; }
}
[Route("/GameGenres/{Name}/Images/{Type}", "GET")]
[Route("/GameGenres/{Name}/Images/{Type}/{Index}", "GET")]
[Api(Description = "Gets a genre image")]
public class GetGameGenreImage : ImageRequest
{
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
[ApiMember(Name = "Name", Description = "Genre name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Name { get; set; }
}
/// <summary>
/// Class GetYearImage
/// </summary>
@ -530,6 +543,13 @@ namespace MediaBrowser.Api.Images
return GetImage(request, item);
}
public object Get(GetGameGenreImage request)
{
var item = GetGameGenre(request.Name, _libraryManager).Result;
return GetImage(request, item);
}
/// <summary>
/// Posts the specified request.
/// </summary>

View File

@ -56,6 +56,17 @@ namespace MediaBrowser.Api
public string Name { get; set; }
}
[Route("/GameGenres/{Name}/Refresh", "POST")]
[Api(Description = "Refreshes metadata for a game genre")]
public class RefreshGameGenre : IReturnVoid
{
[ApiMember(Name = "Forced", Description = "Indicates if a normal or forced refresh should occur.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "POST")]
public bool Forced { get; set; }
[ApiMember(Name = "Name", Description = "Name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public string Name { get; set; }
}
[Route("/Persons/{Name}/Refresh", "POST")]
[Api(Description = "Refreshes metadata for a person")]
public class RefreshPerson : IReturnVoid
@ -152,6 +163,27 @@ namespace MediaBrowser.Api
}
}
public void Post(RefreshGameGenre request)
{
var task = RefreshGameGenre(request);
Task.WaitAll(task);
}
private async Task RefreshGameGenre(RefreshGameGenre request)
{
var item = await GetGameGenre(request.Name, _libraryManager).ConfigureAwait(false);
try
{
await item.RefreshMetadata(CancellationToken.None, forceRefresh: request.Forced).ConfigureAwait(false);
}
catch (Exception ex)
{
Logger.ErrorException("Error refreshing library", ex);
}
}
public void Post(RefreshPerson request)
{
var task = RefreshPerson(request);

View File

@ -53,6 +53,14 @@ namespace MediaBrowser.Api
public string GenreName { get; set; }
}
[Route("/GameGenres/{GenreName}", "POST")]
[Api(("Updates a game genre"))]
public class UpdateGameGenre : BaseItemDto, IReturnVoid
{
[ApiMember(Name = "GenreName", Description = "The name of the item", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public string GenreName { get; set; }
}
[Route("/Genres/{GenreName}", "POST")]
[Api(("Updates a genre"))]
public class UpdateGenre : BaseItemDto, IReturnVoid
@ -152,6 +160,22 @@ namespace MediaBrowser.Api
await _libraryManager.UpdateItem(item, ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
}
public void Post(UpdateGameGenre request)
{
var task = UpdateItem(request);
Task.WaitAll(task);
}
private async Task UpdateItem(UpdateGameGenre request)
{
var item = await _libraryManager.GetGameGenre(request.GenreName).ConfigureAwait(false);
UpdateItem(request, item);
await _libraryManager.UpdateItem(item, ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
}
public void Post(UpdateGenre request)
{
var task = UpdateItem(request);

View File

@ -106,6 +106,7 @@
<Compile Include="UserLibrary\ArtistsService.cs" />
<Compile Include="UserLibrary\BaseItemsByNameService.cs" />
<Compile Include="UserLibrary\BaseItemsRequest.cs" />
<Compile Include="UserLibrary\GameGenresService.cs" />
<Compile Include="UserLibrary\GenresService.cs" />
<Compile Include="UserLibrary\ItemByNameUserDataService.cs" />
<Compile Include="UserLibrary\ItemsService.cs" />

View File

@ -0,0 +1,166 @@
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Querying;
using ServiceStack.ServiceHost;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MediaBrowser.Api.UserLibrary
{
[Route("/GameGenres", "GET")]
[Api(Description = "Gets all Game genres from a given item, folder, or the entire library")]
public class GetGameGenres : GetItemsByName
{
public GetGameGenres()
{
IncludeItemTypes = typeof(Audio).Name;
}
}
[Route("/GameGenres/{Name}/Counts", "GET")]
[Api(Description = "Gets item counts of library items that a genre appears in")]
public class GetGameGenreItemCounts : IReturn<ItemByNameCounts>
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public Guid? UserId { get; set; }
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
[ApiMember(Name = "Name", Description = "The genre name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Name { get; set; }
}
[Route("/GameGenres/{Name}", "GET")]
[Api(Description = "Gets a Game genre, by name")]
public class GetGameGenre : IReturn<BaseItemDto>
{
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
[ApiMember(Name = "Name", Description = "The genre name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Name { get; set; }
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
[ApiMember(Name = "UserId", Description = "Optional. Filter by user id, and attach user data", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public Guid? UserId { get; set; }
}
public class GameGenresService : BaseItemsByNameService<GameGenre>
{
public GameGenresService(IUserManager userManager, ILibraryManager libraryManager, IUserDataRepository userDataRepository, IItemRepository itemRepo)
: base(userManager, libraryManager, userDataRepository, itemRepo)
{
}
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public object Get(GetGameGenre request)
{
var result = GetItem(request).Result;
return ToOptimizedResult(result);
}
/// <summary>
/// Gets the item.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>Task{BaseItemDto}.</returns>
private async Task<BaseItemDto> GetItem(GetGameGenre request)
{
var item = await GetGameGenre(request.Name, LibraryManager).ConfigureAwait(false);
// Get everything
var fields = Enum.GetNames(typeof(ItemFields)).Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true));
var builder = new DtoBuilder(Logger, LibraryManager, UserDataRepository, ItemRepository);
if (request.UserId.HasValue)
{
var user = UserManager.GetUserById(request.UserId.Value);
return await builder.GetBaseItemDto(item, fields.ToList(), user).ConfigureAwait(false);
}
return await builder.GetBaseItemDto(item, fields.ToList()).ConfigureAwait(false);
}
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public object Get(GetGameGenres request)
{
var result = GetResult(request).Result;
return ToOptimizedResult(result);
}
/// <summary>
/// Gets all items.
/// </summary>
/// <param name="request">The request.</param>
/// <param name="items">The items.</param>
/// <returns>IEnumerable{Tuple{System.StringFunc{System.Int32}}}.</returns>
protected override IEnumerable<IbnStub<GameGenre>> GetAllItems(GetItemsByName request, IEnumerable<BaseItem> items)
{
var itemsList = items.Where(i => i.Genres != null).ToList();
return itemsList
.SelectMany(i => i.Genres)
.Distinct(StringComparer.OrdinalIgnoreCase)
.Select(name => new IbnStub<GameGenre>(name, () => itemsList.Where(i => i.Genres.Contains(name, StringComparer.OrdinalIgnoreCase)), GetEntity));
}
/// <summary>
/// Gets the entity.
/// </summary>
/// <param name="name">The name.</param>
/// <returns>Task{Genre}.</returns>
protected Task<GameGenre> GetEntity(string name)
{
return LibraryManager.GetGameGenre(name);
}
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public object Get(GetGameGenreItemCounts request)
{
var name = DeSlugGenreName(request.Name, LibraryManager);
var items = GetItems(request.UserId).Where(i => i.Genres != null && i.Genres.Contains(name, StringComparer.OrdinalIgnoreCase)).ToList();
var counts = new ItemByNameCounts
{
TotalCount = items.Count,
GameCount = items.OfType<Game>().Count()
};
return ToOptimizedResult(counts);
}
}
}

View File

@ -17,6 +17,7 @@ namespace MediaBrowser.Api.UserLibrary
[Route("/Users/{UserId}/Favorites/Studios/{Name}", "POST")]
[Route("/Users/{UserId}/Favorites/Genres/{Name}", "POST")]
[Route("/Users/{UserId}/Favorites/MusicGenres/{Name}", "POST")]
[Route("/Users/{UserId}/Favorites/GameGenres/{Name}", "POST")]
[Api(Description = "Marks something as a favorite")]
public class MarkItemByNameFavorite : IReturnVoid
{
@ -43,6 +44,7 @@ namespace MediaBrowser.Api.UserLibrary
[Route("/Users/{UserId}/Favorites/Studios/{Name}", "DELETE")]
[Route("/Users/{UserId}/Favorites/Genres/{Name}", "DELETE")]
[Route("/Users/{UserId}/Favorites/MusicGenres/{Name}", "DELETE")]
[Route("/Users/{UserId}/Favorites/GameGenres/{Name}", "DELETE")]
[Api(Description = "Unmarks something as a favorite")]
public class UnmarkItemByNameFavorite : IReturnVoid
{
@ -102,6 +104,7 @@ namespace MediaBrowser.Api.UserLibrary
[Route("/Users/{UserId}/Ratings/Studios/{Name}", "DELETE")]
[Route("/Users/{UserId}/Ratings/Genres/{Name}", "DELETE")]
[Route("/Users/{UserId}/Ratings/MusicGenres/{Name}", "DELETE")]
[Route("/Users/{UserId}/Ratings/GameGenres/{Name}", "DELETE")]
[Api(Description = "Deletes a user's saved personal rating for an item")]
public class DeleteItemByNameRating : IReturnVoid
{
@ -230,6 +233,10 @@ namespace MediaBrowser.Api.UserLibrary
{
item = await GetMusicGenre(name, LibraryManager).ConfigureAwait(false);
}
else if (string.Equals(type, "GameGenres"))
{
item = await GetGameGenre(name, LibraryManager).ConfigureAwait(false);
}
else if (string.Equals(type, "Studios"))
{
item = await GetStudio(name, LibraryManager).ConfigureAwait(false);
@ -278,6 +285,10 @@ namespace MediaBrowser.Api.UserLibrary
{
item = await GetMusicGenre(name, LibraryManager).ConfigureAwait(false);
}
else if (string.Equals(type, "GameGenres"))
{
item = await GetGameGenre(name, LibraryManager).ConfigureAwait(false);
}
else if (string.Equals(type, "Studios"))
{
item = await GetStudio(name, LibraryManager).ConfigureAwait(false);

View File

@ -0,0 +1,15 @@

namespace MediaBrowser.Controller.Entities
{
public class GameGenre : BaseItem, IItemByName
{
/// <summary>
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
public override string GetUserDataKey()
{
return "GameGenre-" + Name;
}
}
}

View File

@ -45,6 +45,12 @@ namespace MediaBrowser.Controller
/// </summary>
/// <value>The music genre path.</value>
string MusicGenrePath { get; }
/// <summary>
/// Gets the game genre path.
/// </summary>
/// <value>The game genre path.</value>
string GameGenrePath { get; }
/// <summary>
/// Gets the artists path.

View File

@ -87,6 +87,14 @@ namespace MediaBrowser.Controller.Library
/// <param name="allowSlowProviders">if set to <c>true</c> [allow slow providers].</param>
/// <returns>Task{MusicGenre}.</returns>
Task<MusicGenre> GetMusicGenre(string name, bool allowSlowProviders = false);
/// <summary>
/// Gets the game genre.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="allowSlowProviders">if set to <c>true</c> [allow slow providers].</param>
/// <returns>Task{GameGenre}.</returns>
Task<GameGenre> GetGameGenre(string name, bool allowSlowProviders = false);
/// <summary>
/// Gets a Year

View File

@ -75,6 +75,7 @@
<Compile Include="Entities\Audio\MusicAlbumDisc.cs" />
<Compile Include="Entities\Audio\MusicGenre.cs" />
<Compile Include="Entities\Game.cs" />
<Compile Include="Entities\GameGenre.cs" />
<Compile Include="Entities\IByReferenceItem.cs" />
<Compile Include="Entities\IItemByName.cs" />
<Compile Include="Entities\MusicVideo.cs" />

View File

@ -662,6 +662,17 @@ namespace MediaBrowser.Server.Implementations.Library
return GetItemByName<MusicGenre>(ConfigurationManager.ApplicationPaths.MusicGenrePath, name, CancellationToken.None, allowSlowProviders);
}
/// <summary>
/// Gets the game genre.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="allowSlowProviders">if set to <c>true</c> [allow slow providers].</param>
/// <returns>Task{GameGenre}.</returns>
public Task<GameGenre> GetGameGenre(string name, bool allowSlowProviders = false)
{
return GetItemByName<GameGenre>(ConfigurationManager.ApplicationPaths.GameGenrePath, name, CancellationToken.None, allowSlowProviders);
}
/// <summary>
/// Gets a Genre
/// </summary>

View File

@ -225,5 +225,18 @@ namespace MediaBrowser.Server.Implementations
return Path.Combine(ItemsByNamePath, "artists");
}
}
/// <summary>
/// Gets the game genre path.
/// </summary>
/// <value>The game genre path.</value>
public string GameGenrePath
{
get
{
return Path.Combine(ItemsByNamePath, "GameGenre");
}
}
}
}

View File

@ -497,6 +497,24 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
});
};
self.refreshGameGenre = function (name, force) {
if (!name) {
throw new Error("null name");
}
var url = self.getUrl("GameGenres/" + self.encodeName(name) + "/Refresh", {
forced: force || false
});
return self.ajax({
type: "POST",
url: url
});
};
self.refreshPerson = function (name, force) {
if (!name) {
@ -1263,6 +1281,27 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
});
};
self.getGameGenre = function (name, userId) {
if (!name) {
throw new Error("null name");
}
var options = {};
if (userId) {
options.userId = userId;
}
var url = self.getUrl("GameGenres/" + self.encodeName(name), options);
return self.ajax({
type: "GET",
url: url,
dataType: "json"
});
};
/**
* Gets an artist
*/
@ -1552,6 +1591,41 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
return self.getUrl(url, options);
};
/**
* Constructs a url for a genre image
* @param {String} name
* @param {Object} options
* Options supports the following properties:
* width - download the image at a fixed width
* height - download the image at a fixed height
* maxWidth - download the image at a maxWidth
* maxHeight - download the image at a maxHeight
* quality - A scale of 0-100. This should almost always be omitted as the default will suffice.
* For best results do not specify both width and height together, as aspect ratio might be altered.
*/
self.getGameGenreImageUrl = function (name, options) {
if (!name) {
throw new Error("null name");
}
options = options || {
};
var url = "GameGenres/" + self.encodeName(name) + "/Images/" + options.type;
if (options.index != null) {
url += "/" + options.index;
}
// Don't put these on the query string
delete options.type;
delete options.index;
return self.getUrl(url, options);
};
/**
* Constructs a url for a artist image
* @param {String} name
@ -1922,7 +1996,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
});
};
self.updateMusicGenres = function (item) {
self.updateMusicGenre = function (item) {
if (!item) {
throw new Error("null item");
@ -1938,6 +2012,22 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
});
};
self.updateGameGenre = function (item) {
if (!item) {
throw new Error("null item");
}
var url = self.getUrl("GameGenres/" + self.encodeName(item.Name));
return self.ajax({
type: "POST",
url: url,
data: JSON.stringify(item),
contentType: "application/json"
});
};
/**
* Updates plugin security info
*/
@ -2136,6 +2226,24 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
});
};
self.getGameGenres = function (userId, options) {
if (!userId) {
throw new Error("null userId");
}
options = options || {};
options.userId = userId;
var url = self.getUrl("GameGenres", options);
return self.ajax({
type: "GET",
url: url,
dataType: "json"
});
};
/**
Gets people from an item
*/
@ -2484,6 +2592,26 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
});
};
self.updateFavoriteGameGenreStatus = function (userId, name, isFavorite) {
if (!userId) {
throw new Error("null userId");
}
if (!name) {
throw new Error("null name");
}
var url = self.getUrl("Users/" + userId + "/Favorites/GameGenres/" + self.encodeName(name));
var method = isFavorite ? "POST" : "DELETE";
return self.ajax({
type: method,
url: url
});
};
/**
* Updates a user's rating for an item by name.
* @param {String} userId
@ -2590,6 +2718,26 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
});
};
self.updateGameGenreRating = function (userId, name, likes) {
if (!userId) {
throw new Error("null userId");
}
if (!name) {
throw new Error("null name");
}
var url = self.getUrl("Users/" + userId + "/Ratings/GameGenres/" + self.encodeName(name), {
likes: likes
});
return self.ajax({
type: "POST",
url: url
});
};
/**
* Clears a user's rating for an item by name.
* @param {String} userId
@ -2685,6 +2833,24 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
});
};
self.clearGameGenreRating = function (userId, name) {
if (!userId) {
throw new Error("null userId");
}
if (!name) {
throw new Error("null name");
}
var url = self.getUrl("Users/" + userId + "/Ratings/GameGenres/" + self.encodeName(name));
return self.ajax({
type: "DELETE",
url: url
});
};
self.getItemCounts = function (userId) {
var options = {};
@ -2771,6 +2937,27 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
});
};
self.getGameGenreItemCounts = function (userId, name) {
if (!userId) {
throw new Error("null userId");
}
if (!name) {
throw new Error("null name");
}
var url = self.getUrl("GameGenres/" + self.encodeName(name) + "/Counts", {
userId: userId
});
return self.ajax({
type: "GET",
url: url,
dataType: "json"
});
};
/**
Gets a variety of item counts that an artist appears in
*/

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MediaBrowser.ApiClient.Javascript" version="3.0.130" targetFramework="net45" />
<package id="MediaBrowser.ApiClient.Javascript" version="3.0.131" targetFramework="net45" />
<package id="ServiceStack.Common" version="3.9.54" targetFramework="net45" />
<package id="ServiceStack.Text" version="3.9.54" targetFramework="net45" />
</packages>