fixed: search using tvdb id is now fixed.

pull/6/head
Keivan Beigi 10 years ago
parent efbe052b26
commit c368335183

@ -1,69 +1,69 @@
using System;
using System.Collections.Generic;
using Moq;
using NUnit.Framework;
using NzbDrone.Common.Http;
using NzbDrone.Core.MetadataSource;
using NzbDrone.Core.MetadataSource.Trakt;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.MetadataSourceTests
{
[TestFixture]
public class TraktProxyQueryFixture : CoreTest<TraktProxy>
{
[TestCase("tvdb:78804", "/78804/")]
[TestCase("TVDB:78804", "/78804/")]
[TestCase("TVDB: 78804 ", "/78804/")]
public void search_by_lookup(string title, string expectedPartialQuery)
{
Assert.Throws<TraktException>(() => Subject.SearchForNewSeries(title));
Mocker.GetMock<IHttpClient>()
.Verify(v => v.Get<Show>(It.Is<HttpRequest>(d => d.Url.ToString().Contains(expectedPartialQuery))), Times.Once());
ExceptionVerification.ExpectedWarns(1);
}
[TestCase("imdb:tt0436992", "tt0436992")]
[TestCase("imdb:0436992", "tt0436992")]
[TestCase("IMDB:0436992", "tt0436992")]
[TestCase("IMDB: 0436992 ", "tt0436992")]
// [TestCase("The BigBangTheory", "the+bigbangtheory")]
// [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("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("Utopia (US) (2014)", "utopia+us+2014")]
[TestCase("Utopia US 2014", "utopia+us+2014")]
// [TestCase("UtopiaUS2014", "utopia+us+2014")]
[TestCase("@Midnight", "midnight")]
// [TestCase("The4400", "the+4400")]
// [TestCase("StargateSG-1", "stargate+sg-1")]
// [TestCase("Warehouse13", "warehouse+13")]
// [TestCase("Ben10AlienForce", "ben+10+alien+force")]
// [TestCase("FridayThe13thTheSeries","friday+the+13th+the+series")]
[TestCase("W1A", "w1a")]
[TestCase("O2Be", "o2be")]
// [TestCase("TeenMom2", "teen+mom+2")]
[TestCase("123-456-789", "123-456-789")]
// [TestCase("BuckRodgersInThe25thCentury", "buck+rodgers+in+the+25th+century")]
// [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")]
public void search_by_query(string title, string expectedPartialQuery)
{
expectedPartialQuery = String.Format("query={0}&", expectedPartialQuery);
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());
ExceptionVerification.ExpectedWarns(1);
}
}
}
//using System;
//using System.Collections.Generic;
//using Moq;
//using NUnit.Framework;
//using NzbDrone.Common.Http;
//using NzbDrone.Core.MetadataSource;
//using NzbDrone.Core.MetadataSource.Trakt;
//using NzbDrone.Core.Test.Framework;
//using NzbDrone.Test.Common;
//
//namespace NzbDrone.Core.Test.MetadataSourceTests
//{
// [TestFixture]
// public class TraktProxyQueryFixture : CoreTest<TraktProxy>
// {
// [TestCase("tvdb:78804", "/78804/")]
// [TestCase("TVDB:78804", "/78804/")]
// [TestCase("TVDB: 78804 ", "/78804/")]
// public void search_by_lookup(string title, string expectedPartialQuery)
// {
// Assert.Throws<TraktException>(() => Subject.SearchForNewSeries(title));
//
// Mocker.GetMock<IHttpClient>()
// .Verify(v => v.Get<Show>(It.Is<HttpRequest>(d => d.Url.ToString().Contains(expectedPartialQuery))), Times.Once());
//
// ExceptionVerification.ExpectedWarns(1);
// }
//
// [TestCase("imdb:tt0436992", "tt0436992")]
// [TestCase("imdb:0436992", "tt0436992")]
// [TestCase("IMDB:0436992", "tt0436992")]
// [TestCase("IMDB: 0436992 ", "tt0436992")]
//// [TestCase("The BigBangTheory", "the+bigbangtheory")]
//// [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("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("Utopia (US) (2014)", "utopia+us+2014")]
// [TestCase("Utopia US 2014", "utopia+us+2014")]
//// [TestCase("UtopiaUS2014", "utopia+us+2014")]
// [TestCase("@Midnight", "midnight")]
//// [TestCase("The4400", "the+4400")]
//// [TestCase("StargateSG-1", "stargate+sg-1")]
//// [TestCase("Warehouse13", "warehouse+13")]
//// [TestCase("Ben10AlienForce", "ben+10+alien+force")]
//// [TestCase("FridayThe13thTheSeries","friday+the+13th+the+series")]
// [TestCase("W1A", "w1a")]
// [TestCase("O2Be", "o2be")]
//// [TestCase("TeenMom2", "teen+mom+2")]
// [TestCase("123-456-789", "123-456-789")]
//// [TestCase("BuckRodgersInThe25thCentury", "buck+rodgers+in+the+25th+century")]
//// [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")]
// public void search_by_query(string title, string expectedPartialQuery)
// {
// expectedPartialQuery = String.Format("query={0}&", expectedPartialQuery);
//
// 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());
//
// ExceptionVerification.ExpectedWarns(1);
// }
// }
//}

