From 67c4c9381f3c56f44d7ecadb3b95f72929b8af6e Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 11 Jun 2015 17:22:44 -0400 Subject: [PATCH] 3.0.5641.0 --- .../Subtitles/ISubtitleProvider.cs | 8 +++++ .../Subtitles/OpenSubtitleDownloader.cs | 36 +++++++++++++++---- .../TV/TvdbSeriesProvider.cs | 26 +++++++------- .../Connect/ConnectEntryPoint.cs | 9 +++-- SharedVersion.cs | 4 +-- 5 files changed, 59 insertions(+), 24 deletions(-) diff --git a/MediaBrowser.Controller/Subtitles/ISubtitleProvider.cs b/MediaBrowser.Controller/Subtitles/ISubtitleProvider.cs index dceea0cc6..5cb106fec 100644 --- a/MediaBrowser.Controller/Subtitles/ISubtitleProvider.cs +++ b/MediaBrowser.Controller/Subtitles/ISubtitleProvider.cs @@ -1,4 +1,5 @@ using MediaBrowser.Controller.Providers; +using MediaBrowser.Model.Dto; using MediaBrowser.Model.Providers; using System.Collections.Generic; using System.Threading; @@ -35,5 +36,12 @@ namespace MediaBrowser.Controller.Subtitles /// The cancellation token. /// Task{SubtitleResponse}. Task GetSubtitles(string id, CancellationToken cancellationToken); + + /// + /// Gets the supported languages. + /// + /// The cancellation token. + /// Task<IEnumerable<NameIdPair>>. + Task> GetSupportedLanguages(CancellationToken cancellationToken); } } diff --git a/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs b/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs index 289c5661f..54db0d5fa 100644 --- a/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs +++ b/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs @@ -5,10 +5,11 @@ using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Security; using MediaBrowser.Controller.Subtitles; -using MediaBrowser.Model.Configuration; +using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Providers; +using MediaBrowser.Model.Serialization; using OpenSubtitlesHandler; using System; using System.Collections.Generic; @@ -38,17 +39,23 @@ namespace MediaBrowser.Providers.Subtitles // And the user may restart the server private const int MaxDownloadsPerDay = 150; - public OpenSubtitleDownloader(ILogManager logManager, IHttpClient httpClient, IServerConfigurationManager config, IEncryptionManager encryption) + private readonly IJsonSerializer _json; + + public OpenSubtitleDownloader(ILogManager logManager, IHttpClient httpClient, IServerConfigurationManager config, IEncryptionManager encryption, IJsonSerializer json) { _logger = logManager.GetLogger(GetType().Name); _httpClient = httpClient; _config = config; _encryption = encryption; + _json = json; _config.NamedConfigurationUpdating += _config_NamedConfigurationUpdating; // Reset the count every 24 hours _dailyTimer = new Timer(state => _dailyDownloadCount = 0, null, TimeSpan.FromHours(24), TimeSpan.FromHours(24)); + + Utilities.HttpClient = httpClient; + OpenSubtitles.SetUserAgent("mediabrowser.tv"); } private const string PasswordHashPrefix = "h:"; @@ -195,6 +202,26 @@ namespace MediaBrowser.Providers.Subtitles _lastLogin = DateTime.UtcNow; } + public async Task> GetSupportedLanguages(CancellationToken cancellationToken) + { + await Login(cancellationToken).ConfigureAwait(false); + + var result = OpenSubtitles.GetSubLanguages("en"); + if (!(result is MethodResponseGetSubLanguages)) + { + _logger.Error("Invalid response type"); + return new List(); + } + + var results = ((MethodResponseGetSubLanguages)result).Languages; + + return results.Select(i => new NameIdPair + { + Name = i.LanguageName, + Id = i.SubLanguageID + }); + } + public async Task> Search(SubtitleSearchRequest request, CancellationToken cancellationToken) { var imdbIdText = request.GetProviderId(MetadataProviders.Imdb); @@ -229,9 +256,6 @@ namespace MediaBrowser.Providers.Subtitles return new List(); } - Utilities.HttpClient = _httpClient; - OpenSubtitles.SetUserAgent("mediabrowser.tv"); - await Login(cancellationToken).ConfigureAwait(false); var subLanguageId = request.Language; @@ -260,7 +284,7 @@ namespace MediaBrowser.Providers.Subtitles var result = await OpenSubtitles.SearchSubtitlesAsync(parms.ToArray(), cancellationToken).ConfigureAwait(false); if (!(result is MethodResponseSubtitleSearch)) { - _logger.Debug("Invalid response type"); + _logger.Error("Invalid response type"); return new List(); } diff --git a/MediaBrowser.Providers/TV/TvdbSeriesProvider.cs b/MediaBrowser.Providers/TV/TvdbSeriesProvider.cs index 60e484a36..8bdd914df 100644 --- a/MediaBrowser.Providers/TV/TvdbSeriesProvider.cs +++ b/MediaBrowser.Providers/TV/TvdbSeriesProvider.cs @@ -398,21 +398,21 @@ namespace MediaBrowser.Providers.TV } } - if (titles.Any(t => string.Equals(t, comparableName, StringComparison.OrdinalIgnoreCase))) - { - var id = node.SelectSingleNode("./seriesid") ?? - node.SelectSingleNode("./id"); - - if (id != null) - { - searchResult.Name = titles.FirstOrDefault(); - searchResult.SetProviderId(MetadataProviders.Tvdb, id.InnerText); - searchResults.Add(searchResult); - } - } - foreach (var title in titles) { + if (string.Equals(title, comparableName, StringComparison.OrdinalIgnoreCase)) + { + var id = node.SelectSingleNode("./seriesid") ?? + node.SelectSingleNode("./id"); + + if (id != null) + { + searchResult.Name = title; + searchResult.SetProviderId(MetadataProviders.Tvdb, id.InnerText); + searchResults.Add(searchResult); + } + break; + } _logger.Info("TVDb Provider - " + title + " did not match " + comparableName); } } diff --git a/MediaBrowser.Server.Implementations/Connect/ConnectEntryPoint.cs b/MediaBrowser.Server.Implementations/Connect/ConnectEntryPoint.cs index 770eaa41f..973519a77 100644 --- a/MediaBrowser.Server.Implementations/Connect/ConnectEntryPoint.cs +++ b/MediaBrowser.Server.Implementations/Connect/ConnectEntryPoint.cs @@ -1,4 +1,4 @@ -using System.Linq; +using MediaBrowser.Common; using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Net; using MediaBrowser.Controller.Connect; @@ -22,14 +22,16 @@ namespace MediaBrowser.Server.Implementations.Connect private readonly IConnectManager _connectManager; private readonly INetworkManager _networkManager; + private readonly IApplicationHost _appHost; - public ConnectEntryPoint(IHttpClient httpClient, IApplicationPaths appPaths, ILogger logger, INetworkManager networkManager, IConnectManager connectManager) + public ConnectEntryPoint(IHttpClient httpClient, IApplicationPaths appPaths, ILogger logger, INetworkManager networkManager, IConnectManager connectManager, IApplicationHost appHost) { _httpClient = httpClient; _appPaths = appPaths; _logger = logger; _networkManager = networkManager; _connectManager = connectManager; + _appHost = appHost; } public void Run() @@ -49,7 +51,8 @@ namespace MediaBrowser.Server.Implementations.Connect { using (var stream = await _httpClient.Get(new HttpRequestOptions { - Url = ipLookupUrl + Url = ipLookupUrl, + UserAgent = "Emby Server/" + _appHost.ApplicationVersion }).ConfigureAwait(false)) { diff --git a/SharedVersion.cs b/SharedVersion.cs index c576e56f1..c81991d9a 100644 --- a/SharedVersion.cs +++ b/SharedVersion.cs @@ -1,4 +1,4 @@ using System.Reflection; -[assembly: AssemblyVersion("3.0.*")] -//[assembly: AssemblyVersion("3.0.5621.4")] +//[assembly: AssemblyVersion("3.0.*")] +[assembly: AssemblyVersion("3.0.5641.0")]