mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-25 22:37:27 -04:00
Reformat and apply Stylecop rules
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.Profiles;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.Profiles;
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource
|
||||
{
|
||||
public interface IProvideMovieInfo
|
||||
{
|
||||
Movie GetMovieInfo(string ImdbId);
|
||||
Movie GetMovieInfo(int TmdbId, Profile profile, bool hasPreDBEntry);
|
||||
Movie GetMovieInfo(string imdbId);
|
||||
Movie GetMovieInfo(int tmdbId, Profile profile, bool hasPreDBEntry);
|
||||
HashSet<int> GetChangedMovies(DateTime startTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
namespace NzbDrone.Core.MetadataSource.PreDB
|
||||
{
|
||||
class PreDBResult
|
||||
internal class PreDBResult
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public string Link { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Common.Instrumentation.Extensions;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Download.Pending;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Movies;
|
||||
using System;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource.PreDB
|
||||
{
|
||||
@@ -131,9 +131,6 @@ namespace NzbDrone.Core.MetadataSource.PreDB
|
||||
return matches;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private List<Movie> Sync()
|
||||
{
|
||||
_logger.ProgressInfo("Starting PreDB Sync");
|
||||
@@ -168,33 +165,33 @@ namespace NzbDrone.Core.MetadataSource.PreDB
|
||||
|
||||
public bool HasReleases(Movie movie)
|
||||
{
|
||||
try
|
||||
{
|
||||
var results = GetResults("movies", movie.Title);
|
||||
|
||||
foreach (PreDBResult result in results)
|
||||
try
|
||||
{
|
||||
var parsed = Parser.Parser.ParseMovieTitle(result.Title, true);
|
||||
if (parsed == null)
|
||||
{
|
||||
parsed = new Parser.Model.ParsedMovieInfo { MovieTitle = result.Title, Year = 0 };
|
||||
}
|
||||
var match = _parsingService.Map(parsed, "", new MovieSearchCriteria { Movie = movie });
|
||||
var results = GetResults("movies", movie.Title);
|
||||
|
||||
if (match != null && match.RemoteMovie.Movie != null && match.RemoteMovie.Movie.Id == movie.Id)
|
||||
foreach (PreDBResult result in results)
|
||||
{
|
||||
return true;
|
||||
var parsed = Parser.Parser.ParseMovieTitle(result.Title, true);
|
||||
if (parsed == null)
|
||||
{
|
||||
parsed = new Parser.Model.ParsedMovieInfo { MovieTitle = result.Title, Year = 0 };
|
||||
}
|
||||
|
||||
var match = _parsingService.Map(parsed, "", new MovieSearchCriteria { Movie = movie });
|
||||
|
||||
if (match != null && match.RemoteMovie.Movie != null && match.RemoteMovie.Movie.Id == movie.Id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Warn(ex, "Error while looking on predb.me.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Warn(ex, "Error while looking on predb.me.");
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace NzbDrone.Core.MetadataSource.PreDB
|
||||
{
|
||||
public class PreDBSyncCommand : Command
|
||||
{
|
||||
|
||||
public override bool SendUpdatesToClient => true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using NzbDrone.Common.Messaging;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.Movies;
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource.PreDB
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.MetadataSource.SkyHook.Resource;
|
||||
using NzbDrone.Core.Movies.AlternativeTitles;
|
||||
using NzbDrone.Core.Parser;
|
||||
@@ -14,9 +14,9 @@ namespace NzbDrone.Core.MetadataSource.RadarrAPI
|
||||
{
|
||||
IHttpRequestBuilderFactory RadarrAPI { get; }
|
||||
List<MovieResult> DiscoverMovies(string action, Func<HttpRequest, HttpRequest> enhanceRequest);
|
||||
List<AlternativeTitle> AlternativeTitlesForMovie(int TmdbId);
|
||||
List<AlternativeTitle> AlternativeTitlesForMovie(int tmdbId);
|
||||
Tuple<List<AlternativeTitle>, AlternativeYear> AlternativeTitlesAndYearForMovie(int tmdbId);
|
||||
AlternativeTitle AddNewAlternativeTitle(AlternativeTitle title, int TmdbId);
|
||||
AlternativeTitle AddNewAlternativeTitle(AlternativeTitle title, int tmdbId);
|
||||
AlternativeYear AddNewAlternativeYear(int year, int tmdbId);
|
||||
string APIURL { get; }
|
||||
}
|
||||
@@ -40,7 +40,7 @@ namespace NzbDrone.Core.MetadataSource.RadarrAPI
|
||||
APIURL = "https://api.radarr.video/v2";
|
||||
}
|
||||
|
||||
RadarrAPI = new HttpRequestBuilder(APIURL+"/{route}/{action}")
|
||||
RadarrAPI = new HttpRequestBuilder(APIURL + "/{route}/{action}")
|
||||
.CreateFactory();
|
||||
}
|
||||
|
||||
@@ -82,7 +82,6 @@ namespace NzbDrone.Core.MetadataSource.RadarrAPI
|
||||
//No error!
|
||||
}
|
||||
|
||||
|
||||
if (response.StatusCode != System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
throw new HttpException(request, response);
|
||||
@@ -91,7 +90,7 @@ namespace NzbDrone.Core.MetadataSource.RadarrAPI
|
||||
return JsonConvert.DeserializeObject<T>(response.Content);
|
||||
}
|
||||
|
||||
public List<MovieResult> DiscoverMovies(string action, Func<HttpRequest, HttpRequest> enhanceRequest = null )
|
||||
public List<MovieResult> DiscoverMovies(string action, Func<HttpRequest, HttpRequest> enhanceRequest = null)
|
||||
{
|
||||
var request = RadarrAPI.Create().SetSegment("route", "discovery").SetSegment("action", action).Build();
|
||||
|
||||
@@ -103,10 +102,9 @@ namespace NzbDrone.Core.MetadataSource.RadarrAPI
|
||||
return Execute<List<MovieResult>>(request);
|
||||
}
|
||||
|
||||
|
||||
public List<AlternativeTitle> AlternativeTitlesForMovie(int TmdbId)
|
||||
public List<AlternativeTitle> AlternativeTitlesForMovie(int tmdbId)
|
||||
{
|
||||
var request = RadarrAPI.Create().SetSegment("route", "mappings").SetSegment("action", "find").AddQueryParam("tmdbid", TmdbId).Build();
|
||||
var request = RadarrAPI.Create().SetSegment("route", "mappings").SetSegment("action", "find").AddQueryParam("tmdbid", tmdbId).Build();
|
||||
|
||||
var mappings = Execute<Mapping>(request);
|
||||
|
||||
@@ -149,10 +147,10 @@ namespace NzbDrone.Core.MetadataSource.RadarrAPI
|
||||
return new Tuple<List<AlternativeTitle>, AlternativeYear>(titles, newYear);
|
||||
}
|
||||
|
||||
public AlternativeTitle AddNewAlternativeTitle(AlternativeTitle title, int TmdbId)
|
||||
public AlternativeTitle AddNewAlternativeTitle(AlternativeTitle title, int tmdbId)
|
||||
{
|
||||
var request = RadarrAPI.Create().SetSegment("route", "mappings").SetSegment("action", "add")
|
||||
.AddQueryParam("tmdbid", TmdbId).AddQueryParam("type", "title")
|
||||
.AddQueryParam("tmdbid", tmdbId).AddQueryParam("type", "title")
|
||||
.AddQueryParam("language", IsoLanguages.Get(title.Language).TwoLetterCode)
|
||||
.AddQueryParam("aka_title", title.Title).Build();
|
||||
|
||||
|
||||
@@ -29,7 +29,8 @@ namespace NzbDrone.Core.MetadataSource.RadarrAPI
|
||||
{
|
||||
public RadarrError APIErrors;
|
||||
|
||||
public RadarrAPIException(RadarrError apiError) : base(HumanReadable(apiError))
|
||||
public RadarrAPIException(RadarrError apiError)
|
||||
: base(HumanReadable(apiError))
|
||||
{
|
||||
APIErrors = apiError;
|
||||
}
|
||||
@@ -41,13 +42,12 @@ namespace NzbDrone.Core.MetadataSource.RadarrAPI
|
||||
{
|
||||
return $"{error.Title} ({error.Status}, RayId: {error.RayId}), Details: {error.Detail}";
|
||||
}));
|
||||
return $"Error while calling api: {firstError.Title}\nFull error(s): {details}";
|
||||
return $"Error while calling api: {firstError.Title}\nFull error(s): {details}";
|
||||
}
|
||||
}
|
||||
|
||||
public class TitleInfo
|
||||
{
|
||||
|
||||
[JsonProperty("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
@@ -60,7 +60,6 @@ namespace NzbDrone.Core.MetadataSource.RadarrAPI
|
||||
|
||||
public class YearInfo
|
||||
{
|
||||
|
||||
[JsonProperty("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
@@ -70,7 +69,6 @@ namespace NzbDrone.Core.MetadataSource.RadarrAPI
|
||||
|
||||
public class Title
|
||||
{
|
||||
|
||||
[JsonProperty("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
@@ -98,7 +96,6 @@ namespace NzbDrone.Core.MetadataSource.RadarrAPI
|
||||
|
||||
public class Year
|
||||
{
|
||||
|
||||
[JsonProperty("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
@@ -126,7 +123,6 @@ namespace NzbDrone.Core.MetadataSource.RadarrAPI
|
||||
|
||||
public class Mappings
|
||||
{
|
||||
|
||||
[JsonProperty("titles")]
|
||||
public IList<Title> Titles { get; set; }
|
||||
|
||||
@@ -136,7 +132,6 @@ namespace NzbDrone.Core.MetadataSource.RadarrAPI
|
||||
|
||||
public class Mapping
|
||||
{
|
||||
|
||||
[JsonProperty("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
@@ -152,7 +147,6 @@ namespace NzbDrone.Core.MetadataSource.RadarrAPI
|
||||
|
||||
public class AddTitleMapping
|
||||
{
|
||||
|
||||
[JsonProperty("tmdbid")]
|
||||
public string Tmdbid { get; set; }
|
||||
|
||||
@@ -180,7 +174,6 @@ namespace NzbDrone.Core.MetadataSource.RadarrAPI
|
||||
|
||||
public class AddYearMapping
|
||||
{
|
||||
|
||||
[JsonProperty("tmdbid")]
|
||||
public string Tmdbid { get; set; }
|
||||
|
||||
@@ -205,5 +198,4 @@ namespace NzbDrone.Core.MetadataSource.RadarrAPI
|
||||
[JsonProperty("locked")]
|
||||
public bool Locked { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,23 +39,38 @@ namespace NzbDrone.Core.MetadataSource
|
||||
|
||||
// Prefer exact matches
|
||||
result = Compare(x, y, s => CleanPunctuation(s.Title).Equals(CleanPunctuation(SearchQuery)));
|
||||
if (result != 0) return -result;
|
||||
if (result != 0)
|
||||
{
|
||||
return -result;
|
||||
}
|
||||
|
||||
// Remove Articles (a/an/the)
|
||||
result = Compare(x, y, s => CleanArticles(s.Title).Equals(CleanArticles(SearchQuery)));
|
||||
if (result != 0) return -result;
|
||||
if (result != 0)
|
||||
{
|
||||
return -result;
|
||||
}
|
||||
|
||||
// Prefer close matches
|
||||
result = Compare(x, y, s => CleanPunctuation(s.Title).LevenshteinDistance(CleanPunctuation(SearchQuery)) <= 1);
|
||||
if (result != 0) return -result;
|
||||
if (result != 0)
|
||||
{
|
||||
return -result;
|
||||
}
|
||||
|
||||
// Compare clean matches by year "Battlestar Galactica 1978"
|
||||
result = CompareWithYear(x, y, s => CleanTitle(s.Title).LevenshteinDistance(_searchQueryWithoutYear) <= 1);
|
||||
if (result != 0) return -result;
|
||||
if (result != 0)
|
||||
{
|
||||
return -result;
|
||||
}
|
||||
|
||||
// Compare prefix matches by year "(CSI: ..."
|
||||
result = CompareWithYear(x, y, s => s.Title.ToLowerInvariant().StartsWith(_searchQueryWithoutYear + ":"));
|
||||
if (result != 0) return -result;
|
||||
if (result != 0)
|
||||
{
|
||||
return -result;
|
||||
}
|
||||
|
||||
return Compare(x, y, s => SearchQuery.LevenshteinDistanceClean(s.Title) - GetYearFactor(s));
|
||||
}
|
||||
@@ -79,7 +94,10 @@ namespace NzbDrone.Core.MetadataSource
|
||||
if (_year.HasValue)
|
||||
{
|
||||
var result = Compare(x, y, s => s.Year == _year.Value);
|
||||
if (result != 0) return result;
|
||||
if (result != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return Compare(x, y, s => s.Year);
|
||||
@@ -117,7 +135,7 @@ namespace NzbDrone.Core.MetadataSource
|
||||
var offset = Math.Abs(movie.Year - _year.Value);
|
||||
if (offset <= 1)
|
||||
{
|
||||
return 20 - 10 * offset;
|
||||
return 20 - (10 * offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||
{
|
||||
|
||||
public class ConfigResource
|
||||
{
|
||||
public Images images { get; set; }
|
||||
@@ -17,5 +16,4 @@
|
||||
public string[] profile_sizes { get; set; }
|
||||
public string[] still_sizes { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||
{
|
||||
public class ImdbResource
|
||||
{
|
||||
public int v { get; set; }
|
||||
public string q { get; set; }
|
||||
public MovieResource[] d { get; set; }
|
||||
}
|
||||
{
|
||||
public int v { get; set; }
|
||||
public string q { get; set; }
|
||||
public MovieResource[] d { get; set; }
|
||||
}
|
||||
|
||||
public class MovieResource
|
||||
{
|
||||
public string l { get; set; }
|
||||
public string id { get; set; }
|
||||
public string s { get; set; }
|
||||
public int y { get; set; }
|
||||
public string q { get; set; }
|
||||
public object[] i { get; set; }
|
||||
}
|
||||
public class MovieResource
|
||||
{
|
||||
public string l { get; set; }
|
||||
public string id { get; set; }
|
||||
public string s { get; set; }
|
||||
public int y { get; set; }
|
||||
public string q { get; set; }
|
||||
public object[] i { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||
{
|
||||
|
||||
public class FindRoot
|
||||
{
|
||||
public MovieResult[] movie_results { get; set; }
|
||||
}
|
||||
|
||||
public class MovieSearchRoot
|
||||
{
|
||||
public int page { get; set; }
|
||||
@@ -37,7 +37,6 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||
public string physical_release_note { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class MovieResourceRoot
|
||||
{
|
||||
public bool adult { get; set; }
|
||||
@@ -173,5 +172,4 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||
public string name { get; set; }
|
||||
public string original_name { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
{
|
||||
public class SkyHookException : NzbDroneClientException
|
||||
{
|
||||
public SkyHookException(string message) : base(HttpStatusCode.ServiceUnavailable, message)
|
||||
public SkyHookException(string message)
|
||||
: base(HttpStatusCode.ServiceUnavailable, message)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Cloud;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Exceptions;
|
||||
using NzbDrone.Core.MediaCover;
|
||||
using NzbDrone.Core.MetadataSource.SkyHook.Resource;
|
||||
using NzbDrone.Core.MetadataSource.PreDB;
|
||||
using NzbDrone.Core.Movies;
|
||||
using System.Threading;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Languages;
|
||||
using NzbDrone.Core.Profiles;
|
||||
using NzbDrone.Core.NetImport.ImportExclusions;
|
||||
using NzbDrone.Core.MediaCover;
|
||||
using NzbDrone.Core.MetadataSource.PreDB;
|
||||
using NzbDrone.Core.MetadataSource.RadarrAPI;
|
||||
using NzbDrone.Core.MetadataSource.SkyHook.Resource;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.Movies.AlternativeTitles;
|
||||
using System.Globalization;
|
||||
using NzbDrone.Core.NetImport.ImportExclusions;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Profiles;
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
{
|
||||
@@ -35,8 +35,15 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
private readonly IAlternativeTitleService _altTitleService;
|
||||
private readonly IRadarrAPIClient _radarrAPI;
|
||||
|
||||
public SkyHookProxy(IHttpClient httpClient, IRadarrCloudRequestBuilder requestBuilder, ITmdbConfigService configService, IMovieService movieService,
|
||||
IPreDBService predbService, IImportExclusionsService exclusionService, IAlternativeTitleService altTitleService, IRadarrAPIClient radarrAPI, Logger logger)
|
||||
public SkyHookProxy(IHttpClient httpClient,
|
||||
IRadarrCloudRequestBuilder requestBuilder,
|
||||
ITmdbConfigService configService,
|
||||
IMovieService movieService,
|
||||
IPreDBService predbService,
|
||||
IImportExclusionsService exclusionService,
|
||||
IAlternativeTitleService altTitleService,
|
||||
IRadarrAPIClient radarrAPI,
|
||||
Logger logger)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_movieBuilder = requestBuilder.TMDB;
|
||||
@@ -50,7 +57,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public HashSet<int> GetChangedMovies (DateTime startTime)
|
||||
public HashSet<int> GetChangedMovies(DateTime startTime)
|
||||
{
|
||||
var startDate = startTime.ToString("o");
|
||||
|
||||
@@ -69,16 +76,17 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
return new HashSet<int>(response.Resource.results.Select(c => c.id));
|
||||
}
|
||||
|
||||
public Movie GetMovieInfo(int TmdbId, Profile profile = null, bool hasPreDBEntry = false)
|
||||
public Movie GetMovieInfo(int tmdbId, Profile profile = null, bool hasPreDBEntry = false)
|
||||
{
|
||||
var langCode = profile != null ? IsoLanguages.Get(profile.Language)?.TwoLetterCode ?? "en" : "en";
|
||||
|
||||
var request = _movieBuilder.Create()
|
||||
.SetSegment("route", "movie")
|
||||
.SetSegment("id", TmdbId.ToString())
|
||||
.SetSegment("id", tmdbId.ToString())
|
||||
.SetSegment("secondaryRoute", "")
|
||||
.AddQueryParam("append_to_response", "alternative_titles,release_dates,videos")
|
||||
.AddQueryParam("language", langCode.ToUpper())
|
||||
|
||||
// .AddQueryParam("country", "US")
|
||||
.Build();
|
||||
|
||||
@@ -91,6 +99,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
{
|
||||
throw new MovieNotFoundException("Movie not found.");
|
||||
}
|
||||
|
||||
if (response.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
throw new HttpException(request, response);
|
||||
@@ -104,7 +113,6 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
// The dude abides, so should us, Lets be nice to TMDb
|
||||
// var allowed = int.Parse(response.Headers.GetValues("X-RateLimit-Limit").First()); // get allowed
|
||||
// var reset = long.Parse(response.Headers.GetValues("X-RateLimit-Reset").First()); // get time when it resets
|
||||
|
||||
if (response.Headers.ContainsKey("X-RateLimit-Remaining"))
|
||||
{
|
||||
var remaining = int.Parse(response.Headers.GetValues("X-RateLimit-Remaining").First());
|
||||
@@ -120,7 +128,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
{
|
||||
if (resource.status_code == 34)
|
||||
{
|
||||
_logger.Warn("Movie with TmdbId {0} could not be found. This is probably the case when the movie was deleted from TMDB.", TmdbId);
|
||||
_logger.Warn("Movie with TmdbId {0} could not be found. This is probably the case when the movie was deleted from TMDB.", tmdbId);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -136,7 +144,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
var iso = IsoLanguages.Find(resource.original_language);
|
||||
if (iso != null)
|
||||
{
|
||||
altTitles.Add(new AlternativeTitle(resource.original_title, SourceType.TMDB, TmdbId, iso.Language));
|
||||
altTitles.Add(new AlternativeTitle(resource.original_title, SourceType.TMDB, tmdbId, iso.Language));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,15 +152,15 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
{
|
||||
if (alternativeTitle.iso_3166_1.ToLower() == langCode)
|
||||
{
|
||||
altTitles.Add(new AlternativeTitle(alternativeTitle.title, SourceType.TMDB, TmdbId, IsoLanguages.Find(alternativeTitle.iso_3166_1.ToLower())?.Language ?? Language.English));
|
||||
altTitles.Add(new AlternativeTitle(alternativeTitle.title, SourceType.TMDB, tmdbId, IsoLanguages.Find(alternativeTitle.iso_3166_1.ToLower())?.Language ?? Language.English));
|
||||
}
|
||||
else if (alternativeTitle.iso_3166_1.ToLower() == "us")
|
||||
{
|
||||
altTitles.Add(new AlternativeTitle(alternativeTitle.title, SourceType.TMDB, TmdbId, Language.English));
|
||||
altTitles.Add(new AlternativeTitle(alternativeTitle.title, SourceType.TMDB, tmdbId, Language.English));
|
||||
}
|
||||
}
|
||||
|
||||
movie.TmdbId = TmdbId;
|
||||
movie.TmdbId = tmdbId;
|
||||
movie.ImdbId = resource.imdb_id;
|
||||
movie.Title = resource.title;
|
||||
movie.TitleSlug = Parser.Parser.ToUrlSlug(resource.title);
|
||||
@@ -174,12 +182,13 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
lowestYear.Add(DateTime.Parse(releaseDate.release_date).Year);
|
||||
}
|
||||
}
|
||||
|
||||
movie.Year = lowestYear.Min();
|
||||
}
|
||||
|
||||
movie.TitleSlug += "-" + movie.TmdbId.ToString();
|
||||
|
||||
movie.Images.Add(_configService.GetCoverForURL(resource.poster_path, MediaCoverTypes.Poster));//TODO: Update to load image specs from tmdb page!
|
||||
movie.Images.Add(_configService.GetCoverForURL(resource.poster_path, MediaCoverTypes.Poster)); //TODO: Update to load image specs from tmdb page!
|
||||
movie.Images.Add(_configService.GetCoverForURL(resource.backdrop_path, MediaCoverTypes.Fanart));
|
||||
movie.Runtime = resource.runtime;
|
||||
|
||||
@@ -187,10 +196,9 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
//{
|
||||
// movie.AlternativeTitles.Add(title.title);
|
||||
//}
|
||||
|
||||
foreach(ReleaseDates releaseDates in resource.release_dates.results)
|
||||
foreach (ReleaseDates releaseDates in resource.release_dates.results)
|
||||
{
|
||||
foreach(ReleaseDate releaseDate in releaseDates.release_dates)
|
||||
foreach (ReleaseDate releaseDate in releaseDates.release_dates)
|
||||
{
|
||||
if (releaseDate.type == 5 || releaseDate.type == 4)
|
||||
{
|
||||
@@ -215,32 +223,43 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
movie.Ratings.Votes = resource.vote_count;
|
||||
movie.Ratings.Value = (decimal)resource.vote_average;
|
||||
|
||||
foreach(Genre genre in resource.genres)
|
||||
foreach (Genre genre in resource.genres)
|
||||
{
|
||||
movie.Genres.Add(genre.name);
|
||||
}
|
||||
|
||||
var now = DateTime.Now;
|
||||
|
||||
//handle the case when we have both theatrical and physical release dates
|
||||
if (movie.InCinemas.HasValue && movie.PhysicalRelease.HasValue)
|
||||
{
|
||||
if (now < movie.InCinemas)
|
||||
{
|
||||
movie.Status = MovieStatusType.Announced;
|
||||
}
|
||||
else if (now >= movie.InCinemas)
|
||||
{
|
||||
movie.Status = MovieStatusType.InCinemas;
|
||||
}
|
||||
|
||||
if (now >= movie.PhysicalRelease)
|
||||
{
|
||||
movie.Status = MovieStatusType.Released;
|
||||
}
|
||||
}
|
||||
|
||||
//handle the case when we have theatrical release dates but we dont know the physical release date
|
||||
else if (movie.InCinemas.HasValue && (now >= movie.InCinemas))
|
||||
{
|
||||
movie.Status = MovieStatusType.InCinemas;
|
||||
}
|
||||
|
||||
//handle the case where we only have a physical release date
|
||||
else if (movie.PhysicalRelease.HasValue && (now >= movie.PhysicalRelease))
|
||||
{
|
||||
movie.Status = MovieStatusType.Released;
|
||||
}
|
||||
|
||||
//otherwise the title has only been announced
|
||||
else
|
||||
{
|
||||
@@ -248,7 +267,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
}
|
||||
|
||||
//since TMDB lacks alot of information lets assume that stuff is released if its been in cinemas for longer than 3 months.
|
||||
if (!movie.PhysicalRelease.HasValue && (movie.Status == MovieStatusType.InCinemas) && (((DateTime.Now).Subtract(movie.InCinemas.Value)).TotalSeconds > 60*60*24*30*3))
|
||||
if (!movie.PhysicalRelease.HasValue && (movie.Status == MovieStatusType.InCinemas) && (DateTime.Now.Subtract(movie.InCinemas.Value).TotalSeconds > 60 * 60 * 24 * 30 * 3))
|
||||
{
|
||||
movie.Status = MovieStatusType.Released;
|
||||
}
|
||||
@@ -303,8 +322,8 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
.Build();
|
||||
|
||||
request.AllowAutoRedirect = true;
|
||||
// request.SuppressHttpError = true;
|
||||
|
||||
// request.SuppressHttpError = true;
|
||||
var response = _httpClient.Get<FindRoot>(request);
|
||||
|
||||
if (response.HasHttpError)
|
||||
@@ -376,13 +395,15 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
|
||||
private string StripTrailingTheFromTitle(string title)
|
||||
{
|
||||
if(title.EndsWith(",the"))
|
||||
if (title.EndsWith(",the"))
|
||||
{
|
||||
title = title.Substring(0, title.Length - 4);
|
||||
} else if(title.EndsWith(", the"))
|
||||
}
|
||||
else if (title.EndsWith(", the"))
|
||||
{
|
||||
title = title.Substring(0, title.Length - 5);
|
||||
}
|
||||
|
||||
return title;
|
||||
}
|
||||
|
||||
@@ -417,7 +438,6 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
{
|
||||
return new List<Movie>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -450,7 +470,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
|
||||
int tmdbid = -1;
|
||||
|
||||
if (slug.IsNullOrWhiteSpace() || slug.Any(char.IsWhiteSpace) || !(int.TryParse(slug, out tmdbid)))
|
||||
if (slug.IsNullOrWhiteSpace() || slug.Any(char.IsWhiteSpace) || !int.TryParse(slug, out tmdbid))
|
||||
{
|
||||
return new List<Movie>();
|
||||
}
|
||||
@@ -530,29 +550,38 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
_logger.Debug("Not a valid date time.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
var now = DateTime.Now;
|
||||
|
||||
//handle the case when we have both theatrical and physical release dates
|
||||
if (imdbMovie.InCinemas.HasValue && imdbMovie.PhysicalRelease.HasValue)
|
||||
{
|
||||
if (now < imdbMovie.InCinemas)
|
||||
{
|
||||
imdbMovie.Status = MovieStatusType.Announced;
|
||||
}
|
||||
else if (now >= imdbMovie.InCinemas)
|
||||
{
|
||||
imdbMovie.Status = MovieStatusType.InCinemas;
|
||||
}
|
||||
|
||||
if (now >= imdbMovie.PhysicalRelease)
|
||||
{
|
||||
imdbMovie.Status = MovieStatusType.Released;
|
||||
}
|
||||
}
|
||||
|
||||
//handle the case when we have theatrical release dates but we dont know the physical release date
|
||||
else if (imdbMovie.InCinemas.HasValue && (now >= imdbMovie.InCinemas))
|
||||
{
|
||||
imdbMovie.Status = MovieStatusType.InCinemas;
|
||||
}
|
||||
|
||||
//handle the case where we only have a physical release date
|
||||
else if (imdbMovie.PhysicalRelease.HasValue && (now >= imdbMovie.PhysicalRelease))
|
||||
{
|
||||
imdbMovie.Status = MovieStatusType.Released;
|
||||
}
|
||||
|
||||
//otherwise the title has only been announced
|
||||
else
|
||||
{
|
||||
@@ -560,7 +589,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
}
|
||||
|
||||
//since TMDB lacks alot of information lets assume that stuff is released if its been in cinemas for longer than 3 months.
|
||||
if (!imdbMovie.PhysicalRelease.HasValue && (imdbMovie.Status == MovieStatusType.InCinemas) && (((DateTime.Now).Subtract(imdbMovie.InCinemas.Value)).TotalSeconds > 60 * 60 * 24 * 30 * 3))
|
||||
if (!imdbMovie.PhysicalRelease.HasValue && (imdbMovie.Status == MovieStatusType.InCinemas) && (DateTime.Now.Subtract(imdbMovie.InCinemas.Value).TotalSeconds > 60 * 60 * 24 * 30 * 3))
|
||||
{
|
||||
imdbMovie.Status = MovieStatusType.Released;
|
||||
}
|
||||
@@ -569,7 +598,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
|
||||
imdbMovie.Images = new List<MediaCover.MediaCover>();
|
||||
imdbMovie.Overview = result.overview;
|
||||
imdbMovie.Ratings = new Ratings { Value = (decimal)result.vote_average, Votes = result.vote_count};
|
||||
imdbMovie.Ratings = new Ratings { Value = (decimal)result.vote_average, Votes = result.vote_count };
|
||||
|
||||
try
|
||||
{
|
||||
@@ -587,7 +616,6 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
{
|
||||
imdbMovie.YouTubeTrailerId = result.trailer_key;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return imdbMovie;
|
||||
@@ -661,7 +689,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
{
|
||||
try
|
||||
{
|
||||
Movie newMovie = movie;
|
||||
Movie newMovie = movie;
|
||||
if (movie.TmdbId > 0)
|
||||
{
|
||||
newMovie = GetMovieInfo(movie.TmdbId);
|
||||
@@ -677,6 +705,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
{
|
||||
yearStr = $" {movie.Year}";
|
||||
}
|
||||
|
||||
newMovie = SearchForNewMovie(movie.Title + yearStr).FirstOrDefault();
|
||||
}
|
||||
|
||||
@@ -699,7 +728,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Warn(ex, "Couldn't map movie {0} to a movie on The Movie DB. It will not be added :(", movie.Title);
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.MediaCover;
|
||||
using NzbDrone.Common.Cache;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Common.Cloud;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.MediaCover;
|
||||
using NzbDrone.Core.MetadataSource.SkyHook.Resource;
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource
|
||||
@@ -12,7 +12,7 @@ namespace NzbDrone.Core.MetadataSource
|
||||
MediaCover.MediaCover GetCoverForURL(string url, MediaCover.MediaCoverTypes type);
|
||||
}
|
||||
|
||||
class TmdbConfigService : ITmdbConfigService
|
||||
internal class TmdbConfigService : ITmdbConfigService
|
||||
{
|
||||
private readonly ICached<ConfigResource> _configurationCache;
|
||||
private readonly IHttpClient _httpClient;
|
||||
|
||||
Reference in New Issue
Block a user