1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-01 00:12:30 +01:00
Sonarr/NzbDrone.Core/Indexers/Newznab/NewznabParser.cs

37 lines
1.2 KiB
C#
Raw Normal View History

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