2013-04-07 07:30:37 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
2013-05-07 05:38:40 +00:00
|
|
|
using System.Linq;
|
2013-04-07 07:30:37 +00:00
|
|
|
using NLog;
|
|
|
|
using Newtonsoft.Json;
|
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.Nzbx
|
|
|
|
{
|
|
|
|
public class NzbxParser : IParseFeed
|
|
|
|
{
|
|
|
|
private readonly Logger _logger;
|
|
|
|
private readonly JsonSerializer _serializer;
|
|
|
|
|
2013-04-28 00:25:28 +00:00
|
|
|
public NzbxParser()
|
2013-04-07 07:30:37 +00:00
|
|
|
{
|
2013-04-28 00:25:28 +00:00
|
|
|
_logger = LogManager.GetCurrentClassLogger();
|
2013-04-07 07:30:37 +00:00
|
|
|
_serializer = new JsonSerializer();
|
|
|
|
}
|
|
|
|
|
2013-04-15 01:41:39 +00:00
|
|
|
public IEnumerable<ReportInfo> Process(Stream source)
|
2013-04-07 07:30:37 +00:00
|
|
|
{
|
2013-04-15 01:41:39 +00:00
|
|
|
var result = new List<ReportInfo>();
|
2013-04-07 07:30:37 +00:00
|
|
|
var jsonReader = new JsonTextReader(new StreamReader(source));
|
|
|
|
var feed = _serializer.Deserialize<List<NzbxRecentItem>>(jsonReader);
|
|
|
|
|
2013-05-07 05:38:40 +00:00
|
|
|
foreach (var item in feed.Where(c => !string.IsNullOrWhiteSpace(c.Name)))
|
2013-04-07 07:30:37 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2013-04-23 06:14:55 +00:00
|
|
|
var reportInfo = new ReportInfo();
|
|
|
|
reportInfo.Age = DateTime.Now.Date.Subtract(item.PostDate).Days;
|
|
|
|
reportInfo.Title = item.Name;
|
|
|
|
reportInfo.NzbUrl = String.Format("http://nzbx.co/nzb?{0}*|*{1}", item.Guid, item.Name);
|
|
|
|
reportInfo.NzbInfoUrl = String.Format("http://nzbx.co/d?{0}", item.Guid);
|
|
|
|
reportInfo.Size = item.Size;
|
2013-04-07 07:30:37 +00:00
|
|
|
|
2013-04-23 06:14:55 +00:00
|
|
|
result.Add(reportInfo);
|
2013-04-07 07:30:37 +00:00
|
|
|
}
|
|
|
|
catch (Exception itemEx)
|
|
|
|
{
|
|
|
|
itemEx.Data.Add("Item", item.Name);
|
|
|
|
_logger.ErrorException("An error occurred while processing feed item", itemEx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|