Sonarr/NzbDrone.Core/Indexers/Nzbx/NzbxParser.cs

50 lines
1.6 KiB
C#
Raw Normal View History

2013-04-07 07:30:37 +00:00
using System;
using System.Collections.Generic;
using System.IO;
using NLog;
using Newtonsoft.Json;
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;
public NzbxParser()
2013-04-07 07:30:37 +00:00
{
_logger = LogManager.GetCurrentClassLogger();
2013-04-07 07:30:37 +00:00
_serializer = new JsonSerializer();
}
public IEnumerable<ReportInfo> Process(Stream source)
2013-04-07 07:30:37 +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);
foreach (var item in feed)
{
try
{
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
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;
}
}
}