2013-08-06 04:45:57 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Indexers
|
|
|
|
|
{
|
|
|
|
|
public static class XElementExtensions
|
|
|
|
|
{
|
|
|
|
|
public static string Title(this XElement item)
|
|
|
|
|
{
|
2013-08-06 07:06:58 +02:00
|
|
|
|
return item.TryGetValue("title", "Unknown");
|
2013-08-06 04:45:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static DateTime PublishDate(this XElement item)
|
|
|
|
|
{
|
2013-08-06 07:06:58 +02:00
|
|
|
|
return DateTime.Parse(item.TryGetValue("pubDate"));
|
2013-08-06 04:45:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<String> Links(this XElement item)
|
|
|
|
|
{
|
|
|
|
|
var elements = item.Elements("link");
|
|
|
|
|
|
2013-08-06 07:06:58 +02:00
|
|
|
|
return elements.Select(link => link.Value).ToList();
|
2013-08-06 04:45:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string Description(this XElement item)
|
|
|
|
|
{
|
2013-08-06 07:06:58 +02:00
|
|
|
|
return item.TryGetValue("description");
|
2013-08-06 04:45:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string Comments(this XElement item)
|
|
|
|
|
{
|
2013-08-06 07:06:58 +02:00
|
|
|
|
return item.TryGetValue("comments");
|
2013-08-06 04:45:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-06 07:06:58 +02:00
|
|
|
|
private static string TryGetValue(this XElement item, string elementName, string defaultValue = "")
|
2013-08-06 04:45:57 +02:00
|
|
|
|
{
|
|
|
|
|
var element = item.Element(elementName);
|
|
|
|
|
|
|
|
|
|
return element != null ? element.Value : defaultValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|