mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-10 13:02:47 +01:00
New: Import List by TMDb Company ID
This commit is contained in:
parent
8eb0f33718
commit
efeb216383
@ -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.Company
|
||||||
|
{
|
||||||
|
public class TMDbCompanyImport : TMDbImportListBase<TMDbCompanySettings>
|
||||||
|
{
|
||||||
|
public TMDbCompanyImport(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 Company";
|
||||||
|
public override bool Enabled => true;
|
||||||
|
public override bool EnableAuto => false;
|
||||||
|
|
||||||
|
public override IParseImportListResponse GetParser()
|
||||||
|
{
|
||||||
|
return new TMDbCompanyParser();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IImportListRequestGenerator GetRequestGenerator()
|
||||||
|
{
|
||||||
|
return new TMDbCompanyRequestGenerator()
|
||||||
|
{
|
||||||
|
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.Company
|
||||||
|
{
|
||||||
|
public class TMDbCompanyParser : 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,57 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using NLog;
|
||||||
|
using NzbDrone.Common.Http;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.ImportLists.TMDb.Company
|
||||||
|
{
|
||||||
|
public class TMDbCompanyRequestGenerator : IImportListRequestGenerator
|
||||||
|
{
|
||||||
|
public TMDbCompanySettings Settings { get; set; }
|
||||||
|
public IHttpClient HttpClient { get; set; }
|
||||||
|
public IHttpRequestBuilderFactory RequestBuilder { get; set; }
|
||||||
|
public Logger Logger { get; set; }
|
||||||
|
public int MaxPages { get; set; }
|
||||||
|
|
||||||
|
public TMDbCompanyRequestGenerator()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual ImportListPageableRequestChain GetMovies()
|
||||||
|
{
|
||||||
|
var pageableRequests = new ImportListPageableRequestChain();
|
||||||
|
|
||||||
|
pageableRequests.Add(GetMoviesRequest());
|
||||||
|
|
||||||
|
return pageableRequests;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<ImportListRequest> GetMoviesRequest()
|
||||||
|
{
|
||||||
|
Logger.Info($"Importing TMDb movies from company: {Settings.CompanyId}");
|
||||||
|
|
||||||
|
var requestBuilder = RequestBuilder.Create()
|
||||||
|
.SetSegment("api", "3")
|
||||||
|
.SetSegment("route", "discover")
|
||||||
|
.SetSegment("id", $"movie")
|
||||||
|
.SetSegment("secondaryRoute", "");
|
||||||
|
|
||||||
|
requestBuilder.AddQueryParam("with_companies", Settings.CompanyId);
|
||||||
|
|
||||||
|
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.Company
|
||||||
|
{
|
||||||
|
public class TMDbCompanySettingsValidator : TMDbSettingsBaseValidator<TMDbCompanySettings>
|
||||||
|
{
|
||||||
|
public TMDbCompanySettingsValidator()
|
||||||
|
: base()
|
||||||
|
{
|
||||||
|
RuleFor(c => c.CompanyId).Matches(@"^[1-9][0-9]*$", RegexOptions.IgnoreCase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TMDbCompanySettings : TMDbSettingsBase<TMDbCompanySettings>
|
||||||
|
{
|
||||||
|
protected override AbstractValidator<TMDbCompanySettings> Validator => new TMDbCompanySettingsValidator();
|
||||||
|
|
||||||
|
public TMDbCompanySettings()
|
||||||
|
{
|
||||||
|
CompanyId = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
[FieldDefinition(1, Label = "Company Id", Type = FieldType.Textbox, HelpText = "TMDb Id of Company to Follow")]
|
||||||
|
public string CompanyId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user