Sonarr/NzbDrone.Core/Indexers/Newznab/NewznabParser.cs

48 lines
1.7 KiB
C#
Raw Normal View History

2013-04-07 07:30:37 +00:00
using System;
2013-08-06 02:45:57 +00:00
using System.Drawing;
using System.Linq;
using System.Xml.Linq;
using NLog;
using NzbDrone.Core.Parser.Model;
2013-04-07 07:30:37 +00:00
namespace NzbDrone.Core.Indexers.Newznab
{
public class NewznabParser : BasicRssParser
{
2013-08-06 05:06:58 +00:00
private static readonly XNamespace NewznabNamespace = "http://www.newznab.com/DTD/2010/feeds/attributes/";
2013-04-07 07:30:37 +00:00
2013-08-06 02:45:57 +00:00
protected override string GetNzbInfoUrl(XElement item)
2013-04-07 07:30:37 +00:00
{
2013-08-06 02:45:57 +00:00
return item.Comments().Replace("#comments", "");
2013-04-07 07:30:37 +00:00
}
2013-08-06 02:45:57 +00:00
protected override ReportInfo PostProcessor(XElement item, ReportInfo currentResult)
2013-04-07 07:30:37 +00:00
{
if (currentResult != null)
{
var attributes = item.Elements(NewznabNamespace + "attr").ToList();
var sizeElement = attributes.SingleOrDefault(e => e.Attribute("name").Value.Equals("size", StringComparison.CurrentCultureIgnoreCase));
var rageIdElement = attributes.SingleOrDefault(e => e.Attribute("name").Value.Equals("rageid", StringComparison.CurrentCultureIgnoreCase));
if (sizeElement == null)
{
2013-08-14 05:25:53 +00:00
throw new SizeParsingException("Unable to parse size from: {0} [{1}]", currentResult.Title, currentResult.Indexer);
}
2013-04-07 07:30:37 +00:00
2013-08-06 02:45:57 +00:00
currentResult.Size = Convert.ToInt64(sizeElement.Attribute("value").Value);
if (rageIdElement != null)
{
int tvRageId;
if (Int32.TryParse(rageIdElement.Attribute("value").Value, out tvRageId))
{
currentResult.TvRageId = tvRageId;
}
}
2013-04-07 07:30:37 +00:00
}
return currentResult;
}
}
}