mirror of https://github.com/Sonarr/Sonarr
fixed: search using tvdb id is now fixed.
This commit is contained in:
parent
efbe052b26
commit
c368335183
|
@ -1,69 +1,69 @@
|
||||||
using System;
|
//using System;
|
||||||
using System.Collections.Generic;
|
//using System.Collections.Generic;
|
||||||
using Moq;
|
//using Moq;
|
||||||
using NUnit.Framework;
|
//using NUnit.Framework;
|
||||||
using NzbDrone.Common.Http;
|
//using NzbDrone.Common.Http;
|
||||||
using NzbDrone.Core.MetadataSource;
|
//using NzbDrone.Core.MetadataSource;
|
||||||
using NzbDrone.Core.MetadataSource.Trakt;
|
//using NzbDrone.Core.MetadataSource.Trakt;
|
||||||
using NzbDrone.Core.Test.Framework;
|
//using NzbDrone.Core.Test.Framework;
|
||||||
using NzbDrone.Test.Common;
|
//using NzbDrone.Test.Common;
|
||||||
|
//
|
||||||
namespace NzbDrone.Core.Test.MetadataSourceTests
|
//namespace NzbDrone.Core.Test.MetadataSourceTests
|
||||||
{
|
//{
|
||||||
[TestFixture]
|
// [TestFixture]
|
||||||
public class TraktProxyQueryFixture : CoreTest<TraktProxy>
|
// public class TraktProxyQueryFixture : CoreTest<TraktProxy>
|
||||||
{
|
// {
|
||||||
[TestCase("tvdb:78804", "/78804/")]
|
// [TestCase("tvdb:78804", "/78804/")]
|
||||||
[TestCase("TVDB:78804", "/78804/")]
|
// [TestCase("TVDB:78804", "/78804/")]
|
||||||
[TestCase("TVDB: 78804 ", "/78804/")]
|
// [TestCase("TVDB: 78804 ", "/78804/")]
|
||||||
public void search_by_lookup(string title, string expectedPartialQuery)
|
// public void search_by_lookup(string title, string expectedPartialQuery)
|
||||||
{
|
// {
|
||||||
Assert.Throws<TraktException>(() => Subject.SearchForNewSeries(title));
|
// Assert.Throws<TraktException>(() => Subject.SearchForNewSeries(title));
|
||||||
|
//
|
||||||
Mocker.GetMock<IHttpClient>()
|
// Mocker.GetMock<IHttpClient>()
|
||||||
.Verify(v => v.Get<Show>(It.Is<HttpRequest>(d => d.Url.ToString().Contains(expectedPartialQuery))), Times.Once());
|
// .Verify(v => v.Get<Show>(It.Is<HttpRequest>(d => d.Url.ToString().Contains(expectedPartialQuery))), Times.Once());
|
||||||
|
//
|
||||||
ExceptionVerification.ExpectedWarns(1);
|
// ExceptionVerification.ExpectedWarns(1);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
[TestCase("imdb:tt0436992", "tt0436992")]
|
// [TestCase("imdb:tt0436992", "tt0436992")]
|
||||||
[TestCase("imdb:0436992", "tt0436992")]
|
// [TestCase("imdb:0436992", "tt0436992")]
|
||||||
[TestCase("IMDB:0436992", "tt0436992")]
|
// [TestCase("IMDB:0436992", "tt0436992")]
|
||||||
[TestCase("IMDB: 0436992 ", "tt0436992")]
|
// [TestCase("IMDB: 0436992 ", "tt0436992")]
|
||||||
// [TestCase("The BigBangTheory", "the+bigbangtheory")]
|
//// [TestCase("The BigBangTheory", "the+bigbangtheory")]
|
||||||
// [TestCase("TheBigBangTheory", "the+big+bang+theory")]
|
//// [TestCase("TheBigBangTheory", "the+big+bang+theory")]
|
||||||
// [TestCase(" TheBigBangTheory", "the+big+bang+theory")]
|
//// [TestCase(" TheBigBangTheory", "the+big+bang+theory")]
|
||||||
[TestCase("Agents of S.H.I.E.L.D.", "agents+of+s.h.i.e.l.d.")]
|
// [TestCase("Agents of S.H.I.E.L.D.", "agents+of+s.h.i.e.l.d.")]
|
||||||
[TestCase("Marvel's Agents of S.H.I.E.L.D.", "marvels+agents+of+s.h.i.e.l.d.")]
|
// [TestCase("Marvel's Agents of S.H.I.E.L.D.", "marvels+agents+of+s.h.i.e.l.d.")]
|
||||||
// [TestCase("Marvel'sAgentsOfS.H.I.E.L.D.", "marvels+agents+of+s.h.i.e.l.d.")]
|
//// [TestCase("Marvel'sAgentsOfS.H.I.E.L.D.", "marvels+agents+of+s.h.i.e.l.d.")]
|
||||||
[TestCase("Utopia (US) (2014)", "utopia+us+2014")]
|
// [TestCase("Utopia (US) (2014)", "utopia+us+2014")]
|
||||||
[TestCase("Utopia US 2014", "utopia+us+2014")]
|
|
||||||
// [TestCase("Utopia US 2014", "utopia+us+2014")]
|
// [TestCase("Utopia US 2014", "utopia+us+2014")]
|
||||||
[TestCase("@Midnight", "midnight")]
|
//// [TestCase("UtopiaUS2014", "utopia+us+2014")]
|
||||||
// [TestCase("The4400", "the+4400")]
|
// [TestCase("@Midnight", "midnight")]
|
||||||
// [TestCase("StargateSG-1", "stargate+sg-1")]
|
//// [TestCase("The4400", "the+4400")]
|
||||||
// [TestCase("Warehouse13", "warehouse+13")]
|
//// [TestCase("StargateSG-1", "stargate+sg-1")]
|
||||||
// [TestCase("Ben10AlienForce", "ben+10+alien+force")]
|
//// [TestCase("Warehouse13", "warehouse+13")]
|
||||||
// [TestCase("FridayThe13thTheSeries","friday+the+13th+the+series")]
|
//// [TestCase("Ben10AlienForce", "ben+10+alien+force")]
|
||||||
[TestCase("W1A", "w1a")]
|
//// [TestCase("FridayThe13thTheSeries","friday+the+13th+the+series")]
|
||||||
[TestCase("O2Be", "o2be")]
|
// [TestCase("W1A", "w1a")]
|
||||||
// [TestCase("TeenMom2", "teen+mom+2")]
|
// [TestCase("O2Be", "o2be")]
|
||||||
[TestCase("123-456-789", "123-456-789")]
|
//// [TestCase("TeenMom2", "teen+mom+2")]
|
||||||
// [TestCase("BuckRodgersInThe25thCentury", "buck+rodgers+in+the+25th+century")]
|
// [TestCase("123-456-789", "123-456-789")]
|
||||||
// [TestCase("EPDaily", "ep+daily")]
|
//// [TestCase("BuckRodgersInThe25thCentury", "buck+rodgers+in+the+25th+century")]
|
||||||
[TestCase("6ad072c8-d000-4ed5-97d5-324858c45774", "6ad072c8-d000-4ed5-97d5-324858c45774")]
|
//// [TestCase("EPDaily", "ep+daily")]
|
||||||
[TestCase("6AD072C8-D000-4ED5-97D5-324858C45774", "6ad072c8-d000-4ed5-97d5-324858c45774")]
|
// [TestCase("6ad072c8-d000-4ed5-97d5-324858c45774", "6ad072c8-d000-4ed5-97d5-324858c45774")]
|
||||||
[TestCase("MythBusters", "mythbusters")]
|
// [TestCase("6AD072C8-D000-4ED5-97D5-324858C45774", "6ad072c8-d000-4ed5-97d5-324858c45774")]
|
||||||
public void search_by_query(string title, string expectedPartialQuery)
|
// [TestCase("MythBusters", "mythbusters")]
|
||||||
{
|
// public void search_by_query(string title, string expectedPartialQuery)
|
||||||
expectedPartialQuery = String.Format("query={0}&", expectedPartialQuery);
|
// {
|
||||||
|
// expectedPartialQuery = String.Format("query={0}&", expectedPartialQuery);
|
||||||
Assert.Throws<TraktException>(() => Subject.SearchForNewSeries(title));
|
//
|
||||||
|
// Assert.Throws<TraktException>(() => Subject.SearchForNewSeries(title));
|
||||||
Mocker.GetMock<IHttpClient>()
|
//
|
||||||
.Verify(v => v.Get<List<Show>>(It.Is<HttpRequest>(d => d.Url.ToString().Contains(expectedPartialQuery))), Times.Once());
|
// Mocker.GetMock<IHttpClient>()
|
||||||
|
// .Verify(v => v.Get<List<Show>>(It.Is<HttpRequest>(d => d.Url.ToString().Contains(expectedPartialQuery))), Times.Once());
|
||||||
ExceptionVerification.ExpectedWarns(1);
|
//
|
||||||
}
|
// ExceptionVerification.ExpectedWarns(1);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//}
|
||||||
|
|
|
@ -32,7 +32,9 @@ namespace NzbDrone.Core.Test.MetadataSourceTests
|
||||||
[TestCase("Rob & Big", "Rob & Big")]
|
[TestCase("Rob & Big", "Rob & Big")]
|
||||||
[TestCase("M*A*S*H", "M*A*S*H")]
|
[TestCase("M*A*S*H", "M*A*S*H")]
|
||||||
//[TestCase("imdb:tt0436992", "Doctor Who (2005)")]
|
//[TestCase("imdb:tt0436992", "Doctor Who (2005)")]
|
||||||
//[TestCase("tvdb:78804", "Doctor Who (2005)")]
|
[TestCase("tvdb:78804", "Doctor Who (2005)")]
|
||||||
|
[TestCase("tvdbid:78804", "Doctor Who (2005)")]
|
||||||
|
[TestCase("tvdbid: 78804 ", "Doctor Who (2005)")]
|
||||||
public void successful_search(string title, string expected)
|
public void successful_search(string title, string expected)
|
||||||
{
|
{
|
||||||
var result = Subject.SearchForNewSeries(title);
|
var result = Subject.SearchForNewSeries(title);
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
using NzbDrone.Common.Http;
|
|
||||||
using NzbDrone.Core.MediaCover;
|
using NzbDrone.Core.MediaCover;
|
||||||
using NzbDrone.Core.MetadataSource.Trakt;
|
using NzbDrone.Core.MetadataSource.Trakt;
|
||||||
using NzbDrone.Core.Tv;
|
using NzbDrone.Core.Tv;
|
||||||
|
using TVDBSharp;
|
||||||
using TVDBSharp.Models.Enums;
|
using TVDBSharp.Models.Enums;
|
||||||
|
|
||||||
namespace NzbDrone.Core.MetadataSource
|
namespace NzbDrone.Core.MetadataSource
|
||||||
|
@ -17,63 +16,36 @@ namespace NzbDrone.Core.MetadataSource
|
||||||
public class TvDbProxy : ISearchForNewSeries, IProvideSeriesInfo
|
public class TvDbProxy : ISearchForNewSeries, IProvideSeriesInfo
|
||||||
{
|
{
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
private readonly IHttpClient _httpClient;
|
|
||||||
private static readonly Regex CollapseSpaceRegex = new Regex(@"\s+", RegexOptions.Compiled);
|
private static readonly Regex CollapseSpaceRegex = new Regex(@"\s+", RegexOptions.Compiled);
|
||||||
private static readonly Regex InvalidSearchCharRegex = new Regex(@"(?:\*|\(|\)|'|!|@|\+)", RegexOptions.Compiled);
|
private static readonly Regex InvalidSearchCharRegex = new Regex(@"(?:\*|\(|\)|'|!|@|\+)", RegexOptions.Compiled);
|
||||||
private static readonly Regex ExpandCamelCaseRegEx = new Regex(@"(?<!^|[A-Z]\.?|[^\w.])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|(?<!^|\d\.?|[^\w.])(?=\d)", RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);
|
|
||||||
|
|
||||||
private readonly HttpRequestBuilder _requestBuilder;
|
private readonly TVDB _tvdb;
|
||||||
private TVDBSharp.TVDB tvdb;
|
|
||||||
|
|
||||||
public TvDbProxy(Logger logger, IHttpClient httpClient)
|
public TvDbProxy(Logger logger)
|
||||||
{
|
{
|
||||||
_requestBuilder = new HttpRequestBuilder("http://api.trakt.tv/{path}/{resource}.json/bc3c2c460f22cbb01c264022b540e191");
|
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_httpClient = httpClient;
|
_tvdb = new TVDB("5D2D188E86E07F4F");
|
||||||
|
|
||||||
|
|
||||||
tvdb = new TVDBSharp.TVDB("5D2D188E86E07F4F");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<TVDBSharp.Models.Show> SearchTrakt(string title)
|
private IEnumerable<TVDBSharp.Models.Show> SearchTrakt(string title)
|
||||||
{
|
{
|
||||||
/* Common.Http.HttpRequest request;
|
|
||||||
|
|
||||||
var lowerTitle = title.ToLowerInvariant();
|
var lowerTitle = title.ToLowerInvariant();
|
||||||
|
|
||||||
if (lowerTitle.StartsWith("tvdb:") || lowerTitle.StartsWith("tvdbid:") /*|| lowerTitle.StartsWith("slug:")#1#)
|
if (lowerTitle.StartsWith("tvdb:") || lowerTitle.StartsWith("tvdbid:"))
|
||||||
{
|
{
|
||||||
var slug = lowerTitle.Split(':')[1].Trim();
|
var slug = lowerTitle.Split(':')[1].Trim();
|
||||||
|
|
||||||
if (slug.IsNullOrWhiteSpace() || slug.Any(char.IsWhiteSpace))
|
int tvdbId;
|
||||||
|
|
||||||
|
if (slug.IsNullOrWhiteSpace() || slug.Any(char.IsWhiteSpace) || !Int32.TryParse(slug, out tvdbId))
|
||||||
{
|
{
|
||||||
return Enumerable.Empty<TVDBSharp.Models.Show>();
|
return Enumerable.Empty<TVDBSharp.Models.Show>();
|
||||||
}
|
}
|
||||||
|
|
||||||
request = _requestBuilder.Build("/{slug}/extended");
|
return new[] { _tvdb.GetShow(tvdbId) };
|
||||||
|
|
||||||
request.AddSegment("path", "show");
|
|
||||||
request.AddSegment("resource", "summary");
|
|
||||||
request.AddSegment("slug", GetSearchTerm(slug));
|
|
||||||
|
|
||||||
return new List<Show> { _httpClient.Get<Show>(request).Resource };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lowerTitle.StartsWith("imdb:") || lowerTitle.StartsWith("imdbid:"))
|
return _tvdb.Search(GetSearchTerm(lowerTitle));
|
||||||
{
|
|
||||||
var slug = lowerTitle.Split(':')[1].TrimStart('t').Trim();
|
|
||||||
|
|
||||||
if (slug.IsNullOrWhiteSpace() || !slug.All(char.IsDigit) || slug.Length < 7)
|
|
||||||
{
|
|
||||||
return Enumerable.Empty<Show>();
|
|
||||||
}
|
|
||||||
|
|
||||||
title = "tt" + slug;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
return tvdb.Search(GetSearchTerm(title));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Series> SearchForNewSeries(string title)
|
public List<Series> SearchForNewSeries(string title)
|
||||||
|
@ -101,14 +73,7 @@ namespace NzbDrone.Core.MetadataSource
|
||||||
|
|
||||||
public Tuple<Series, List<Tv.Episode>> GetSeriesInfo(int tvdbSeriesId)
|
public Tuple<Series, List<Tv.Episode>> GetSeriesInfo(int tvdbSeriesId)
|
||||||
{
|
{
|
||||||
|
var tvdbSeries = _tvdb.GetShow(tvdbSeriesId);
|
||||||
var request = _requestBuilder.Build("/{tvdbId}/extended");
|
|
||||||
|
|
||||||
request.AddSegment("path", "show");
|
|
||||||
request.AddSegment("resource", "summary");
|
|
||||||
request.AddSegment("tvdbId", tvdbSeriesId.ToString());
|
|
||||||
|
|
||||||
var tvdbSeries = tvdb.GetShow(tvdbSeriesId);
|
|
||||||
|
|
||||||
var episodes = tvdbSeries.Episodes.Select(MapEpisode);
|
var episodes = tvdbSeries.Episodes.Select(MapEpisode);
|
||||||
|
|
||||||
|
@ -193,14 +158,6 @@ namespace NzbDrone.Core.MetadataSource
|
||||||
return episode;
|
return episode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetPosterThumbnailUrl(string posterUrl)
|
|
||||||
{
|
|
||||||
if (posterUrl.Contains("poster-small.jpg") || posterUrl.Contains("poster-dark.jpg")) return posterUrl;
|
|
||||||
|
|
||||||
var extension = Path.GetExtension(posterUrl);
|
|
||||||
var withoutExtension = posterUrl.Substring(0, posterUrl.Length - extension.Length);
|
|
||||||
return withoutExtension + "-300" + extension;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static SeriesStatusType GetSeriesStatus(Status status)
|
private static SeriesStatusType GetSeriesStatus(Status status)
|
||||||
{
|
{
|
||||||
|
@ -212,27 +169,6 @@ namespace NzbDrone.Core.MetadataSource
|
||||||
return SeriesStatusType.Continuing;
|
return SeriesStatusType.Continuing;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DateTime? FromIso(string iso)
|
|
||||||
{
|
|
||||||
DateTime result;
|
|
||||||
|
|
||||||
if (!DateTime.TryParse(iso, out result))
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return result.ToUniversalTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string FromIsoToString(string iso)
|
|
||||||
{
|
|
||||||
if (String.IsNullOrWhiteSpace(iso)) return null;
|
|
||||||
|
|
||||||
var match = Regex.Match(iso, @"^\d{4}\W\d{2}\W\d{2}");
|
|
||||||
|
|
||||||
if (!match.Success) return null;
|
|
||||||
|
|
||||||
return match.Captures[0].Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string GetSearchTerm(string phrase)
|
private static string GetSearchTerm(string phrase)
|
||||||
{
|
{
|
||||||
phrase = phrase.RemoveAccent();
|
phrase = phrase.RemoveAccent();
|
||||||
|
@ -251,15 +187,6 @@ namespace NzbDrone.Core.MetadataSource
|
||||||
return phrase;
|
return phrase;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int GetYear(int year, int firstAired)
|
|
||||||
{
|
|
||||||
if (year > 1969) return year;
|
|
||||||
|
|
||||||
if (firstAired == 0) return DateTime.Today.Year;
|
|
||||||
|
|
||||||
return year;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Tv.Ratings GetRatings(int ratingCount, double? rating)
|
private static Tv.Ratings GetRatings(int ratingCount, double? rating)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -273,31 +200,6 @@ namespace NzbDrone.Core.MetadataSource
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Tv.Actor> GetActors(People people)
|
|
||||||
{
|
|
||||||
if (people == null)
|
|
||||||
{
|
|
||||||
return new List<Tv.Actor>();
|
|
||||||
}
|
|
||||||
|
|
||||||
return GetActors(people.actors).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IEnumerable<Tv.Actor> GetActors(IEnumerable<Trakt.Actor> trakcActors)
|
|
||||||
{
|
|
||||||
foreach (var traktActor in trakcActors)
|
|
||||||
{
|
|
||||||
var actor = new Tv.Actor
|
|
||||||
{
|
|
||||||
Name = traktActor.name,
|
|
||||||
Character = traktActor.character,
|
|
||||||
};
|
|
||||||
|
|
||||||
actor.Images.Add(new MediaCover.MediaCover(MediaCoverTypes.Headshot, traktActor.images.headshot));
|
|
||||||
|
|
||||||
yield return actor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<Tv.Season> GetSeasons(TVDBSharp.Models.Show show)
|
private static List<Tv.Season> GetSeasons(TVDBSharp.Models.Show show)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 2013
|
# Visual Studio 2013
|
||||||
VisualStudioVersion = 12.0.30723.0
|
VisualStudioVersion = 12.0.31101.0
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{57A04B72-8088-4F75-A582-1158CF8291F7}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{57A04B72-8088-4F75-A582-1158CF8291F7}"
|
||||||
EndProject
|
EndProject
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
<div class="text-center hint col-md-12">
|
<div class="text-center hint col-md-12">
|
||||||
<span>You can also search by tvdbid and imdbid using the tvdb: and imdb: prefixes.</span>
|
<span>You can also search by tvdbid using the tvdb: prefixes.</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue