SeriesNfoParser.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using MediaBrowser.Common.Configuration;
  2. using MediaBrowser.Controller.Entities.TV;
  3. using MediaBrowser.Controller.Library;
  4. using MediaBrowser.Controller.Providers;
  5. using MediaBrowser.Model.Entities;
  6. using MediaBrowser.Model.Logging;
  7. using System;
  8. using System.Xml;
  9. using MediaBrowser.Model.IO;
  10. using MediaBrowser.Model.Xml;
  11. namespace MediaBrowser.XbmcMetadata.Parsers
  12. {
  13. public class SeriesNfoParser : BaseNfoParser<Series>
  14. {
  15. /// <summary>
  16. /// Fetches the data from XML node.
  17. /// </summary>
  18. /// <param name="reader">The reader.</param>
  19. /// <param name="itemResult">The item result.</param>
  20. protected override void FetchDataFromXmlNode(XmlReader reader, MetadataResult<Series> itemResult)
  21. {
  22. var item = itemResult.Item;
  23. switch (reader.Name)
  24. {
  25. case "id":
  26. {
  27. string imdbId = reader.GetAttribute("IMDB");
  28. string tmdbId = reader.GetAttribute("TMDB");
  29. string tvdbId = reader.GetAttribute("TVDB");
  30. if (string.IsNullOrWhiteSpace(tvdbId))
  31. {
  32. tvdbId = reader.ReadElementContentAsString();
  33. }
  34. if (!string.IsNullOrWhiteSpace(imdbId))
  35. {
  36. item.SetProviderId(MetadataProviders.Imdb, imdbId);
  37. }
  38. if (!string.IsNullOrWhiteSpace(tmdbId))
  39. {
  40. item.SetProviderId(MetadataProviders.Tmdb, tmdbId);
  41. }
  42. if (!string.IsNullOrWhiteSpace(tvdbId))
  43. {
  44. item.SetProviderId(MetadataProviders.Tvdb, tvdbId);
  45. }
  46. break;
  47. }
  48. case "airs_dayofweek":
  49. {
  50. item.AirDays = TVUtils.GetAirDays(reader.ReadElementContentAsString());
  51. break;
  52. }
  53. case "airs_time":
  54. {
  55. var val = reader.ReadElementContentAsString();
  56. if (!string.IsNullOrWhiteSpace(val))
  57. {
  58. item.AirTime = val;
  59. }
  60. break;
  61. }
  62. case "animeseriesindex":
  63. {
  64. var number = reader.ReadElementContentAsString();
  65. if (!string.IsNullOrWhiteSpace(number))
  66. {
  67. int num;
  68. if (int.TryParse(number, out num))
  69. {
  70. item.AnimeSeriesIndex = num;
  71. }
  72. }
  73. break;
  74. }
  75. case "status":
  76. {
  77. var status = reader.ReadElementContentAsString();
  78. if (!string.IsNullOrWhiteSpace(status))
  79. {
  80. SeriesStatus seriesStatus;
  81. if (Enum.TryParse(status, true, out seriesStatus))
  82. {
  83. item.Status = seriesStatus;
  84. }
  85. else
  86. {
  87. Logger.Info("Unrecognized series status: " + status);
  88. }
  89. }
  90. break;
  91. }
  92. default:
  93. base.FetchDataFromXmlNode(reader, itemResult);
  94. break;
  95. }
  96. }
  97. public SeriesNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager, IFileSystem fileSystem, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(logger, config, providerManager, fileSystem, xmlReaderSettingsFactory)
  98. {
  99. }
  100. }
  101. }