|
|
|
@ -2,8 +2,8 @@ using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.ServiceModel.Syndication;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
|
|
|
|
|
|
|
|
@ -25,27 +25,27 @@ namespace NzbDrone.Core.Indexers
|
|
|
|
|
|
|
|
|
|
public IEnumerable<ReportInfo> Process(Stream source)
|
|
|
|
|
{
|
|
|
|
|
//TODO: replace this BS with plain Linq to XML
|
|
|
|
|
var reader = new SyndicationFeedXmlReader(source);
|
|
|
|
|
var feed = SyndicationFeed.Load(reader).Items;
|
|
|
|
|
var xdoc = XDocument.Load(source);
|
|
|
|
|
var items = xdoc.Descendants("item");
|
|
|
|
|
|
|
|
|
|
var result = new List<ReportInfo>();
|
|
|
|
|
|
|
|
|
|
foreach (var syndicationItem in feed)
|
|
|
|
|
foreach (var item in items)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var parsedEpisode = ParseFeed(syndicationItem);
|
|
|
|
|
if (parsedEpisode != null)
|
|
|
|
|
var reportInfo = ParseFeedItem(item);
|
|
|
|
|
if (reportInfo != null)
|
|
|
|
|
{
|
|
|
|
|
parsedEpisode.NzbUrl = GetNzbUrl(syndicationItem);
|
|
|
|
|
parsedEpisode.NzbInfoUrl = GetNzbInfoUrl(syndicationItem);
|
|
|
|
|
result.Add(parsedEpisode);
|
|
|
|
|
reportInfo.NzbUrl = GetNzbUrl(item);
|
|
|
|
|
reportInfo.NzbInfoUrl = GetNzbInfoUrl(item);
|
|
|
|
|
|
|
|
|
|
result.Add(reportInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception itemEx)
|
|
|
|
|
{
|
|
|
|
|
itemEx.Data.Add("Item", syndicationItem.Title);
|
|
|
|
|
itemEx.Data.Add("Item", item.Title());
|
|
|
|
|
_logger.ErrorException("An error occurred while processing feed item", itemEx);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -54,37 +54,37 @@ namespace NzbDrone.Core.Indexers
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual string GetTitle(SyndicationItem syndicationItem)
|
|
|
|
|
protected virtual string GetTitle(XElement item)
|
|
|
|
|
{
|
|
|
|
|
return syndicationItem.Title.Text;
|
|
|
|
|
return item.Title();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual string GetNzbUrl(SyndicationItem item)
|
|
|
|
|
protected virtual string GetNzbUrl(XElement item)
|
|
|
|
|
{
|
|
|
|
|
return item.Links[0].Uri.ToString();
|
|
|
|
|
return item.Links()[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual string GetNzbInfoUrl(SyndicationItem item)
|
|
|
|
|
protected virtual string GetNzbInfoUrl(XElement item)
|
|
|
|
|
{
|
|
|
|
|
return String.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual ReportInfo PostProcessor(SyndicationItem item, ReportInfo currentResult)
|
|
|
|
|
protected virtual ReportInfo PostProcessor(XElement item, ReportInfo currentResult)
|
|
|
|
|
{
|
|
|
|
|
return currentResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ReportInfo ParseFeed(SyndicationItem item)
|
|
|
|
|
private ReportInfo ParseFeedItem(XElement item)
|
|
|
|
|
{
|
|
|
|
|
var title = GetTitle(item);
|
|
|
|
|
|
|
|
|
|
var reportInfo = new ReportInfo();
|
|
|
|
|
|
|
|
|
|
reportInfo.Title = title;
|
|
|
|
|
reportInfo.Age = DateTime.Now.Date.Subtract(item.PublishDate.Date).Days;
|
|
|
|
|
reportInfo.Age = DateTime.Now.Date.Subtract(item.PublishDate().Date).Days;
|
|
|
|
|
reportInfo.ReleaseGroup = ParseReleaseGroup(title);
|
|
|
|
|
|
|
|
|
|
_logger.Trace("Parsed: {0} from: {1}", reportInfo, item.Title.Text);
|
|
|
|
|
_logger.Trace("Parsed: {0} from: {1}", reportInfo, item.Title());
|
|
|
|
|
|
|
|
|
|
return PostProcessor(item, reportInfo);
|
|
|
|
|
}
|
|
|
|
|