mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 03:52:33 +02:00
New: TMDb Keyword List support (#6297)
This commit is contained in:
parent
446b2ffff9
commit
4300d8d8c6
@ -0,0 +1,43 @@
|
||||
using NLog;
|
||||
using NzbDrone.Common.Cloud;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.MetadataSource;
|
||||
using NzbDrone.Core.Parser;
|
||||
|
||||
namespace NzbDrone.Core.ImportLists.TMDb.Keyword
|
||||
{
|
||||
public class TMDbKeywordImport : TMDbImportListBase<TMDbKeywordSettings>
|
||||
{
|
||||
public TMDbKeywordImport(IRadarrCloudRequestBuilder requestBuilder,
|
||||
IHttpClient httpClient,
|
||||
IImportListStatusService importListStatusService,
|
||||
IConfigService configService,
|
||||
IParsingService parsingService,
|
||||
ISearchForNewMovie searchForNewMovie,
|
||||
Logger logger)
|
||||
: base(requestBuilder, httpClient, importListStatusService, configService, parsingService, searchForNewMovie, logger)
|
||||
{
|
||||
}
|
||||
|
||||
public override string Name => "TMDb Keyword";
|
||||
public override bool Enabled => true;
|
||||
public override bool EnableAuto => false;
|
||||
|
||||
public override IParseImportListResponse GetParser()
|
||||
{
|
||||
return new TMDbKeywordParser();
|
||||
}
|
||||
|
||||
public override IImportListRequestGenerator GetRequestGenerator()
|
||||
{
|
||||
return new TMDbKeywordRequestGenerator()
|
||||
{
|
||||
RequestBuilder = _requestBuilder,
|
||||
Settings = Settings,
|
||||
Logger = _logger,
|
||||
HttpClient = _httpClient
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.ImportLists.ImportListMovies;
|
||||
|
||||
namespace NzbDrone.Core.ImportLists.TMDb.Keyword
|
||||
{
|
||||
public class TMDbKeywordParser : TMDbParser
|
||||
{
|
||||
public override IList<ImportListMovie> ParseResponse(ImportListResponse importResponse)
|
||||
{
|
||||
var movies = new List<ImportListMovie>();
|
||||
|
||||
if (!PreProcess(importResponse))
|
||||
{
|
||||
return movies;
|
||||
}
|
||||
|
||||
var jsonResponse = JsonConvert.DeserializeObject<MovieSearchResource>(importResponse.Content);
|
||||
|
||||
// no movies were return
|
||||
if (jsonResponse == null)
|
||||
{
|
||||
return movies;
|
||||
}
|
||||
|
||||
foreach (var movie in jsonResponse.Results)
|
||||
{
|
||||
// Movies with no Year Fix
|
||||
if (string.IsNullOrWhiteSpace(movie.ReleaseDate))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
movies.AddIfNotNull(MapListMovie(movie));
|
||||
}
|
||||
|
||||
return movies;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Http;
|
||||
|
||||
namespace NzbDrone.Core.ImportLists.TMDb.Keyword
|
||||
{
|
||||
public class TMDbKeywordRequestGenerator : IImportListRequestGenerator
|
||||
{
|
||||
public TMDbKeywordSettings Settings { get; set; }
|
||||
public IHttpClient HttpClient { get; set; }
|
||||
public IHttpRequestBuilderFactory RequestBuilder { get; set; }
|
||||
public Logger Logger { get; set; }
|
||||
public int MaxPages { get; set; }
|
||||
|
||||
public TMDbKeywordRequestGenerator()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual ImportListPageableRequestChain GetMovies()
|
||||
{
|
||||
var pageableRequests = new ImportListPageableRequestChain();
|
||||
|
||||
pageableRequests.Add(GetMoviesRequest());
|
||||
|
||||
return pageableRequests;
|
||||
}
|
||||
|
||||
private IEnumerable<ImportListRequest> GetMoviesRequest()
|
||||
{
|
||||
Logger.Info($"Importing TMDb movies from keyword Id: {Settings.KeywordId}");
|
||||
|
||||
var requestBuilder = RequestBuilder.Create()
|
||||
.SetSegment("api", "3")
|
||||
.SetSegment("route", "keyword")
|
||||
.SetSegment("id", $"{Settings.KeywordId}")
|
||||
.SetSegment("secondaryRoute", "/movies");
|
||||
|
||||
var jsonResponse = JsonConvert.DeserializeObject<MovieSearchResource>(HttpClient.Execute(requestBuilder.Build()).Content);
|
||||
|
||||
MaxPages = jsonResponse.TotalPages;
|
||||
|
||||
for (var pageNumber = 1; pageNumber <= MaxPages; pageNumber++)
|
||||
{
|
||||
requestBuilder.AddQueryParam("page", pageNumber, true);
|
||||
|
||||
var request = requestBuilder.Build();
|
||||
|
||||
Logger.Debug($"Importing TMDb movies from: {request.Url}");
|
||||
|
||||
yield return new ImportListRequest(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using FluentValidation;
|
||||
using NzbDrone.Core.Annotations;
|
||||
|
||||
namespace NzbDrone.Core.ImportLists.TMDb.Keyword
|
||||
{
|
||||
public class TMDbKeywordSettingsValidator : TMDbSettingsBaseValidator<TMDbKeywordSettings>
|
||||
{
|
||||
public TMDbKeywordSettingsValidator()
|
||||
: base()
|
||||
{
|
||||
RuleFor(c => c.KeywordId).Matches(@"^[1-9][0-9]*$", RegexOptions.IgnoreCase);
|
||||
}
|
||||
}
|
||||
|
||||
public class TMDbKeywordSettings : TMDbSettingsBase<TMDbKeywordSettings>
|
||||
{
|
||||
protected override AbstractValidator<TMDbKeywordSettings> Validator => new TMDbKeywordSettingsValidator();
|
||||
|
||||
public TMDbKeywordSettings()
|
||||
{
|
||||
KeywordId = "";
|
||||
}
|
||||
|
||||
[FieldDefinition(1, Label = "Keyword Id", Type = FieldType.Textbox, HelpText = "TMDb Id of keyword to Follow")]
|
||||
public string KeywordId { get; set; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user