From 73b1e227d35db3554a0176d1ca81a73f24cf60c3 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 18 Dec 2015 11:43:42 -0500 Subject: [PATCH] fix tvdb lookup by imdb id --- MediaBrowser.Api/Playback/MediaInfoService.cs | 2 +- .../TV/TvdbSeriesProvider.cs | 44 +++++++++++++++++-- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/MediaBrowser.Api/Playback/MediaInfoService.cs b/MediaBrowser.Api/Playback/MediaInfoService.cs index 5a2c286d5..3b577ac01 100644 --- a/MediaBrowser.Api/Playback/MediaInfoService.cs +++ b/MediaBrowser.Api/Playback/MediaInfoService.cs @@ -156,7 +156,7 @@ namespace MediaBrowser.Api.Playback { var mediaSourceId = request.MediaSourceId; - SetDeviceSpecificData(request.Id, info, profile, authInfo, request.MaxStreamingBitrate, request.StartTimeTicks ?? 0, mediaSourceId, request.AudioStreamIndex, request.SubtitleStreamIndex); + SetDeviceSpecificData(request.Id, info, profile, authInfo, request.MaxStreamingBitrate ?? profile.MaxStreamingBitrate, request.StartTimeTicks ?? 0, mediaSourceId, request.AudioStreamIndex, request.SubtitleStreamIndex); } return ToOptimizedResult(info); diff --git a/MediaBrowser.Providers/TV/TvdbSeriesProvider.cs b/MediaBrowser.Providers/TV/TvdbSeriesProvider.cs index 5df5151ca..d63022900 100644 --- a/MediaBrowser.Providers/TV/TvdbSeriesProvider.cs +++ b/MediaBrowser.Providers/TV/TvdbSeriesProvider.cs @@ -56,7 +56,7 @@ namespace MediaBrowser.Providers.TV private const string SeriesSearchUrl = "http://www.thetvdb.com/api/GetSeries.php?seriesname={0}&language={1}"; private const string SeriesGetZip = "http://www.thetvdb.com/api/{0}/series/{1}/all/{2}.zip"; - private const string SeriesGetZipByImdbId = "http://www.thetvdb.com/api/{0}/GetSeriesByRemoteID.php?imdbid={1}&language={2}"; + private const string GetSeriesByImdbId = "http://www.thetvdb.com/api/GetSeriesByRemoteID.php?imdbid={0}&language={1}"; public async Task> GetSearchResults(SeriesInfo searchInfo, CancellationToken cancellationToken) { @@ -219,9 +219,12 @@ namespace MediaBrowser.Providers.TV throw new ArgumentNullException("seriesId"); } - var url = string.Equals(idType, "tvdb", StringComparison.OrdinalIgnoreCase) ? - string.Format(SeriesGetZip, TVUtils.TvdbApiKey, seriesId, preferredMetadataLanguage) : - string.Format(SeriesGetZipByImdbId, TVUtils.TvdbApiKey, seriesId, preferredMetadataLanguage); + if (!string.Equals(idType, "tvdb", StringComparison.OrdinalIgnoreCase)) + { + seriesId = await GetSeriesByRemoteId(seriesId, idType, preferredMetadataLanguage, cancellationToken).ConfigureAwait(false); + } + + var url = string.Format(SeriesGetZip, TVUtils.TvdbApiKey, seriesId, preferredMetadataLanguage); using (var zipStream = await _httpClient.Get(new HttpRequestOptions { @@ -262,6 +265,39 @@ namespace MediaBrowser.Providers.TV await ExtractEpisodes(seriesDataPath, downloadLangaugeXmlFile, lastTvDbUpdateTime).ConfigureAwait(false); } + private async Task GetSeriesByRemoteId(string id, string idType, string language, CancellationToken cancellationToken) + { + var url = string.Format(GetSeriesByImdbId, id, language); + + using (var result = await _httpClient.Get(new HttpRequestOptions + { + Url = url, + ResourcePool = TvDbResourcePool, + CancellationToken = cancellationToken + + }).ConfigureAwait(false)) + { + var doc = new XmlDocument(); + doc.Load(result); + + if (doc.HasChildNodes) + { + var node = doc.SelectSingleNode("//Series/seriesid"); + + if (node != null) + { + var idResult = node.InnerText; + + _logger.Info("Tvdb GetSeriesByRemoteId produced id of {0}", idResult ?? string.Empty); + + return idResult; + } + } + } + + return null; + } + public TvdbOptions GetTvDbOptions() { return _config.GetConfiguration("tvdb");