jellyfin/MediaBrowser.Controller/Providers/TV/SeriesXmlParser.cs

100 lines
3.2 KiB
C#
Raw Normal View History

2013-02-21 20:26:35 +00:00
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
2013-02-21 01:33:05 +00:00
using MediaBrowser.Model.Entities;
2013-02-21 20:26:35 +00:00
using MediaBrowser.Model.Logging;
2013-02-21 01:33:05 +00:00
using System;
using System.Xml;
namespace MediaBrowser.Controller.Providers.TV
{
/// <summary>
/// Class SeriesXmlParser
/// </summary>
public class SeriesXmlParser : BaseItemXmlParser<Series>
{
2013-02-21 20:26:35 +00:00
/// <summary>
/// Initializes a new instance of the <see cref="BaseItemXmlParser{T}" /> class.
/// </summary>
/// <param name="logger">The logger.</param>
public SeriesXmlParser(ILogger logger)
: base(logger)
{
}
2013-02-21 01:33:05 +00:00
/// <summary>
/// Fetches the data from XML node.
/// </summary>
/// <param name="reader">The reader.</param>
/// <param name="item">The item.</param>
protected override void FetchDataFromXmlNode(XmlReader reader, Series item)
{
switch (reader.Name)
{
case "Series":
//MB generated metadata is within a "Series" node
using (var subTree = reader.ReadSubtree())
{
subTree.MoveToContent();
// Loop through each element
while (subTree.Read())
{
if (subTree.NodeType == XmlNodeType.Element)
{
FetchDataFromXmlNode(subTree, item);
}
}
}
break;
case "id":
string id = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(id))
{
item.SetProviderId(MetadataProviders.Tvdb, id);
}
break;
case "Airs_DayOfWeek":
{
item.AirDays = TVUtils.GetAirDays(reader.ReadElementContentAsString());
break;
}
case "Airs_Time":
item.AirTime = reader.ReadElementContentAsString();
break;
case "SeriesName":
item.Name = reader.ReadElementContentAsString();
break;
case "Status":
{
var status = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(status))
{
SeriesStatus seriesStatus;
if (Enum.TryParse(status, true, out seriesStatus))
{
item.Status = seriesStatus;
}
else
{
2013-02-21 20:26:35 +00:00
Logger.Info("Unrecognized series status: " + status);
2013-02-21 01:33:05 +00:00
}
}
break;
}
default:
base.FetchDataFromXmlNode(reader, item);
break;
}
}
}
}