using System; using System.Linq; using System.Text.RegularExpressions; using System.Xml.Linq; using NLog; using NzbDrone.Core.Parser.Model; namespace NzbDrone.Core.Indexers.NzbClub { public class NzbClubParser : RssParserBase { private static readonly Regex SizeRegex = new Regex(@"(?:Size:)\s(?\d+.\d+\s[g|m]i?[b])", RegexOptions.Compiled | RegexOptions.IgnoreCase); protected override long GetSize(XElement item) { logger = LogManager.GetCurrentClassLogger(); if (match.Success && match.Groups["size"].Success) { return ParseSize(match.Groups["size"].Value); } return 0; } protected override string GetTitle(XElement item) { var title = ParseHeader(item.Title()); if (String.IsNullOrWhiteSpace(title)) return item.Title(); return title; } private static readonly Regex[] HeaderRegex = new[] { new Regex(@"(?:\[.+\]\-\[.+\]\-\[.+\]\-\[)(?.+)(?:\]\-.+)", RegexOptions.IgnoreCase), new Regex(@"(?:\[.+\]\W+\[.+\]\W+\[.+\]\W+\"")(?.+)(?:\"".+)", RegexOptions.IgnoreCase), new Regex(@"(?:\[)(?.+)(?:\]\-.+)", 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; } protected override string GetNzbInfoUrl(XElement item) { return item.Links().First(); } protected override string GetNzbUrl(XElement item) { var enclosure = item.Element("enclosure"); return enclosure.Attribute("url").Value; } } }