Set up framework for artist indexer searching

pull/18/head
Daniel Underwood 7 years ago
parent bb196e19e1
commit 6ba2821828

@ -0,0 +1,11 @@
using NzbDrone.Core.Messaging.Commands;
namespace NzbDrone.Core.IndexerSearch
{
class AlbumSearchCommand : Command
{
public int AlbumId { get; set; }
public override bool SendUpdatesToClient => true;
}
}

@ -0,0 +1,31 @@
using NLog;
using NzbDrone.Common.Instrumentation.Extensions;
using NzbDrone.Core.Download;
using NzbDrone.Core.Messaging.Commands;
namespace NzbDrone.Core.IndexerSearch
{
class AlbumSearchService : IExecute<AlbumSearchCommand>
{
private readonly ISearchForNzb _nzbSearchService;
private readonly IProcessDownloadDecisions _processDownloadDecisions;
private readonly Logger _logger;
public AlbumSearchService(ISearchForNzb nzbSearchService,
IProcessDownloadDecisions processDownloadDecisions,
Logger logger)
{
_nzbSearchService = nzbSearchService;
_processDownloadDecisions = processDownloadDecisions;
_logger = logger;
}
public void Execute(AlbumSearchCommand message)
{
var decisions = _nzbSearchService.AlbumSearch(message.AlbumId, false, message.Trigger == CommandTrigger.Manual);
var processed = _processDownloadDecisions.ProcessDecisions(decisions);
_logger.ProgressInfo("Album search completed. {0} reports downloaded.", processed.Grabbed.Count);
}
}
}

@ -0,0 +1,12 @@
using System;
namespace NzbDrone.Core.IndexerSearch.Definitions
{
public class AlbumSearchCriteria : SearchCriteriaBase
{
public override string ToString()
{
return $"[{Album.Title}]";
}
}
}

