mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-29 02:57:15 +02:00
70 lines
2.0 KiB
C#
70 lines
2.0 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using NLog;
|
|
using NzbDrone.Core.Parser.Model;
|
|
using NzbDrone.Common.TPL;
|
|
|
|
namespace NzbDrone.Core.Indexers
|
|
{
|
|
public interface IFetchAndParseRss
|
|
{
|
|
List<ReleaseInfo> Fetch();
|
|
}
|
|
|
|
public class FetchAndParseRssService : IFetchAndParseRss
|
|
{
|
|
private readonly IIndexerFactory _indexerFactory;
|
|
private readonly IFetchFeedFromIndexers _feedFetcher;
|
|
private readonly Logger _logger;
|
|
|
|
public FetchAndParseRssService(IIndexerFactory indexerFactory, IFetchFeedFromIndexers feedFetcher, Logger logger)
|
|
{
|
|
_indexerFactory = indexerFactory;
|
|
_feedFetcher = feedFetcher;
|
|
_logger = logger;
|
|
}
|
|
|
|
public List<ReleaseInfo> Fetch()
|
|
{
|
|
var result = new List<ReleaseInfo>();
|
|
|
|
var indexers = _indexerFactory.GetAvailableProviders().ToList();
|
|
|
|
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);
|
|
}
|
|
}).LogExceptions();
|
|
|
|
taskList.Add(task);
|
|
}
|
|
|
|
Task.WaitAll(taskList.ToArray());
|
|
|
|
_logger.Debug("Found {0} reports", result.Count);
|
|
|
|
return result;
|
|
}
|
|
}
|
|
} |