From ad7af6355db70793b7302be8202962b4ab300076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Miguel=20Alm=C3=A1nzar?= Date: Thu, 8 May 2014 23:24:58 -0400 Subject: [PATCH] fix episodes subtitles --- .../Subtitles/OpenSubtitleDownloader.cs | 37 ++++++++------ .../SubtitleTypes/SubtitleSearchParameters.cs | 50 +------------------ 2 files changed, 24 insertions(+), 63 deletions(-) diff --git a/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs b/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs index 7b40b5673a..a8e9ff4a85 100644 --- a/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs +++ b/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs @@ -166,14 +166,7 @@ namespace MediaBrowser.Providers.Subtitles public async Task> SearchSubtitles(SubtitleSearchRequest request, CancellationToken cancellationToken) { var imdbIdText = request.GetProviderId(MetadataProviders.Imdb); - long imdbId; - - if (string.IsNullOrWhiteSpace(imdbIdText) || - !long.TryParse(imdbIdText.TrimStart('t'), NumberStyles.Any, _usCulture, out imdbId)) - { - _logger.Debug("Imdb id missing"); - return new List(); - } + long imdbId = 0; switch (request.ContentType) { @@ -190,6 +183,11 @@ namespace MediaBrowser.Providers.Subtitles _logger.Debug("Movie name missing"); return new List(); } + if (string.IsNullOrWhiteSpace(imdbIdText) || !long.TryParse(imdbIdText.TrimStart('t'), NumberStyles.Any, _usCulture, out imdbId)) + { + _logger.Debug("Imdb id missing"); + return new List(); + } break; } @@ -208,16 +206,25 @@ namespace MediaBrowser.Providers.Subtitles var hash = Utilities.ComputeHash(request.MediaPath); var fileInfo = new FileInfo(request.MediaPath); var movieByteSize = fileInfo.Length; - + var searchImdbId = request.ContentType == SubtitleMediaType.Movie ? imdbId.ToString(_usCulture) : ""; var subtitleSearchParameters = request.ContentType == SubtitleMediaType.Episode - ? new SubtitleSearchParameters(subLanguageId, request.SeriesName, request.ParentIndexNumber.Value.ToString(_usCulture), request.IndexNumber.Value.ToString(_usCulture)) - : new SubtitleSearchParameters(subLanguageId, request.Name); - + ? new List { + new SubtitleSearchParameters(subLanguageId, + query: request.SeriesName, + season: request.ParentIndexNumber.Value.ToString(_usCulture), + episode: request.IndexNumber.Value.ToString(_usCulture)) + } + : new List { + new SubtitleSearchParameters(subLanguageId, imdbid: searchImdbId), + new SubtitleSearchParameters(subLanguageId, query: request.Name, imdbid: searchImdbId) + }; var parms = new List { - new SubtitleSearchParameters(subLanguageId, hash, movieByteSize), - subtitleSearchParameters + new SubtitleSearchParameters( subLanguageId, + movieHash: hash, + movieByteSize: movieByteSize, + imdbid: searchImdbId ), }; - + parms.AddRange(subtitleSearchParameters); var result = OpenSubtitles.SearchSubtitles(parms.ToArray()); if (!(result is MethodResponseSubtitleSearch)) { diff --git a/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchParameters.cs b/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchParameters.cs index f2e70ef813..46af6215ba 100644 --- a/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchParameters.cs +++ b/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchParameters.cs @@ -25,63 +25,17 @@ namespace OpenSubtitlesHandler /// public struct SubtitleSearchParameters { - /// - /// Paramaters for subtitle search call - /// - /// List of language ISO639-3 language codes to search for, divided by ',' (e.g. 'cze,eng,slo') - /// Video file hash as calculated by one of the implementation functions as seen on http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes - /// Size of video file in bytes - public SubtitleSearchParameters(string subLanguageId, string movieHash, long movieByteSize) + public SubtitleSearchParameters(string subLanguageId, string query = "", string season = "", string episode = "", string movieHash = "", long movieByteSize = 0, string imdbid = "") { this.subLanguageId = subLanguageId; this.movieHash = movieHash; this.movieByteSize = movieByteSize; - this.imdbid = ""; - this._episode = ""; - this._season = ""; - this._query = ""; - } - - public SubtitleSearchParameters(string subLanguageId, string query) - { - this.subLanguageId = subLanguageId; - this.movieHash = ""; - this.movieByteSize = 0; - this.imdbid = ""; - this._episode = ""; - this._season = ""; - this._query = query; - } - - public SubtitleSearchParameters(string subLanguageId, string query, string season, string episode) - { - this.subLanguageId = subLanguageId; - this.movieHash = ""; - this.movieByteSize = 0; - this.imdbid = ""; + this.imdbid = imdbid; this._episode = episode; this._season = season; this._query = query; } - /// - /// Paramaters for subtitle search call - /// - /// List of language ISO639-3 language codes to search for, divided by ',' (e.g. 'cze,eng,slo') - /// Video file hash as calculated by one of the implementation functions as seen on http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes - /// Size of video file in bytes - /// IMDb ID of movie this video is part of, belongs to. - public SubtitleSearchParameters(string subLanguageId, string movieHash, long movieByteSize, string imdbid) - { - this.subLanguageId = subLanguageId; - this.movieHash = movieHash; - this.movieByteSize = movieByteSize; - this.imdbid = imdbid; - this._episode = ""; - this._season = ""; - this._query = ""; - } - private string subLanguageId; private string movieHash; private long movieByteSize;