@ -14,13 +14,17 @@ namespace NzbDrone.Core.IndexerSearch.Definitions
private static readonly Regex NonWord = new Regex(@"[\W]", RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static readonly Regex BeginningThe = new Regex(@"^the\s", RegexOptions.IgnoreCase | RegexOptions.Compiled);
[System.Obsolete("Sonarr TV Stuff -- Shouldn't be needed for Lidarr")]
public Series Series { get; set; }
[System.Obsolete("Sonarr TV Stuff -- Shouldn't be needed for Lidarr")]
public List<string> SceneTitles { get; set; }
[System.Obsolete("Sonarr TV Stuff -- Shouldn't be needed for Lidarr")]
public List<Episode> Episodes { get; set; }
public virtual bool MonitoredEpisodesOnly { get; set; }
public virtual bool UserInvokedSearch { get; set; }
public Artist Artist { get; set; }
public Album Album { get; set; }
public List<Track> Tracks { get; set; }
public List<string> QueryTitles => SceneTitles.Select(GetQueryTitle).ToList();

@ -12,6 +12,7 @@ using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Tv;
using System.Linq;
using NzbDrone.Common.TPL;
using NzbDrone.Core.Music;
namespace NzbDrone.Core.IndexerSearch
{
@ -20,14 +21,19 @@ namespace NzbDrone.Core.IndexerSearch
List<DownloadDecision> EpisodeSearch(int episodeId, bool userInvokedSearch);
List<DownloadDecision> EpisodeSearch(Episode episode, bool userInvokedSearch);
List<DownloadDecision> SeasonSearch(int seriesId, int seasonNumber, bool missingOnly, bool userInvokedSearch);
List<DownloadDecision> AlbumSearch(int albumId, bool missingOnly, bool userInvokedSearch);
}
public class NzbSearchService : ISearchForNzb
{
private readonly IIndexerFactory _indexerFactory;
// private readonly ISceneMappingService _sceneMapping;
[System.Obsolete("Used for sonarr, not lidarr")]
private readonly ISeriesService _seriesService;
[System.Obsolete("Used for sonarr, not lidarr")]
private readonly IEpisodeService _episodeService;
private readonly IAlbumService _albumService;
private readonly IMakeDownloadDecision _makeDownloadDecision;
private readonly Logger _logger;
@ -35,6 +41,7 @@ namespace NzbDrone.Core.IndexerSearch
// ISceneMappingService sceneMapping,
ISeriesService seriesService,
IEpisodeService episodeService,
IAlbumService albumService,
IMakeDownloadDecision makeDownloadDecision,
Logger logger)
{
@ -42,6 +49,7 @@ namespace NzbDrone.Core.IndexerSearch
//_sceneMapping = sceneMapping;
_seriesService = seriesService;
_episodeService = episodeService;
_albumService = albumService;
_makeDownloadDecision = makeDownloadDecision;
_logger = logger;
}
@ -158,6 +166,18 @@ namespace NzbDrone.Core.IndexerSearch
return downloadDecisions;
}
public List<DownloadDecision> AlbumSearch(int albumId, bool missingOnly, bool userInvokedSearch)
{
var album = _albumService.GetAlbum(1);
return AlbumSearch(album, missingOnly, userInvokedSearch);
}
public List<DownloadDecision> AlbumSearch(Album album, bool missingOnly, bool userInvokedSearch)
{
var searchSpec = Get<AlbumSearchCriteria>(album, userInvokedSearch);
return Dispatch(indexer => indexer.Fetch(searchSpec), searchSpec);
}
private List<DownloadDecision> SearchSingle(Series series, Episode episode, bool userInvokedSearch)
{
var searchSpec = Get<SingleEpisodeSearchCriteria>(series, new List<Episode> { episode }, userInvokedSearch);
@ -245,6 +265,16 @@ namespace NzbDrone.Core.IndexerSearch
return spec;
}
private TSpec Get<TSpec>(Album album, bool userInvokedSearch) where TSpec : SearchCriteriaBase, new()
{
var spec = new TSpec();
spec.Album = album;
spec.UserInvokedSearch = userInvokedSearch;
return spec;
}
private List<DownloadDecision> Dispatch(Func<IIndexer, IEnumerable<ReleaseInfo>> searchAction, SearchCriteriaBase criteriaBase)
{
var indexers = _indexerFactory.SearchEnabled();

@ -42,6 +42,11 @@ namespace NzbDrone.Core.Indexers.BitMeTv
return new IndexerPageableRequestChain();
}
public IndexerPageableRequestChain GetSearchRequests(AlbumSearchCriteria searchCriteria)
{
throw new System.NotImplementedException();
}
private IEnumerable<IndexerRequest> GetRssRequests()
{
var request = new IndexerRequest(string.Format("{0}/rss.php?uid={1}&passkey={2}", Settings.BaseUrl.Trim().TrimEnd('/'), Settings.UserId, Settings.RssPasskey), HttpAccept.Html);

@ -160,6 +160,11 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet
return new IndexerPageableRequestChain();
}
public IndexerPageableRequestChain GetSearchRequests(AlbumSearchCriteria searchCriteria)
{
throw new System.NotImplementedException();
}
private bool AddSeriesSearchParameters(BroadcastheNetTorrentQuery parameters, SearchCriteriaBase searchCriteria)
{
if (searchCriteria.Series.TvdbId != 0)

@ -60,6 +60,11 @@ namespace NzbDrone.Core.Indexers.Fanzub
return new IndexerPageableRequestChain();
}
public IndexerPageableRequestChain GetSearchRequests(AlbumSearchCriteria searchCriteria)
{
throw new System.NotImplementedException();
}
private IEnumerable<IndexerRequest> GetPagedRequests(string query)
{
var url = new StringBuilder();

@ -43,6 +43,11 @@ namespace NzbDrone.Core.Indexers.HDBits
return new IndexerPageableRequestChain();
}
public IndexerPageableRequestChain GetSearchRequests(AlbumSearchCriteria searchCriteria)
{
throw new System.NotImplementedException();
}
public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
{
var pageableRequests = new IndexerPageableRequestChain();

@ -51,6 +51,7 @@ namespace NzbDrone.Core.Indexers
return FetchReleases(generator.GetRecentRequests(), true);
}
[System.Obsolete("Sonarr TV Stuff -- Shouldn't be needed for Lidarr")]
public override IList<ReleaseInfo> Fetch(SingleEpisodeSearchCriteria searchCriteria)
{
if (!SupportsSearch)
@ -63,6 +64,7 @@ namespace NzbDrone.Core.Indexers
return FetchReleases(generator.GetSearchRequests(searchCriteria));
}
[System.Obsolete("Sonarr TV Stuff -- Shouldn't be needed for Lidarr")]
public override IList<ReleaseInfo> Fetch(SeasonSearchCriteria searchCriteria)
{
if (!SupportsSearch)
@ -75,6 +77,7 @@ namespace NzbDrone.Core.Indexers
return FetchReleases(generator.GetSearchRequests(searchCriteria));
}
[System.Obsolete("Sonarr TV Stuff -- Shouldn't be needed for Lidarr")]
public override IList<ReleaseInfo> Fetch(DailyEpisodeSearchCriteria searchCriteria)
{
if (!SupportsSearch)
@ -87,6 +90,7 @@ namespace NzbDrone.Core.Indexers
return FetchReleases(generator.GetSearchRequests(searchCriteria));
}
[System.Obsolete("Sonarr TV Stuff -- Shouldn't be needed for Lidarr")]
public override IList<ReleaseInfo> Fetch(AnimeEpisodeSearchCriteria searchCriteria)
{
if (!SupportsSearch)
@ -99,6 +103,7 @@ namespace NzbDrone.Core.Indexers
return FetchReleases(generator.GetSearchRequests(searchCriteria));
}
[System.Obsolete("Sonarr TV Stuff -- Shouldn't be needed for Lidarr")]
public override IList<ReleaseInfo> Fetch(SpecialEpisodeSearchCriteria searchCriteria)
{
if (!SupportsSearch)
@ -111,6 +116,18 @@ namespace NzbDrone.Core.Indexers
return FetchReleases(generator.GetSearchRequests(searchCriteria));
}
public override IList<ReleaseInfo> Fetch(AlbumSearchCriteria searchCriteria)
{
if (!SupportsSearch)
{
return new List<ReleaseInfo>();
}
var generator = GetRequestGenerator();
return FetchReleases(generator.GetSearchRequests(searchCriteria));
}
protected virtual IList<ReleaseInfo> FetchReleases(IndexerPageableRequestChain pageableRequestChain, bool isRecent = false)
{
var releases = new List<ReleaseInfo>();

@ -17,5 +17,6 @@ namespace NzbDrone.Core.Indexers
IList<ReleaseInfo> Fetch(DailyEpisodeSearchCriteria searchCriteria);
IList<ReleaseInfo> Fetch(AnimeEpisodeSearchCriteria searchCriteria);
IList<ReleaseInfo> Fetch(SpecialEpisodeSearchCriteria searchCriteria);
IList<ReleaseInfo> Fetch(AlbumSearchCriteria searchCriteria);
}
}