@ -32,7 +32,9 @@ namespace NzbDrone.Core.Test.MetadataSourceTests
[TestCase("Rob & Big", "Rob & Big")]
[TestCase("M*A*S*H", "M*A*S*H")]
//[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)
{
var result = Subject.SearchForNewSeries(title);

@ -1,15 +1,14 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using NLog;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Http;
using NzbDrone.Core.MediaCover;
using NzbDrone.Core.MetadataSource.Trakt;
using NzbDrone.Core.Tv;
using TVDBSharp;
using TVDBSharp.Models.Enums;
namespace NzbDrone.Core.MetadataSource
@ -17,63 +16,36 @@ namespace NzbDrone.Core.MetadataSource
public class TvDbProxy : ISearchForNewSeries, IProvideSeriesInfo
{
private readonly Logger _logger;
private readonly IHttpClient _httpClient;
private static readonly Regex CollapseSpaceRegex = new Regex(@"\s+", 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 TVDBSharp.TVDB tvdb;
private readonly 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;
_httpClient = httpClient;
tvdb = new TVDBSharp.TVDB("5D2D188E86E07F4F");
_tvdb = new TVDB("5D2D188E86E07F4F");
}
private IEnumerable<TVDBSharp.Models.Show> SearchTrakt(string title)
{
/* Common.Http.HttpRequest request;
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();
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>();
}
request = _requestBuilder.Build("/{slug}/extended");
request.AddSegment("path", "show");
request.AddSegment("resource", "summary");
request.AddSegment("slug", GetSearchTerm(slug));
return new List<Show> { _httpClient.Get<Show>(request).Resource };
return new[] { _tvdb.GetShow(tvdbId) };
}
if (lowerTitle.StartsWith("imdb:") || lowerTitle.StartsWith("imdbid:"))
{
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));
return _tvdb.Search(GetSearchTerm(lowerTitle));
}
public List<Series> SearchForNewSeries(string title)
@ -101,14 +73,7 @@ namespace NzbDrone.Core.MetadataSource
public Tuple<Series, List<Tv.Episode>> GetSeriesInfo(int 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 tvdbSeries = _tvdb.GetShow(tvdbSeriesId);
var episodes = tvdbSeries.Episodes.Select(MapEpisode);
@ -193,14 +158,6 @@ namespace NzbDrone.Core.MetadataSource
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)
{
@ -212,27 +169,6 @@ namespace NzbDrone.Core.MetadataSource
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)
{
phrase = phrase.RemoveAccent();
@ -251,15 +187,6 @@ namespace NzbDrone.Core.MetadataSource
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)
{
@ -273,31 +200,6 @@ namespace NzbDrone.Core.MetadataSource
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)
{

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30723.0
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{57A04B72-8088-4F75-A582-1158CF8291F7}"
EndProject

@ -1,3 +1,3 @@
<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>

Loading…
Cancel
Save