1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-16 16:04:08 +01:00
Radarr/NzbDrone.Core/Indexers/FetchAndParseRssService.cs

70 lines
2.0 KiB
C#
Raw Normal View History

2013-04-23 08:06:05 +02:00
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NLog;
using NzbDrone.Core.Parser.Model;
2013-07-12 08:10:34 +02:00
using NzbDrone.Common.TPL;
2013-04-23 08:06:05 +02:00
namespace NzbDrone.Core.Indexers
{
public interface IFetchAndParseRss
{
List<ReportInfo> Fetch();
}
public class FetchAndParseRssService : IFetchAndParseRss
{
private readonly IIndexerService _indexerService;
private readonly IFetchFeedFromIndexers _feedFetcher;
private readonly Logger _logger;
public FetchAndParseRssService(IIndexerService indexerService, IFetchFeedFromIndexers feedFetcher, Logger logger)
{
_indexerService = indexerService;
_feedFetcher = feedFetcher;
_logger = logger;
}
public List<ReportInfo> Fetch()
{
var result = new List<ReportInfo>();
var indexers = _indexerService.GetAvailableIndexers().ToList();
2013-04-23 08:06:05 +02:00
if (!indexers.Any())
{
_logger.Warn("No available indexers. check your configuration.");
return result;
}
_logger.Debug("Available indexers {0}", indexers.Count);
var taskList = new List<Task>();
var taskFactory = new TaskFactory(TaskCreationOptions.LongRunning, TaskContinuationOptions.None);
foreach (var indexer in indexers)
{
var indexerLocal = indexer;
var task = taskFactory.StartNew(() =>
{
var indexerFeed = _feedFetcher.FetchRss(indexerLocal);
lock (result)
{
result.AddRange(indexerFeed);
}
2013-07-12 08:10:34 +02:00
}).LogExceptions();
taskList.Add(task);
}
Task.WaitAll(taskList.ToArray());
2013-04-23 08:06:05 +02:00
_logger.Debug("Found {0} reports", result.Count);
return result;
}
}
}