2013-04-07 10:30:37 +03:00
|
|
|
using System;
|
2013-08-06 05:45:57 +03:00
|
|
|
using System.Drawing;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Xml.Linq;
|
2013-08-13 05:14:03 +03:00
|
|
|
using NLog;
|
2013-04-15 04:41:39 +03:00
|
|
|
using NzbDrone.Core.Parser.Model;
|
2013-04-07 10:30:37 +03:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Indexers.Newznab
|
|
|
|
{
|
|
|
|
public class NewznabParser : BasicRssParser
|
|
|
|
{
|
2013-08-06 08:06:58 +03:00
|
|
|
private static readonly XNamespace NewznabNamespace = "http://www.newznab.com/DTD/2010/feeds/attributes/";
|
2013-04-07 10:30:37 +03:00
|
|
|
|
2013-08-06 05:45:57 +03:00
|
|
|
protected override string GetNzbInfoUrl(XElement item)
|
2013-04-07 10:30:37 +03:00
|
|
|
{
|
2013-08-06 05:45:57 +03:00
|
|
|
return item.Comments().Replace("#comments", "");
|
2013-04-07 10:30:37 +03:00
|
|
|
}
|
|
|
|
|
2013-08-06 05:45:57 +03:00
|
|
|
protected override ReportInfo PostProcessor(XElement item, ReportInfo currentResult)
|
2013-04-07 10:30:37 +03:00
|
|
|
{
|
|
|
|
if (currentResult != null)
|
|
|
|
{
|
2013-08-19 08:53:26 +03:00
|
|
|
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));
|
2013-08-13 05:14:03 +03:00
|
|
|
|
|
|
|
if (sizeElement == null)
|
|
|
|
{
|
2013-08-14 08:25:53 +03:00
|
|
|
throw new SizeParsingException("Unable to parse size from: {0} [{1}]", currentResult.Title, currentResult.Indexer);
|
2013-08-13 05:14:03 +03:00
|
|
|
}
|
2013-04-07 10:30:37 +03:00
|
|
|
|
2013-08-06 05:45:57 +03:00
|
|
|
currentResult.Size = Convert.ToInt64(sizeElement.Attribute("value").Value);
|
2013-08-19 08:53:26 +03:00
|
|
|
|
|
|
|
if (rageIdElement != null)
|
|
|
|
{
|
|
|
|
currentResult.TvRageId = Convert.ToInt32(rageIdElement.Attribute("value").Value);
|
|
|
|
}
|
2013-04-07 10:30:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return currentResult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|