mirror of https://github.com/lidarr/Lidarr
Added EpisodeSearchJob, still needs unit tests
This commit is contained in:
parent
9417748056
commit
474f17c5e6
|
@ -175,6 +175,7 @@
|
|||
<Compile Include="Providers\Indexer\SyndicationFeedXmlReader.cs" />
|
||||
<Compile Include="Providers\AutoConfigureProvider.cs" />
|
||||
<Compile Include="Providers\Indexer\NzbMatrix.cs" />
|
||||
<Compile Include="Providers\Jobs\EpisodeSearchJob.cs" />
|
||||
<Compile Include="Providers\Jobs\DeleteSeriesJob.cs" />
|
||||
<Compile Include="Providers\Jobs\DiskScanJob.cs" />
|
||||
<Compile Include="Providers\Jobs\ImportNewSeriesJob.cs" />
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Providers.Indexer;
|
||||
|
||||
namespace NzbDrone.Core.Providers.Jobs
|
||||
{
|
||||
public class EpisodeSearchJob : IJob
|
||||
{
|
||||
private readonly IEnumerable<IndexerBase> _indexers;
|
||||
private readonly InventoryProvider _inventoryProvider;
|
||||
private readonly DownloadProvider _downloadProvider;
|
||||
private readonly IndexerProvider _indexerProvider;
|
||||
private readonly EpisodeProvider _episodeProvider;
|
||||
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public EpisodeSearchJob(IEnumerable<IndexerBase> indexers, InventoryProvider inventoryProvider, DownloadProvider downloadProvider, IndexerProvider indexerProvider, EpisodeProvider episodeProvider)
|
||||
{
|
||||
_indexers = indexers;
|
||||
_inventoryProvider = inventoryProvider;
|
||||
_downloadProvider = downloadProvider;
|
||||
_indexerProvider = indexerProvider;
|
||||
_episodeProvider = episodeProvider;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Episode Search"; }
|
||||
}
|
||||
|
||||
public int DefaultInterval
|
||||
{
|
||||
get { return 0; }
|
||||
}
|
||||
|
||||
public void Start(ProgressNotification notification, int targetId)
|
||||
{
|
||||
var reports = new List<EpisodeParseResult>();
|
||||
var episode = _episodeProvider.GetEpisode(targetId);
|
||||
|
||||
|
||||
foreach (var indexer in _indexers.Where(i => _indexerProvider.GetSettings(i.GetType()).Enable))
|
||||
{
|
||||
try
|
||||
{
|
||||
notification.CurrentMessage = String.Format("Searching for {0} in {1}", episode, indexer.Name);
|
||||
reports.AddRange(indexer.FetchRss());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorException("An error has occured while fetching items from " + indexer.Name, e);
|
||||
}
|
||||
}
|
||||
|
||||
Logger.Debug("Finished searching all indexers. Total {0}", reports.Count);
|
||||
notification.CurrentMessage = "Proccessing search results";
|
||||
|
||||
foreach (var episodeParseResult in reports.OrderBy(c => c.Quality).ThenBy(c => c.Proper))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_inventoryProvider.IsNeeded(episodeParseResult))
|
||||
{
|
||||
_downloadProvider.DownloadReport(episodeParseResult);
|
||||
notification.CurrentMessage = String.Format("{0} {1} Added to download queue", episode, episodeParseResult.Quality);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorException("An error has occured while processing parse result items from " + episodeParseResult, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Logger.Warn("Unable to find {0} in any of indexers.", episode);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -70,5 +70,13 @@ namespace NzbDrone.Core.Repository
|
|||
[SubSonicToManyRelation]
|
||||
public virtual IList<History> Histories { get; protected set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if (EpisodeNumber == 0)
|
||||
return string.Format("{0} - {1}", Series.Title, AirDate.Date);
|
||||
|
||||
return string.Format("{0} - S{1:00}E{2}", Series.Title, SeasonNumber, EpisodeNumber);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue