sonarr-repo-only/NzbDrone.Core/Indexers/Nzbx/NzbxParser.cs

51 lines
1.7 KiB
C#
Raw Normal View History

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;
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);
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
{
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;
}
}
}