GameXmlParser.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.Providers;
  3. using MediaBrowser.Model.Entities;
  4. using MediaBrowser.Model.Logging;
  5. using System.Globalization;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. using System.Xml;
  9. namespace MediaBrowser.Providers.Games
  10. {
  11. /// <summary>
  12. /// Class EpisodeXmlParser
  13. /// </summary>
  14. public class GameXmlParser : BaseItemXmlParser<Game>
  15. {
  16. private Task _chaptersTask = null;
  17. private readonly CultureInfo _usCulture = new CultureInfo("en-US");
  18. public GameXmlParser(ILogger logger)
  19. : base(logger)
  20. {
  21. }
  22. public async Task FetchAsync(Game item, string metadataFile, CancellationToken cancellationToken)
  23. {
  24. _chaptersTask = null;
  25. Fetch(item, metadataFile, cancellationToken);
  26. cancellationToken.ThrowIfCancellationRequested();
  27. if (_chaptersTask != null)
  28. {
  29. await _chaptersTask.ConfigureAwait(false);
  30. }
  31. }
  32. /// <summary>
  33. /// Fetches the data from XML node.
  34. /// </summary>
  35. /// <param name="reader">The reader.</param>
  36. /// <param name="item">The item.</param>
  37. protected override void FetchDataFromXmlNode(XmlReader reader, Game item)
  38. {
  39. switch (reader.Name)
  40. {
  41. case "GameSystem":
  42. {
  43. var val = reader.ReadElementContentAsString();
  44. if (!string.IsNullOrWhiteSpace(val))
  45. {
  46. item.GameSystem = val;
  47. }
  48. break;
  49. }
  50. case "GamesDbId":
  51. {
  52. var val = reader.ReadElementContentAsString();
  53. if (!string.IsNullOrWhiteSpace(val))
  54. {
  55. item.SetProviderId(MetadataProviders.Gamesdb, val);
  56. }
  57. break;
  58. }
  59. case "NesBox":
  60. {
  61. var val = reader.ReadElementContentAsString();
  62. if (!string.IsNullOrWhiteSpace(val))
  63. {
  64. item.SetProviderId(MetadataProviders.NesBox, val);
  65. }
  66. break;
  67. }
  68. case "NesBoxRom":
  69. {
  70. var val = reader.ReadElementContentAsString();
  71. if (!string.IsNullOrWhiteSpace(val))
  72. {
  73. item.SetProviderId(MetadataProviders.NesBoxRom, val);
  74. }
  75. break;
  76. }
  77. case "Players":
  78. {
  79. var val = reader.ReadElementContentAsString();
  80. if (!string.IsNullOrWhiteSpace(val))
  81. {
  82. int num;
  83. if (int.TryParse(val, NumberStyles.Integer, _usCulture, out num))
  84. {
  85. item.PlayersSupported = num;
  86. }
  87. }
  88. break;
  89. }
  90. default:
  91. base.FetchDataFromXmlNode(reader, item);
  92. break;
  93. }
  94. }
  95. }
  96. }