mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-24 22:35:39 -04:00
Merge branch 'develop'
Conflicts: NzbDrone.Core.Test/MetadataSourceTests/TraktProxyFixture.cs NzbDrone.Core/Jobs/TaskManager.cs NzbDrone.Core/MetadataSource/TraktProxy.cs NzbDrone.Core/Tv/SeasonService.cs NzbDrone.Integration.Test/SeasonIntegrationTests.cs
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.MediaCover;
|
||||
using NzbDrone.Core.MetadataSource.Trakt;
|
||||
@@ -15,26 +17,33 @@ namespace NzbDrone.Core.MetadataSource
|
||||
{
|
||||
public class TraktProxy : ISearchForNewSeries, IProvideSeriesInfo
|
||||
{
|
||||
public List<Series> SearchForNewSeries(string title)
|
||||
{
|
||||
var client = BuildClient("search", "shows");
|
||||
var restRequest = new RestRequest(GetSearchTerm(title));
|
||||
var response = client.ExecuteAndValidate<List<SearchShow>>(restRequest);
|
||||
|
||||
return response.Select(MapSearchSeries).ToList();
|
||||
}
|
||||
|
||||
|
||||
private readonly Logger _logger;
|
||||
private static readonly Regex InvalidSearchCharRegex = new Regex(@"[^a-zA-Z0-9\s-\.]", RegexOptions.Compiled);
|
||||
|
||||
private static string GetSearchTerm(string phrase)
|
||||
public TraktProxy(Logger logger)
|
||||
{
|
||||
phrase = phrase.RemoveAccent().ToLower();
|
||||
phrase = phrase.Replace("&", "and");
|
||||
phrase = InvalidSearchCharRegex.Replace(phrase, string.Empty);
|
||||
phrase = phrase.CleanSpaces().Replace(" ", "+");
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
return phrase;
|
||||
public List<Series> SearchForNewSeries(string title)
|
||||
{
|
||||
try
|
||||
{
|
||||
var client = BuildClient("search", "shows");
|
||||
var restRequest = new RestRequest(GetSearchTerm(title) +"/30/seasons");
|
||||
var response = client.ExecuteAndValidate<List<Show>>(restRequest);
|
||||
|
||||
return response.Select(MapSeries).ToList();
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
throw new TraktException("Search for '{0}' failed. Unable to communicate with Trakt.", title);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.WarnException(ex.Message, ex);
|
||||
throw new TraktException("Search for '{0}' failed. Invalid response received from Trakt.", title);
|
||||
}
|
||||
}
|
||||
|
||||
public Tuple<Series, List<Episode>> GetSeriesInfo(int tvDbSeriesId)
|
||||
@@ -43,7 +52,6 @@ namespace NzbDrone.Core.MetadataSource
|
||||
var restRequest = new RestRequest(tvDbSeriesId.ToString() + "/extended");
|
||||
var response = client.ExecuteAndValidate<Show>(restRequest);
|
||||
|
||||
|
||||
var episodes = response.seasons.SelectMany(c => c.episodes).Select(MapEpisode).ToList();
|
||||
var series = MapSeries(response);
|
||||
|
||||
@@ -63,6 +71,7 @@ namespace NzbDrone.Core.MetadataSource
|
||||
series.ImdbId = show.imdb_id;
|
||||
series.Title = show.title;
|
||||
series.CleanTitle = Parser.Parser.CleanSeriesTitle(show.title);
|
||||
series.Year = show.year;
|
||||
series.FirstAired = FromIso(show.first_aired_iso);
|
||||
series.Overview = show.overview;
|
||||
series.Runtime = show.runtime;
|
||||
@@ -71,6 +80,10 @@ namespace NzbDrone.Core.MetadataSource
|
||||
series.TitleSlug = show.url.ToLower().Replace("http://trakt.tv/show/", "");
|
||||
series.Status = GetSeriesStatus(show.status);
|
||||
|
||||
series.Seasons = show.seasons.Select(s => new Tv.Season
|
||||
{
|
||||
SeasonNumber = s.season
|
||||
}).OrderByDescending(s => s.SeasonNumber).ToList();
|
||||
series.Images.Add(new MediaCover.MediaCover { CoverType = MediaCoverTypes.Banner, Url = show.images.banner });
|
||||
series.Images.Add(new MediaCover.MediaCover { CoverType = MediaCoverTypes.Poster, Url = GetPosterThumbnailUrl(show.images.poster) });
|
||||
series.Images.Add(new MediaCover.MediaCover { CoverType = MediaCoverTypes.Fanart, Url = show.images.fanart });
|
||||
@@ -141,6 +154,12 @@ namespace NzbDrone.Core.MetadataSource
|
||||
{
|
||||
DateTime result;
|
||||
|
||||
//Todo: Remove this when DST ends and/or trakt fixes DST airings in EST/EDT
|
||||
if (iso != null && iso.EndsWith("-05:00"))
|
||||
{
|
||||
iso = iso.Replace("-05:00", "-04:00");
|
||||
}
|
||||
|
||||
if (!DateTime.TryParse(iso, out result))
|
||||
return null;
|
||||
|
||||
@@ -158,6 +177,14 @@ namespace NzbDrone.Core.MetadataSource
|
||||
return match.Captures[0].Value;
|
||||
}
|
||||
|
||||
private static string GetSearchTerm(string phrase)
|
||||
{
|
||||
phrase = phrase.RemoveAccent().ToLower();
|
||||
phrase = phrase.Replace("&", "and");
|
||||
phrase = InvalidSearchCharRegex.Replace(phrase, string.Empty);
|
||||
phrase = phrase.CleanSpaces().Replace(" ", "+");
|
||||
|
||||
return phrase;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user