@ -10,5 +10,6 @@ namespace NzbDrone.Core.Indexers
IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria);
IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria);
IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria);
IndexerPageableRequestChain GetSearchRequests(AlbumSearchCriteria searchCriteria);
}
}

@ -42,6 +42,11 @@ namespace NzbDrone.Core.Indexers.IPTorrents
return new IndexerPageableRequestChain();
}
public IndexerPageableRequestChain GetSearchRequests(AlbumSearchCriteria searchCriteria)
{
throw new System.NotImplementedException();
}
private IEnumerable<IndexerRequest> GetRssRequests()
{
yield return new IndexerRequest(Settings.Url, HttpAccept.Rss);

@ -67,6 +67,7 @@ namespace NzbDrone.Core.Indexers
public abstract IList<ReleaseInfo> Fetch(DailyEpisodeSearchCriteria searchCriteria);
public abstract IList<ReleaseInfo> Fetch(AnimeEpisodeSearchCriteria searchCriteria);
public abstract IList<ReleaseInfo> Fetch(SpecialEpisodeSearchCriteria searchCriteria);
public abstract IList<ReleaseInfo> Fetch(AlbumSearchCriteria searchCriteria);
protected virtual IList<ReleaseInfo> CleanupReleases(IEnumerable<ReleaseInfo> releases)
{

@ -180,6 +180,11 @@ namespace NzbDrone.Core.Indexers.Newznab
return pageableRequests;
}
public IndexerPageableRequestChain GetSearchRequests(AlbumSearchCriteria searchCriteria)
{
throw new System.NotImplementedException();
}
private void AddTvIdPageableRequests(IndexerPageableRequestChain chain, int maxPages, IEnumerable<int> categories, SearchCriteriaBase searchCriteria, string parameters)
{
var includeTvdbSearch = SupportsTvdbSearch && searchCriteria.Series.TvdbId > 0;

@ -74,6 +74,11 @@ namespace NzbDrone.Core.Indexers.Nyaa
return pageableRequests;
}
public IndexerPageableRequestChain GetSearchRequests(AlbumSearchCriteria searchCriteria)
{
throw new System.NotImplementedException();
}
private IEnumerable<IndexerRequest> GetPagedRequests(int maxPages, string term)
{
var baseUrl = string.Format("{0}/?page=rss{1}", Settings.BaseUrl.TrimEnd('/'), Settings.AdditionalParameters);

@ -88,6 +88,11 @@ namespace NzbDrone.Core.Indexers.Omgwtfnzbs
return pageableRequests;
}
public IndexerPageableRequestChain GetSearchRequests(AlbumSearchCriteria searchCriteria)
{
throw new System.NotImplementedException();
}
private IEnumerable<IndexerRequest> GetPagedRequests(string query)
{
var url = new StringBuilder();

@ -18,6 +18,7 @@ namespace NzbDrone.Core.Indexers.Rarbg
public override string Name => "Rarbg";
public override DownloadProtocol Protocol => DownloadProtocol.Torrent;
public override TimeSpan RateLimit => TimeSpan.FromSeconds(2);
public Rarbg(IRarbgTokenProvider tokenProvider, IHttpClient httpClient, IIndexerStatusService indexerStatusService, IConfigService configService, IParsingService parsingService, Logger logger)

@ -72,6 +72,15 @@ namespace NzbDrone.Core.Indexers.Rarbg
return pageableRequests;
}
public IndexerPageableRequestChain GetSearchRequests(AlbumSearchCriteria searchCriteria)
{
var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.Add(GetPagedRequests("search", null, "{0}", searchCriteria.Album.Title));
return pageableRequests;
}
private IEnumerable<IndexerRequest> GetPagedRequests(string mode, int? tvdbId, string query, params object[] args)
{
var requestBuilder = new HttpRequestBuilder(Settings.BaseUrl)

@ -46,5 +46,10 @@ namespace NzbDrone.Core.Indexers
{
return new IndexerPageableRequestChain();
}
public IndexerPageableRequestChain GetSearchRequests(AlbumSearchCriteria searchCriteria)
{
throw new System.NotImplementedException();
}
}
}

