2013-04-07 10:30:37 +03:00
|
|
|
using System;
|
2013-08-06 08:30:56 +03:00
|
|
|
using System.Linq;
|
2013-04-07 10:30:37 +03:00
|
|
|
using System.Text.RegularExpressions;
|
2013-08-06 05:45:57 +03:00
|
|
|
using System.Xml.Linq;
|
2013-06-08 20:29:19 +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.NzbClub
|
|
|
|
{
|
|
|
|
public class NzbClubParser : BasicRssParser
|
|
|
|
{
|
2013-06-08 20:29:19 +03:00
|
|
|
|
|
|
|
private static readonly Regex SizeRegex = new Regex(@"(?:Size:)\s(?<size>\d+.\d+\s[g|m]i?[b])", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
|
|
|
private readonly Logger logger;
|
|
|
|
|
|
|
|
public NzbClubParser()
|
|
|
|
{
|
|
|
|
logger = LogManager.GetCurrentClassLogger();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-06 05:45:57 +03:00
|
|
|
var match = SizeRegex.Match(item.Description());
|
2013-06-08 20:29:19 +03:00
|
|
|
|
|
|
|
if (match.Success && match.Groups["size"].Success)
|
|
|
|
{
|
|
|
|
currentResult.Size = GetReportSize(match.Groups["size"].Value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-06 05:45:57 +03:00
|
|
|
logger.Warn("Couldn't parse size from {0}", item.Description());
|
2013-06-08 20:29:19 +03:00
|
|
|
}
|
2013-04-07 10:30:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return currentResult;
|
|
|
|
}
|
|
|
|
|
2013-08-06 05:45:57 +03:00
|
|
|
protected override string GetTitle(XElement item)
|
2013-04-07 10:30:37 +03:00
|
|
|
{
|
2013-08-06 05:45:57 +03:00
|
|
|
var title = ParseHeader(item.Title());
|
2013-04-07 10:30:37 +03:00
|
|
|
|
|
|
|
if (String.IsNullOrWhiteSpace(title))
|
2013-08-06 05:45:57 +03:00
|
|
|
return item.Title();
|
2013-04-07 10:30:37 +03:00
|
|
|
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
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 08:30:56 +03:00
|
|
|
return item.Links().First();
|
2013-08-06 05:45:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override string GetNzbUrl(XElement item)
|
|
|
|
{
|
|
|
|
var enclosure = item.Element("enclosure");
|
|
|
|
|
|
|
|
return enclosure.Attribute("url").Value;
|
2013-04-07 10:30:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|