jellyfin-server/MediaBrowser.LocalMetadata/Parsers/GameXmlParser.cs

89 lines
2.9 KiB
C#
Raw Normal View History

using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
2016-10-30 07:02:23 +00:00
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
2016-10-30 07:02:23 +00:00
using MediaBrowser.Model.Xml;
namespace MediaBrowser.LocalMetadata.Parsers
{
/// <summary>
/// Class EpisodeXmlParser
/// </summary>
public class GameXmlParser : BaseItemXmlParser<Game>
{
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
2014-02-03 17:44:13 +00:00
private readonly Task _cachedTask = Task.FromResult(true);
2015-06-29 01:10:45 +00:00
public Task FetchAsync(MetadataResult<Game> item, string metadataFile, CancellationToken cancellationToken)
{
Fetch(item, metadataFile, cancellationToken);
cancellationToken.ThrowIfCancellationRequested();
2014-02-03 17:44:13 +00:00
return _cachedTask;
}
/// <summary>
/// Fetches the data from XML node.
/// </summary>
/// <param name="reader">The reader.</param>
2015-06-29 01:10:45 +00:00
/// <param name="result">The result.</param>
protected override void FetchDataFromXmlNode(XmlReader reader, MetadataResult<Game> result)
{
2015-06-29 01:10:45 +00:00
var item = result.Item;
switch (reader.Name)
{
case "GameSystem":
{
var val = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(val))
{
item.GameSystem = val;
}
break;
}
case "GamesDbId":
{
var val = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(val))
{
item.SetProviderId(MetadataProviders.Gamesdb, val);
}
break;
}
case "Players":
{
var val = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(val))
{
int num;
if (int.TryParse(val, NumberStyles.Integer, _usCulture, out num))
{
item.PlayersSupported = num;
}
}
break;
}
default:
2015-06-29 01:10:45 +00:00
base.FetchDataFromXmlNode(reader, result);
break;
}
}
2016-10-30 07:02:23 +00:00
public GameXmlParser(ILogger logger, IProviderManager providerManager, IXmlReaderSettingsFactory xmlReaderSettingsFactory, IFileSystem fileSystem) : base(logger, providerManager, xmlReaderSettingsFactory, fileSystem)
{
}
}
}