added game xml saving
This commit is contained in:
parent
57449f62c1
commit
708a8115d5
|
@ -117,7 +117,7 @@ namespace MediaBrowser.Api
|
|||
|
||||
protected Task<GameGenre> GetGameGenre(string name, ILibraryManager libraryManager)
|
||||
{
|
||||
return libraryManager.GetGameGenre(DeSlugGenreName(name, libraryManager));
|
||||
return libraryManager.GetGameGenre(DeSlugGameGenreName(name, libraryManager));
|
||||
}
|
||||
|
||||
protected Task<Person> GetPerson(string name, ILibraryManager libraryManager)
|
||||
|
@ -174,6 +174,26 @@ namespace MediaBrowser.Api
|
|||
}) ?? name;
|
||||
}
|
||||
|
||||
protected string DeSlugGameGenreName(string name, ILibraryManager libraryManager)
|
||||
{
|
||||
if (name.IndexOf(SlugChar) == -1)
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
return libraryManager.RootFolder.RecursiveChildren
|
||||
.OfType<Game>()
|
||||
.SelectMany(i => i.Genres)
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.FirstOrDefault(i =>
|
||||
{
|
||||
i = _dashReplaceChars.Aggregate(i, (current, c) => current.Replace(c, SlugChar));
|
||||
|
||||
return string.Equals(i, name, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
}) ?? name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deslugs a studio name by finding the correct entry in the library
|
||||
/// </summary>
|
||||
|
|
|
@ -68,7 +68,7 @@ namespace MediaBrowser.Api
|
|||
[ApiMember(Name = "GenreName", Description = "The name of the item", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
||||
public string GenreName { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class ItemUpdateService : BaseApiService
|
||||
{
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
|
@ -105,7 +105,7 @@ namespace MediaBrowser.Api
|
|||
|
||||
private async Task UpdateItem(UpdatePerson request)
|
||||
{
|
||||
var item = await _libraryManager.GetPerson(request.PersonName).ConfigureAwait(false);
|
||||
var item = await GetPerson(request.PersonName, _libraryManager).ConfigureAwait(false);
|
||||
|
||||
UpdateItem(request, item);
|
||||
|
||||
|
@ -121,7 +121,7 @@ namespace MediaBrowser.Api
|
|||
|
||||
private async Task UpdateItem(UpdateArtist request)
|
||||
{
|
||||
var item = await _libraryManager.GetArtist(request.ArtistName).ConfigureAwait(false);
|
||||
var item = await GetArtist(request.ArtistName, _libraryManager).ConfigureAwait(false);
|
||||
|
||||
UpdateItem(request, item);
|
||||
|
||||
|
@ -137,7 +137,7 @@ namespace MediaBrowser.Api
|
|||
|
||||
private async Task UpdateItem(UpdateStudio request)
|
||||
{
|
||||
var item = await _libraryManager.GetStudio(request.StudioName).ConfigureAwait(false);
|
||||
var item = await GetStudio(request.StudioName, _libraryManager).ConfigureAwait(false);
|
||||
|
||||
UpdateItem(request, item);
|
||||
|
||||
|
@ -153,7 +153,7 @@ namespace MediaBrowser.Api
|
|||
|
||||
private async Task UpdateItem(UpdateMusicGenre request)
|
||||
{
|
||||
var item = await _libraryManager.GetMusicGenre(request.GenreName).ConfigureAwait(false);
|
||||
var item = await GetMusicGenre(request.GenreName, _libraryManager).ConfigureAwait(false);
|
||||
|
||||
UpdateItem(request, item);
|
||||
|
||||
|
@ -169,7 +169,7 @@ namespace MediaBrowser.Api
|
|||
|
||||
private async Task UpdateItem(UpdateGameGenre request)
|
||||
{
|
||||
var item = await _libraryManager.GetGameGenre(request.GenreName).ConfigureAwait(false);
|
||||
var item = await GetGameGenre(request.GenreName, _libraryManager).ConfigureAwait(false);
|
||||
|
||||
UpdateItem(request, item);
|
||||
|
||||
|
@ -185,7 +185,7 @@ namespace MediaBrowser.Api
|
|||
|
||||
private async Task UpdateItem(UpdateGenre request)
|
||||
{
|
||||
var item = await _libraryManager.GetGenre(request.GenreName).ConfigureAwait(false);
|
||||
var item = await GetGenre(request.GenreName, _libraryManager).ConfigureAwait(false);
|
||||
|
||||
UpdateItem(request, item);
|
||||
|
||||
|
|
|
@ -149,7 +149,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
/// <returns>System.Object.</returns>
|
||||
public object Get(GetGameGenreItemCounts request)
|
||||
{
|
||||
var name = DeSlugGenreName(request.Name, LibraryManager);
|
||||
var name = DeSlugGameGenreName(request.Name, LibraryManager);
|
||||
|
||||
var items = GetItems(request.UserId).Where(i => i.Genres != null && i.Genres.Contains(name, StringComparer.OrdinalIgnoreCase)).ToList();
|
||||
|
||||
|
|
|
@ -82,6 +82,7 @@
|
|||
<Compile Include="Savers\BoxSetXmlSaver.cs" />
|
||||
<Compile Include="Savers\EpisodeXmlSaver.cs" />
|
||||
<Compile Include="Savers\FolderXmlSaver.cs" />
|
||||
<Compile Include="Savers\GameXmlSaver.cs" />
|
||||
<Compile Include="Savers\MovieXmlSaver.cs" />
|
||||
<Compile Include="Savers\PersonXmlSaver.cs" />
|
||||
<Compile Include="Savers\SeasonXmlSaver.cs" />
|
||||
|
|
85
MediaBrowser.Providers/Savers/GameXmlSaver.cs
Normal file
85
MediaBrowser.Providers/Savers/GameXmlSaver.cs
Normal file
|
@ -0,0 +1,85 @@
|
|||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Providers.Movies;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace MediaBrowser.Providers.Savers
|
||||
{
|
||||
/// <summary>
|
||||
/// Saves game.xml for games
|
||||
/// </summary>
|
||||
public class GameXmlSaver : IMetadataSaver
|
||||
{
|
||||
private readonly IServerConfigurationManager _config;
|
||||
|
||||
public GameXmlSaver(IServerConfigurationManager config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether [is enabled for] [the specified item].
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="updateType">Type of the update.</param>
|
||||
/// <returns><c>true</c> if [is enabled for] [the specified item]; otherwise, <c>false</c>.</returns>
|
||||
public bool IsEnabledFor(BaseItem item, ItemUpdateType updateType)
|
||||
{
|
||||
var wasMetadataEdited = (updateType & ItemUpdateType.MetadataEdit) == ItemUpdateType.MetadataEdit;
|
||||
var wasMetadataDownloaded = (updateType & ItemUpdateType.MetadataDownload) == ItemUpdateType.MetadataDownload;
|
||||
|
||||
// If new metadata has been downloaded and save local is on, OR metadata was manually edited, proceed
|
||||
if ((_config.Configuration.SaveLocalMeta && (wasMetadataEdited || wasMetadataDownloaded)) || wasMetadataEdited)
|
||||
{
|
||||
return item is Game;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
|
||||
|
||||
/// <summary>
|
||||
/// Saves the specified item.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
public void Save(BaseItem item, CancellationToken cancellationToken)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.Append("<Item>");
|
||||
|
||||
XmlSaverHelpers.AddCommonNodes(item, builder);
|
||||
|
||||
builder.Append("</Item>");
|
||||
|
||||
var xmlFilePath = GetSavePath(item);
|
||||
|
||||
XmlSaverHelpers.Save(builder, xmlFilePath, new string[]
|
||||
{
|
||||
});
|
||||
|
||||
// Set last refreshed so that the provider doesn't trigger after the file save
|
||||
MovieProviderFromXml.Current.SetLastRefreshed(item, DateTime.UtcNow);
|
||||
}
|
||||
|
||||
public string GetSavePath(BaseItem item)
|
||||
{
|
||||
if (item.ResolveArgs.IsDirectory)
|
||||
{
|
||||
var path = Directory.Exists(item.Path) ? item.Path : Path.GetDirectoryName(item.Path);
|
||||
|
||||
return Path.Combine(path, "game.xml");
|
||||
}
|
||||
|
||||
return Path.ChangeExtension(item.Path, ".xml");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -145,7 +145,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
}
|
||||
|
||||
// Find genres, from non-audio items
|
||||
var genres = items.Where(i => !(i is Audio) && !(i is MusicAlbum) && !(i is MusicAlbumDisc) && !(i is MusicArtist) && !(i is MusicVideo))
|
||||
var genres = items.Where(i => !(i is Audio) && !(i is MusicAlbum) && !(i is MusicAlbumDisc) && !(i is MusicArtist) && !(i is MusicVideo) && !(i is Game))
|
||||
.SelectMany(i => i.Genres)
|
||||
.Where(i => !string.IsNullOrEmpty(i))
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
|
@ -196,6 +196,32 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
}
|
||||
}
|
||||
|
||||
// Find music genres
|
||||
var gameGenres = items.OfType<Game>()
|
||||
.SelectMany(i => i.Genres)
|
||||
.Where(i => !string.IsNullOrEmpty(i))
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
|
||||
foreach (var item in gameGenres)
|
||||
{
|
||||
var index = GetIndex(item, searchTerm, terms);
|
||||
|
||||
if (index.Item2 != -1)
|
||||
{
|
||||
try
|
||||
{
|
||||
var genre = await _libraryManager.GetGameGenre(item).ConfigureAwait(false);
|
||||
|
||||
hints.Add(new Tuple<BaseItem, string, int>(genre, index.Item1, index.Item2));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error getting {0}", ex, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Find studios
|
||||
var studios = items.SelectMany(i => i.Studios)
|
||||
.Where(i => !string.IsNullOrEmpty(i))
|
||||
|
|
Loading…
Reference in New Issue
Block a user