2013-04-07 07:30:37 +00:00
|
|
|
using System;
|
2013-08-06 05:30:56 +00:00
|
|
|
using System.Linq;
|
2013-04-07 07:30:37 +00:00
|
|
|
using System.Text.RegularExpressions;
|
2013-08-06 02:45:57 +00:00
|
|
|
using System.Xml.Linq;
|
2013-06-08 17:29:19 +00:00
|
|
|
using NLog;
|
2013-04-15 01:41:39 +00:00
|
|
|
using NzbDrone.Core.Parser.Model;
|
2013-04-07 07:30:37 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Indexers.NzbClub
|
|
|
|
{
|
2013-09-13 23:17:58 +00:00
|
|
|
public class NzbClubParser : RssParserBase
|
2013-04-07 07:30:37 +00:00
|
|
|
{
|
2013-06-08 17:29:19 +00:00
|
|
|
|
|
|
|
private static readonly Regex SizeRegex = new Regex(@"(?:Size:)\s(?<size>\d+.\d+\s[g|m]i?[b])", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
|
|
|
|
|
|
|
|
2013-09-13 23:17:58 +00:00
|
|
|
protected override long GetSize(XElement item)
|
2013-04-07 07:30:37 +00:00
|
|
|
{
|
2013-09-13 23:17:58 +00:00
|
|
|
logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
|
|
if (match.Success && match.Groups["size"].Success)
|
2013-04-07 07:30:37 +00:00
|
|
|
{
|
2013-09-13 23:17:58 +00:00
|
|
|
return ParseSize(match.Groups["size"].Value);
|
2013-04-07 07:30:37 +00:00
|
|
|
}
|
|
|
|
|
2013-09-13 23:17:58 +00:00
|
|
|
return 0;
|
2013-04-07 07:30:37 +00:00
|
|
|
}
|
|
|
|
|
2013-08-06 02:45:57 +00:00
|
|
|
protected override string GetTitle(XElement item)
|
2013-04-07 07:30:37 +00:00
|
|
|
{
|
2013-08-06 02:45:57 +00:00
|
|
|
var title = ParseHeader(item.Title());
|
2013-04-07 07:30:37 +00:00
|
|
|
|
|
|
|
if (String.IsNullOrWhiteSpace(title))
|
2013-08-06 02:45:57 +00:00
|
|
|
return item.Title();
|
2013-04-07 07:30:37 +00:00
|
|
|
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
2013-09-13 23:17:58 +00:00
|
|
|
private static readonly Regex[] HeaderRegex = new[]
|
|
|
|
{
|
|
|
|
new Regex(@"(?:\[.+\]\-\[.+\]\-\[.+\]\-\[)(?<nzbTitle>.+)(?:\]\-.+)",
|
|
|
|
RegexOptions.IgnoreCase),
|
|
|
|
|
|
|
|
new Regex(@"(?:\[.+\]\W+\[.+\]\W+\[.+\]\W+\"")(?<nzbTitle>.+)(?:\"".+)",
|
|
|
|
RegexOptions.IgnoreCase),
|
|
|
|
|
|
|
|
new Regex(@"(?:\[)(?<nzbTitle>.+)(?:\]\-.+)",
|
|
|
|
RegexOptions.IgnoreCase),
|
|
|
|
};
|
|
|
|
|
|
|
|
private static string ParseHeader(string header)
|
|
|
|
{
|
|
|
|
foreach (var regex in HeaderRegex)
|
|
|
|
{
|
|
|
|
var match = regex.Matches(header);
|
|
|
|
|
|
|
|
if (match.Count != 0)
|
|
|
|
return match[0].Groups["nzbTitle"].Value.Trim();
|
|
|
|
}
|
|
|
|
|
|
|
|
return header;
|
|
|
|
}
|
|
|
|
|
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 05:30:56 +00:00
|
|
|
return item.Links().First();
|
2013-08-06 02:45:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override string GetNzbUrl(XElement item)
|
|
|
|
{
|
|
|
|
var enclosure = item.Element("enclosure");
|
|
|
|
|
|
|
|
return enclosure.Attribute("url").Value;
|
2013-04-07 07:30:37 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-13 23:17:58 +00:00
|
|
|
}
|