removed trakt references, added user agent to tvdb requests

This commit is contained in:
Keivan Beigi
2014-12-31 14:11:45 -08:00
parent 7e76a36d68
commit d4331e9470
23 changed files with 71 additions and 399 deletions
@@ -6,7 +6,7 @@ using NzbDrone.Core.Tv;
namespace NzbDrone.Core.MetadataSource
{
public class TraktSearchSeriesComparer : IComparer<Series>
public class SearchSeriesComparer : IComparer<Series>
{
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);
@@ -14,10 +14,10 @@ namespace NzbDrone.Core.MetadataSource
public String SearchQuery { get; private set; }
private String _searchQueryWithoutYear;
private readonly String _searchQueryWithoutYear;
private Int32? _year;
public TraktSearchSeriesComparer(String searchQuery)
public SearchSeriesComparer(String searchQuery)
{
SearchQuery = searchQuery;
@@ -1,9 +0,0 @@
namespace NzbDrone.Core.MetadataSource.Trakt
{
public class Actor
{
public string name { get; set; }
public string character { get; set; }
public Images images { get; set; }
}
}
@@ -1,19 +0,0 @@
namespace NzbDrone.Core.MetadataSource.Trakt
{
public class Episode
{
public int season { get; set; }
public int episode { get; set; }
public int number { get; set; }
public int tvdb_id { get; set; }
public string title { get; set; }
public string overview { get; set; }
public int first_aired { get; set; }
public string first_aired_iso { get; set; }
public int first_aired_utc { get; set; }
public string url { get; set; }
public string screen { get; set; }
public Ratings ratings { get; set; }
public Images images { get; set; }
}
}
@@ -1,62 +0,0 @@
using System.Collections.Generic;
namespace NzbDrone.Core.MetadataSource.Trakt
{
public class Show
{
public string title { get; set; }
public int year { get; set; }
public string url { get; set; }
public int first_aired { get; set; }
public string first_aired_iso { get; set; }
public int first_aired_utc { get; set; }
public string country { get; set; }
public string overview { get; set; }
public int runtime { get; set; }
public string status { get; set; }
public string network { get; set; }
public string air_day { get; set; }
public string air_day_utc { get; set; }
public string air_time { get; set; }
public string air_time_utc { get; set; }
public string certification { get; set; }
public string imdb_id { get; set; }
public int tvdb_id { get; set; }
public int tvrage_id { get; set; }
public int last_updated { get; set; }
public string poster { get; set; }
public bool? ended { get; set; }
public Images images { get; set; }
public List<string> genres { get; set; }
public List<Season> seasons { get; set; }
public Ratings ratings { get; set; }
public People people { get; set; }
}
public class SearchShow
{
public string title { get; set; }
public int year { get; set; }
public string url { get; set; }
public int first_aired { get; set; }
public string first_aired_iso { get; set; }
public int first_aired_utc { get; set; }
public string country { get; set; }
public string overview { get; set; }
public int runtime { get; set; }
public string status { get; set; }
public string network { get; set; }
public string air_day { get; set; }
public string air_day_utc { get; set; }
public string air_time { get; set; }
public string air_time_utc { get; set; }
public string certification { get; set; }
public string imdb_id { get; set; }
public int tvdb_id { get; set; }
public int tvrage_id { get; set; }
public int last_updated { get; set; }
public string poster { get; set; }
public Images images { get; set; }
public List<string> genres { get; set; }
}
}
@@ -1,11 +0,0 @@
namespace NzbDrone.Core.MetadataSource.Trakt
{
public class Images
{
public string poster { get; set; }
public string fanart { get; set; }
public string banner { get; set; }
public string screen { get; set; }
public string headshot { get; set; }
}
}
@@ -1,9 +0,0 @@
using System.Collections.Generic;
namespace NzbDrone.Core.MetadataSource.Trakt
{
public class People
{
public List<Actor> actors { get; set; }
}
}
@@ -1,12 +0,0 @@
using System;
namespace NzbDrone.Core.MetadataSource.Trakt
{
public class Ratings
{
public Int32 percentage { get; set; }
public Int32 votes { get; set; }
public Int32 loved { get; set; }
public Int32 hated { get; set; }
}
}
@@ -1,13 +0,0 @@
using System.Collections.Generic;
namespace NzbDrone.Core.MetadataSource.Trakt
{
public class Season
{
public int season { get; set; }
public List<Episode> episodes { get; set; }
public string url { get; set; }
public string poster { get; set; }
public Images images { get; set; }
}
}
@@ -1,16 +0,0 @@
using System.Net;
using NzbDrone.Core.Exceptions;
namespace NzbDrone.Core.MetadataSource.Trakt
{
public class TraktException : NzbDroneClientException
{
public TraktException(string message) : base(HttpStatusCode.ServiceUnavailable, message)
{
}
public TraktException(string message, params object[] args) : base(HttpStatusCode.ServiceUnavailable, message, args)
{
}
}
}
+8 -10
View File
@@ -7,7 +7,7 @@ using System.Web;
using NLog;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.MediaCover;
using NzbDrone.Core.MetadataSource.Trakt;
using NzbDrone.Core.MetadataSource.Tvdb;
using NzbDrone.Core.Tv;
using TVDBSharp;
using TVDBSharp.Models.Enums;
@@ -28,7 +28,7 @@ namespace NzbDrone.Core.MetadataSource
_tvdb = new TVDB("5D2D188E86E07F4F");
}
private IEnumerable<TVDBSharp.Models.Show> SearchTrakt(string title)
private IEnumerable<TVDBSharp.Models.Show> SearchTvdb(string title)
{
var lowerTitle = title.ToLowerInvariant();
@@ -47,11 +47,9 @@ namespace NzbDrone.Core.MetadataSource
{
return new[] { _tvdb.GetShow(tvdbId) };
}
catch (WebException ex)
catch (Common.Http.HttpException ex)
{
var resp = ex.Response as HttpWebResponse;
if (resp != null && resp.StatusCode == HttpStatusCode.NotFound)
if (ex.Response.StatusCode == HttpStatusCode.NotFound)
{
return Enumerable.Empty<TVDBSharp.Models.Show>();
}
@@ -67,22 +65,22 @@ namespace NzbDrone.Core.MetadataSource
{
try
{
var tvdbSeries = SearchTrakt(title.Trim());
var tvdbSeries = SearchTvdb(title.Trim());
var series = tvdbSeries.Select(MapSeries).ToList();
series.Sort(new TraktSearchSeriesComparer(title));
series.Sort(new SearchSeriesComparer(title));
return series;
}
catch (Common.Http.HttpException)
{
throw new TraktException("Search for '{0}' failed. Unable to communicate with Trakt.", title);
throw new TvdbException("Search for '{0}' failed. Unable to communicate with TVDB.", title);
}
catch (Exception ex)
{
_logger.WarnException(ex.Message, ex);
throw new TraktException("Search for '{0}' failed. Invalid response received from Trakt.", title);
throw new TvdbException("Search for '{0}' failed. Invalid response received from TVDB.", title);
}
}
@@ -0,0 +1,16 @@
using System.Net;
using NzbDrone.Core.Exceptions;
namespace NzbDrone.Core.MetadataSource.Tvdb
{
public class TvdbException : NzbDroneClientException
{
public TvdbException(string message) : base(HttpStatusCode.ServiceUnavailable, message)
{
}
public TvdbException(string message, params object[] args) : base(HttpStatusCode.ServiceUnavailable, message, args)
{
}
}
}