1
0
mirror of https://github.com/Radarr/Radarr.git synced 2026-04-23 22:25:14 -04:00

Added: A Huge Cleanup of old Series Code. (Let's pray nothing breaks :P) (#2589)

This commit is contained in:
Qstick
2018-03-14 16:41:36 -04:00
committed by Leonardo Galli
parent 8a6d67a6d7
commit 25e10e26e3
551 changed files with 2835 additions and 18867 deletions
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Movies;
namespace NzbDrone.Core.MetadataSource
{
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using NzbDrone.Core.Profiles;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Movies;
namespace NzbDrone.Core.MetadataSource
{
@@ -1,11 +0,0 @@
using System;
using System.Collections.Generic;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.MetadataSource
{
public interface IProvideSeriesInfo
{
Tuple<Series, List<Episode>> GetSeriesInfo(int tvdbSeriesId);
}
}
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Movies;
namespace NzbDrone.Core.MetadataSource
{
@@ -1,10 +0,0 @@
using System.Collections.Generic;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.MetadataSource
{
public interface ISearchForNewSeries
{
List<Series> SearchForNewSeries(string title);
}
}
@@ -12,7 +12,7 @@ using NzbDrone.Core.Indexers;
using System.ServiceModel.Syndication;
using System.Xml;
using NzbDrone.Common.Http;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Movies;
using System;
using System.IO;
using NzbDrone.Core.Parser;
@@ -3,7 +3,7 @@ using NzbDrone.Core.Download;
using System;
using System.Linq;
using System.Collections.Generic;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Movies;
namespace NzbDrone.Core.MetadataSource.PreDB
{
@@ -1,12 +1,12 @@
using System;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Movies;
namespace NzbDrone.Core.MetadataSource
{
public class SearchSeriesComparer : IComparer<Series>
public class SearchMovieComparer : IComparer<Movie>
{
private static readonly Regex RegexCleanPunctuation = new Regex("[-._:]", RegexOptions.Compiled);
private static readonly Regex RegexCleanCountryYearPostfix = new Regex(@"(?<=.+)( \([A-Z]{2}\)| \(\d{4}\)| \([A-Z]{2}\) \(\d{4}\))$", RegexOptions.Compiled);
@@ -17,7 +17,7 @@ namespace NzbDrone.Core.MetadataSource
private readonly string _searchQueryWithoutYear;
private int? _year;
public SearchSeriesComparer(string searchQuery)
public SearchMovieComparer(string searchQuery)
{
SearchQuery = searchQuery;
@@ -33,7 +33,7 @@ namespace NzbDrone.Core.MetadataSource
}
}
public int Compare(Series x, Series y)
public int Compare(Movie x, Movie y)
{
int result = 0;
@@ -60,7 +60,7 @@ namespace NzbDrone.Core.MetadataSource
return Compare(x, y, s => SearchQuery.LevenshteinDistanceClean(s.Title) - GetYearFactor(s));
}
public int Compare<T>(Series x, Series y, Func<Series,T> keySelector)
public int Compare<T>(Movie x, Movie y, Func<Movie, T> keySelector)
where T : IComparable<T>
{
var keyX = keySelector(x);
@@ -69,7 +69,7 @@ namespace NzbDrone.Core.MetadataSource
return keyX.CompareTo(keyY);
}
public int CompareWithYear(Series x, Series y, Predicate<Series> canMatch)
public int CompareWithYear(Movie x, Movie y, Predicate<Movie> canMatch)
{
var matchX = canMatch(x);
var matchY = canMatch(y);
@@ -110,11 +110,11 @@ namespace NzbDrone.Core.MetadataSource
return title.Trim().ToLowerInvariant();
}
private int GetYearFactor(Series series)
private int GetYearFactor(Movie movie)
{
if (_year.HasValue)
{
var offset = Math.Abs(series.Year - _year.Value);
var offset = Math.Abs(movie.Year - _year.Value);
if (offset <= 1)
{
return 20 - 10 * offset;
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
@@ -12,7 +12,7 @@ using NzbDrone.Core.MediaCover;
using NzbDrone.Core.MetadataSource.SkyHook.Resource;
using NzbDrone.Core.MetadataSource;
using NzbDrone.Core.MetadataSource.PreDB;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Movies;
using System.Threading;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Profiles;
@@ -24,7 +24,7 @@ using NzbDrone.Core.MetadataSource.RadarrAPI;
namespace NzbDrone.Core.MetadataSource.SkyHook
{
public class SkyHookProxy : IProvideSeriesInfo, ISearchForNewSeries, IProvideMovieInfo, ISearchForNewMovie, IDiscoverNewMovies
public class SkyHookProxy : IProvideMovieInfo, ISearchForNewMovie, IDiscoverNewMovies
{
private readonly IHttpClient _httpClient;
private readonly Logger _logger;
@@ -56,36 +56,6 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
_logger = logger;
}
public Tuple<Series, List<Episode>> GetSeriesInfo(int tvdbSeriesId)
{
var httpRequest = _requestBuilder.Create()
.SetSegment("route", "shows")
.Resource(tvdbSeriesId.ToString())
.Build();
httpRequest.AllowAutoRedirect = true;
httpRequest.SuppressHttpError = true;
var httpResponse = _httpClient.Get<ShowResource>(httpRequest);
if (httpResponse.HasHttpError)
{
if (httpResponse.StatusCode == HttpStatusCode.NotFound)
{
throw new SeriesNotFoundException(tvdbSeriesId);
}
else
{
throw new HttpException(httpRequest, httpResponse);
}
}
var episodes = httpResponse.Resource.Episodes.Select(MapEpisode);
var series = MapSeries(httpResponse.Resource);
return new Tuple<Series, List<Episode>>(series, episodes.ToList());
}
public Movie GetMovieInfo(int TmdbId, Profile profile = null, bool hasPreDBEntry = false)
{
var langCode = profile != null ? IsoLanguages.Get(profile.Language).TwoLetterCode : "en";
@@ -463,7 +433,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
{
return new List<Movie> { GetMovieInfo(imdbid) };
}
catch (SeriesNotFoundException)
catch (MovieNotFoundException)
{
return new List<Movie>();
}
@@ -508,57 +478,6 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
return movieResults.SelectList(MapMovie);
}
public List<Series> SearchForNewSeries(string title)
{
try
{
var lowerTitle = title.ToLowerInvariant();
if (lowerTitle.StartsWith("tvdb:") || lowerTitle.StartsWith("tvdbid:"))
{
var slug = lowerTitle.Split(':')[1].Trim();
int tvdbId;
if (slug.IsNullOrWhiteSpace() || slug.Any(char.IsWhiteSpace) || !int.TryParse(slug, out tvdbId) || tvdbId <= 0)
{
return new List<Series>();
}
try
{
return new List<Series> { GetSeriesInfo(tvdbId).Item1 };
}
catch (SeriesNotFoundException)
{
return new List<Series>();
}
}
var httpRequest = _requestBuilder.Create()
.SetSegment("route", "search")
.AddQueryParam("term", title.ToLower().Trim())
.Build();
var httpResponse = _httpClient.Get<List<ShowResource>>(httpRequest);
return httpResponse.Resource.SelectList(MapSeries);
}
catch (HttpException)
{
throw new SkyHookException("Search for '{0}' failed. Unable to communicate with SkyHook.", title);
}
catch (Exception ex)
{
_logger.Warn(ex, ex.Message);
throw new SkyHookException("Search for '{0}' failed. Invalid response received from SkyHook.", title);
}
}
public Movie MapMovie(MovieResult result)
{
var imdbMovie = new Movie();
@@ -661,63 +580,6 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
return null;
}
private static Series MapSeries(ShowResource show)
{
var series = new Series();
series.TvdbId = show.TvdbId;
if (show.TvRageId.HasValue)
{
series.TvRageId = show.TvRageId.Value;
}
if (show.TvMazeId.HasValue)
{
series.TvMazeId = show.TvMazeId.Value;
}
series.ImdbId = show.ImdbId;
series.Title = show.Title;
series.CleanTitle = Parser.Parser.CleanSeriesTitle(show.Title);
series.SortTitle = SeriesTitleNormalizer.Normalize(show.Title, show.TvdbId);
if (show.FirstAired != null)
{
series.FirstAired = DateTime.Parse(show.FirstAired).ToUniversalTime();
series.Year = series.FirstAired.Value.Year;
}
series.Overview = show.Overview;
if (show.Runtime != null)
{
series.Runtime = show.Runtime.Value;
}
series.Network = show.Network;
if (show.TimeOfDay != null)
{
series.AirTime = string.Format("{0:00}:{1:00}", show.TimeOfDay.Hours, show.TimeOfDay.Minutes);
}
series.TitleSlug = show.Slug;
series.Status = MapSeriesStatus(show.Status);
series.Ratings = MapRatings(show.Rating);
series.Genres = show.Genres;
if (show.ContentRating.IsNotNullOrWhiteSpace())
{
series.Certification = show.ContentRating.ToUpper();
}
series.Actors = show.Actors.Select(MapActors).ToList();
series.Seasons = show.Seasons.Select(MapSeason).ToList();
series.Images = show.Images.Select(MapImage).ToList();
return series;
}
private static Actor MapActors(ActorResource arg)
{
var newActor = new Actor
@@ -737,48 +599,6 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
return newActor;
}
private static Episode MapEpisode(EpisodeResource oracleEpisode)
{
var episode = new Episode();
episode.Overview = oracleEpisode.Overview;
episode.SeasonNumber = oracleEpisode.SeasonNumber;
episode.EpisodeNumber = oracleEpisode.EpisodeNumber;
episode.AbsoluteEpisodeNumber = oracleEpisode.AbsoluteEpisodeNumber;
episode.Title = oracleEpisode.Title;
episode.AirDate = oracleEpisode.AirDate;
episode.AirDateUtc = oracleEpisode.AirDateUtc;
episode.Ratings = MapRatings(oracleEpisode.Rating);
//Don't include series fanart images as episode screenshot
if (oracleEpisode.Image != null)
{
episode.Images.Add(new MediaCover.MediaCover(MediaCoverTypes.Screenshot, oracleEpisode.Image));
}
return episode;
}
private static Season MapSeason(SeasonResource seasonResource)
{
return new Season
{
SeasonNumber = seasonResource.SeasonNumber,
Images = seasonResource.Images.Select(MapImage).ToList()
};
}
private static SeriesStatusType MapSeriesStatus(string status)
{
if (status.Equals("ended", StringComparison.InvariantCultureIgnoreCase))
{
return SeriesStatusType.Ended;
}
return SeriesStatusType.Continuing;
}
private static Ratings MapRatings(RatingResource rating)
{
if (rating == null)