mirror of https://github.com/lidarr/Lidarr
Add artist search framework code
This commit is contained in:
parent
6ecaa4b97f
commit
f40918ddb8
|
@ -0,0 +1,11 @@
|
|||
using NzbDrone.Core.Messaging.Commands;
|
||||
|
||||
namespace NzbDrone.Core.IndexerSearch
|
||||
{
|
||||
class ArtistSearchCommand : Command
|
||||
{
|
||||
public int ArtistId { 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 ArtistSearchService : IExecute<ArtistSearchCommand>
|
||||
{
|
||||
private readonly ISearchForNzb _nzbSearchService;
|
||||
private readonly IProcessDownloadDecisions _processDownloadDecisions;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public ArtistSearchService(ISearchForNzb nzbSearchService,
|
||||
IProcessDownloadDecisions processDownloadDecisions,
|
||||
Logger logger)
|
||||
{
|
||||
_nzbSearchService = nzbSearchService;
|
||||
_processDownloadDecisions = processDownloadDecisions;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Execute(ArtistSearchCommand message)
|
||||
{
|
||||
var decisions = _nzbSearchService.ArtistSearch(message.ArtistId, false, message.Trigger == CommandTrigger.Manual);
|
||||
var processed = _processDownloadDecisions.ProcessDecisions(decisions);
|
||||
|
||||
_logger.ProgressInfo("Artist search completed. {0} reports downloaded.", processed.Grabbed.Count);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
|
||||
namespace NzbDrone.Core.IndexerSearch.Definitions
|
||||
{
|
||||
public class ArtistSearchCriteria : SearchCriteriaBase
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[{Artist.Name}]";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,6 +22,7 @@ namespace NzbDrone.Core.IndexerSearch
|
|||
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);
|
||||
List<DownloadDecision> ArtistSearch(int artistId, bool missingOnly, bool userInvokedSearch);
|
||||
}
|
||||
|
||||
public class NzbSearchService : ISearchForNzb
|
||||
|
@ -175,6 +176,18 @@ namespace NzbDrone.Core.IndexerSearch
|
|||
return AlbumSearch(album, missingOnly, userInvokedSearch);
|
||||
}
|
||||
|
||||
public List<DownloadDecision> ArtistSearch(int artistId, bool missingOnly, bool userInvokedSearch)
|
||||
{
|
||||
var artist = _artistService.GetArtist(artistId);
|
||||
return ArtistSearch(artist, missingOnly, userInvokedSearch);
|
||||
}
|
||||
|
||||
public List<DownloadDecision> ArtistSearch(Artist artist, bool missingOnly, bool userInvokedSearch)
|
||||
{
|
||||
var searchSpec = Get<ArtistSearchCriteria>(artist, userInvokedSearch);
|
||||
return Dispatch(indexer => indexer.Fetch(searchSpec), searchSpec);
|
||||
}
|
||||
|
||||
public List<DownloadDecision> AlbumSearch(Album album, bool missingOnly, bool userInvokedSearch)
|
||||
{
|
||||
var searchSpec = Get<AlbumSearchCriteria>(album, userInvokedSearch);
|
||||
|
@ -280,6 +293,16 @@ namespace NzbDrone.Core.IndexerSearch
|
|||
return spec;
|
||||
}
|
||||
|
||||
private TSpec Get<TSpec>(Artist artist, bool userInvokedSearch) where TSpec : SearchCriteriaBase, new()
|
||||
{
|
||||
var spec = new TSpec();
|
||||
;
|
||||
spec.Artist = artist;
|
||||
spec.UserInvokedSearch = userInvokedSearch;
|
||||
|
||||
return spec;
|
||||
}
|
||||
|
||||
private List<DownloadDecision> Dispatch(Func<IIndexer, IEnumerable<ReleaseInfo>> searchAction, SearchCriteriaBase criteriaBase)
|
||||
{
|
||||
var indexers = _indexerFactory.SearchEnabled();
|
||||
|
|
|
@ -47,6 +47,11 @@ namespace NzbDrone.Core.Indexers.BitMeTv
|
|||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public IndexerPageableRequestChain GetSearchRequests(ArtistSearchCriteria 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);
|
||||
|
|
|
@ -165,6 +165,11 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet
|
|||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public IndexerPageableRequestChain GetSearchRequests(ArtistSearchCriteria searchCriteria)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
private bool AddSeriesSearchParameters(BroadcastheNetTorrentQuery parameters, SearchCriteriaBase searchCriteria)
|
||||
{
|
||||
if (searchCriteria.Series.TvdbId != 0)
|
||||
|
|
|
@ -65,6 +65,11 @@ namespace NzbDrone.Core.Indexers.Fanzub
|
|||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public IndexerPageableRequestChain GetSearchRequests(ArtistSearchCriteria searchCriteria)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
private IEnumerable<IndexerRequest> GetPagedRequests(string query)
|
||||
{
|
||||
var url = new StringBuilder();
|
||||
|
|
|
@ -48,6 +48,11 @@ namespace NzbDrone.Core.Indexers.HDBits
|
|||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public IndexerPageableRequestChain GetSearchRequests(ArtistSearchCriteria searchCriteria)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
|
||||
{
|
||||
var pageableRequests = new IndexerPageableRequestChain();
|
||||
|
|
|
@ -128,6 +128,18 @@ namespace NzbDrone.Core.Indexers
|
|||
return FetchReleases(generator.GetSearchRequests(searchCriteria));
|
||||
}
|
||||
|
||||
public override IList<ReleaseInfo> Fetch(ArtistSearchCriteria 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>();
|
||||
|
|
|
@ -23,5 +23,6 @@ namespace NzbDrone.Core.Indexers
|
|||
[System.Obsolete("Sonarr TV Stuff -- Shouldn't be needed for Lidarr")]
|
||||
IList<ReleaseInfo> Fetch(SpecialEpisodeSearchCriteria searchCriteria);
|
||||
IList<ReleaseInfo> Fetch(AlbumSearchCriteria searchCriteria);
|
||||
IList<ReleaseInfo> Fetch(ArtistSearchCriteria searchCriteria);
|
||||
}
|
||||
}
|
|
@ -11,5 +11,6 @@ namespace NzbDrone.Core.Indexers
|
|||
IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria);
|
||||
IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria);
|
||||
IndexerPageableRequestChain GetSearchRequests(AlbumSearchCriteria searchCriteria);
|
||||
IndexerPageableRequestChain GetSearchRequests(ArtistSearchCriteria searchCriteria);
|
||||
}
|
||||
}
|
|
@ -47,6 +47,11 @@ namespace NzbDrone.Core.Indexers.IPTorrents
|
|||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public IndexerPageableRequestChain GetSearchRequests(ArtistSearchCriteria searchCriteria)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
private IEnumerable<IndexerRequest> GetRssRequests()
|
||||
{
|
||||
yield return new IndexerRequest(Settings.Url, HttpAccept.Rss);
|
||||
|
|
|
@ -74,6 +74,7 @@ namespace NzbDrone.Core.Indexers
|
|||
[System.Obsolete("Sonarr TV Stuff -- Shouldn't be needed for Lidarr")]
|
||||
public abstract IList<ReleaseInfo> Fetch(SpecialEpisodeSearchCriteria searchCriteria);
|
||||
public abstract IList<ReleaseInfo> Fetch(AlbumSearchCriteria searchCriteria);
|
||||
public abstract IList<ReleaseInfo> Fetch(ArtistSearchCriteria searchCriteria);
|
||||
|
||||
protected virtual IList<ReleaseInfo> CleanupReleases(IEnumerable<ReleaseInfo> releases)
|
||||
{
|
||||
|
|
|
@ -185,6 +185,11 @@ namespace NzbDrone.Core.Indexers.Newznab
|
|||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public IndexerPageableRequestChain GetSearchRequests(ArtistSearchCriteria 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;
|
||||
|
|
|
@ -79,6 +79,11 @@ namespace NzbDrone.Core.Indexers.Nyaa
|
|||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public IndexerPageableRequestChain GetSearchRequests(ArtistSearchCriteria 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);
|
||||
|
|
|
@ -93,6 +93,11 @@ namespace NzbDrone.Core.Indexers.Omgwtfnzbs
|
|||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public IndexerPageableRequestChain GetSearchRequests(ArtistSearchCriteria searchCriteria)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
private IEnumerable<IndexerRequest> GetPagedRequests(string query)
|
||||
{
|
||||
var url = new StringBuilder();
|
||||
|
|
|
@ -86,6 +86,15 @@ namespace NzbDrone.Core.Indexers.Rarbg
|
|||
return pageableRequests;
|
||||
}
|
||||
|
||||
public IndexerPageableRequestChain GetSearchRequests(ArtistSearchCriteria searchCriteria)
|
||||
{
|
||||
var pageableRequests = new IndexerPageableRequestChain();
|
||||
|
||||
pageableRequests.Add(GetPagedRequests("search", null, "{0}", searchCriteria.Artist.Name));
|
||||
|
||||
return pageableRequests;
|
||||
}
|
||||
|
||||
private IEnumerable<IndexerRequest> GetPagedRequests(string mode, int? tvdbId, string query, params object[] args)
|
||||
{
|
||||
var requestBuilder = new HttpRequestBuilder(Settings.BaseUrl)
|
||||
|
|
|
@ -51,5 +51,10 @@ namespace NzbDrone.Core.Indexers
|
|||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public IndexerPageableRequestChain GetSearchRequests(ArtistSearchCriteria searchCriteria)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,11 @@ namespace NzbDrone.Core.Indexers.TorrentRss
|
|||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public IndexerPageableRequestChain GetSearchRequests(ArtistSearchCriteria searchCriteria)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
private IEnumerable<IndexerRequest> GetRssRequests(string searchParameters)
|
||||
{
|
||||
var request = new IndexerRequest(Settings.BaseUrl.Trim().TrimEnd('/'), HttpAccept.Rss);
|
||||
|
|
|
@ -47,6 +47,11 @@ namespace NzbDrone.Core.Indexers.Torrentleech
|
|||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public IndexerPageableRequestChain GetSearchRequests(ArtistSearchCriteria 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);
|
||||
|
|
|
@ -607,7 +607,10 @@
|
|||
<Compile Include="Http\TorcacheHttpInterceptor.cs" />
|
||||
<Compile Include="IndexerSearch\AlbumSearchCommand.cs" />
|
||||
<Compile Include="IndexerSearch\AlbumSearchService.cs" />
|
||||
<Compile Include="IndexerSearch\ArtistSearchCommand.cs" />
|
||||
<Compile Include="IndexerSearch\ArtistSearchService.cs" />
|
||||
<Compile Include="IndexerSearch\Definitions\AlbumSearchCriteria.cs" />
|
||||
<Compile Include="IndexerSearch\Definitions\ArtistSearchCriteria.cs" />
|
||||
<Compile Include="Indexers\BitMeTv\BitMeTv.cs" />
|
||||
<Compile Include="Indexers\BitMeTv\BitMeTvSettings.cs" />
|
||||
<Compile Include="Indexers\BitMeTv\BitMeTvRequestGenerator.cs" />
|
||||
|
|
Loading…
Reference in New Issue