@ -43,6 +43,11 @@ namespace NzbDrone.Core.Indexers.TorrentRss
return new IndexerPageableRequestChain();
}
public IndexerPageableRequestChain GetSearchRequests(AlbumSearchCriteria searchCriteria)
{
throw new System.NotImplementedException();
}
private IEnumerable<IndexerRequest> GetRssRequests(string searchParameters)
{
var request = new IndexerRequest(Settings.BaseUrl.Trim().TrimEnd('/'), HttpAccept.Rss);

@ -42,6 +42,11 @@ namespace NzbDrone.Core.Indexers.Torrentleech
return new IndexerPageableRequestChain();
}
public IndexerPageableRequestChain GetSearchRequests(AlbumSearchCriteria searchCriteria)
{
throw new System.NotImplementedException();
}
private IEnumerable<IndexerRequest> GetRssRequests(string searchParameters)
{
yield return new IndexerRequest(string.Format("{0}/{1}{2}", Settings.BaseUrl.Trim().TrimEnd('/'), Settings.ApiKey, searchParameters), HttpAccept.Rss);

@ -605,6 +605,9 @@
<Compile Include="Http\CloudFlare\CloudFlareHttpInterceptor.cs" />
<Compile Include="Http\HttpProxySettingsProvider.cs" />
<Compile Include="Http\TorcacheHttpInterceptor.cs" />
<Compile Include="IndexerSearch\AlbumSearchCommand.cs" />
<Compile Include="IndexerSearch\AlbumSearchService.cs" />
<Compile Include="IndexerSearch\Definitions\AlbumSearchCriteria.cs" />
<Compile Include="Indexers\BitMeTv\BitMeTv.cs" />
<Compile Include="Indexers\BitMeTv\BitMeTvSettings.cs" />
<Compile Include="Indexers\BitMeTv\BitMeTvRequestGenerator.cs" />

Loading…
Cancel
Save