diff --git a/Emby.Server.sln b/Emby.Server.sln index 7376a6a28a..a12b5c3ecb 100644 --- a/Emby.Server.sln +++ b/Emby.Server.sln @@ -32,6 +32,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.Common.Impleme EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.Providers", "MediaBrowser.Providers\MediaBrowser.Providers.csproj", "{442B5058-DCAF-4263-BB6A-F21E31120A1B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSubtitlesHandler", "OpenSubtitlesHandler\OpenSubtitlesHandler.csproj", "{4A4402D4-E910-443B-B8FC-2C18286A2CA0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -105,6 +107,12 @@ Global {442B5058-DCAF-4263-BB6A-F21E31120A1B}.Release Mono|Any CPU.Build.0 = Release Mono|Any CPU {442B5058-DCAF-4263-BB6A-F21E31120A1B}.Release|Any CPU.ActiveCfg = Release|Any CPU {442B5058-DCAF-4263-BB6A-F21E31120A1B}.Release|Any CPU.Build.0 = Release|Any CPU + {4A4402D4-E910-443B-B8FC-2C18286A2CA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4A4402D4-E910-443B-B8FC-2C18286A2CA0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4A4402D4-E910-443B-B8FC-2C18286A2CA0}.Release Mono|Any CPU.ActiveCfg = Release Mono|Any CPU + {4A4402D4-E910-443B-B8FC-2C18286A2CA0}.Release Mono|Any CPU.Build.0 = Release Mono|Any CPU + {4A4402D4-E910-443B-B8FC-2C18286A2CA0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4A4402D4-E910-443B-B8FC-2C18286A2CA0}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -121,5 +129,6 @@ Global {88AE38DF-19D7-406F-A6A9-09527719A21E} = {8ADD772F-F0A4-4A53-9B2F-AF4A4C585839} {C4D2573A-3FD3-441F-81AF-174AC4CD4E1D} = {8ADD772F-F0A4-4A53-9B2F-AF4A4C585839} {442B5058-DCAF-4263-BB6A-F21E31120A1B} = {8ADD772F-F0A4-4A53-9B2F-AF4A4C585839} + {4A4402D4-E910-443B-B8FC-2C18286A2CA0} = {8ADD772F-F0A4-4A53-9B2F-AF4A4C585839} EndGlobalSection EndGlobal diff --git a/MediaBrowser.Common.Implementations/Cryptography/CryptographyProvider.cs b/MediaBrowser.Common.Implementations/Cryptography/CryptographyProvider.cs index 81cbaa3aae..67dbd76d24 100644 --- a/MediaBrowser.Common.Implementations/Cryptography/CryptographyProvider.cs +++ b/MediaBrowser.Common.Implementations/Cryptography/CryptographyProvider.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Security.Cryptography; using System.Text; using MediaBrowser.Model.Cryptography; @@ -8,10 +9,21 @@ namespace MediaBrowser.Common.Implementations.Cryptography public class CryptographyProvider : ICryptographyProvider { public Guid GetMD5(string str) + { + return new Guid(GetMD5Bytes(str)); + } + public byte[] GetMD5Bytes(string str) { using (var provider = MD5.Create()) { - return new Guid(provider.ComputeHash(Encoding.Unicode.GetBytes(str))); + return provider.ComputeHash(Encoding.Unicode.GetBytes(str)); + } + } + public byte[] GetMD5Bytes(Stream str) + { + using (var provider = MD5.Create()) + { + return provider.ComputeHash(str); } } } diff --git a/MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs b/MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs index a58da3dc8b..d8f36de9a1 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs @@ -218,16 +218,17 @@ namespace MediaBrowser.MediaEncoding.Subtitles }); } - private string NormalizeLanguage(string language) - { - // Problem with Greek subtitle download #1349 - if (string.Equals (language, "gre", StringComparison.OrdinalIgnoreCase)) { - - return "ell"; - } + private string NormalizeLanguage(string language) + { + // Problem with Greek subtitle download #1349 + if (string.Equals(language, "gre", StringComparison.OrdinalIgnoreCase)) + { - return language; - } + return "ell"; + } + + return language; + } public async Task> Search(SubtitleSearchRequest request, CancellationToken cancellationToken) { @@ -265,14 +266,19 @@ namespace MediaBrowser.MediaEncoding.Subtitles await Login(cancellationToken).ConfigureAwait(false); - var subLanguageId = NormalizeLanguage(request.Language); - var hash = Utilities.ComputeHash(request.MediaPath); + var subLanguageId = NormalizeLanguage(request.Language); + string hash; + + using (var fileStream = File.OpenRead(request.MediaPath)) + { + hash = Utilities.ComputeHash(fileStream); + } var fileInfo = new FileInfo(request.MediaPath); var movieByteSize = fileInfo.Length; var searchImdbId = request.ContentType == VideoContentType.Movie ? imdbId.ToString(_usCulture) : ""; var subtitleSearchParameters = request.ContentType == VideoContentType.Episode ? new List { - new SubtitleSearchParameters(subLanguageId, + new SubtitleSearchParameters(subLanguageId, query: request.SeriesName, season: request.ParentIndexNumber.Value.ToString(_usCulture), episode: request.IndexNumber.Value.ToString(_usCulture)) @@ -282,9 +288,9 @@ namespace MediaBrowser.MediaEncoding.Subtitles new SubtitleSearchParameters(subLanguageId, query: request.Name, imdbid: searchImdbId) }; var parms = new List { - new SubtitleSearchParameters( subLanguageId, - movieHash: hash, - movieByteSize: movieByteSize, + new SubtitleSearchParameters( subLanguageId, + movieHash: hash, + movieByteSize: movieByteSize, imdbid: searchImdbId ), }; parms.AddRange(subtitleSearchParameters); diff --git a/MediaBrowser.Model/Cryptography/ICryptographyProvider.cs b/MediaBrowser.Model/Cryptography/ICryptographyProvider.cs index 5899f03d57..70f6798562 100644 --- a/MediaBrowser.Model/Cryptography/ICryptographyProvider.cs +++ b/MediaBrowser.Model/Cryptography/ICryptographyProvider.cs @@ -1,9 +1,12 @@ using System; +using System.IO; namespace MediaBrowser.Model.Cryptography { public interface ICryptographyProvider { Guid GetMD5(string str); + byte[] GetMD5Bytes(string str); + byte[] GetMD5Bytes(Stream str); } -} +} \ No newline at end of file diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index 23b6dd0976..8dbc904299 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -119,6 +119,7 @@ using MediaBrowser.Model.Social; using MediaBrowser.Model.Xml; using MediaBrowser.Server.Implementations.Reflection; using MediaBrowser.Server.Implementations.Xml; +using OpenSubtitlesHandler; namespace MediaBrowser.Server.Startup.Common { @@ -974,6 +975,7 @@ namespace MediaBrowser.Server.Startup.Common CollectionFolder.XmlSerializer = XmlSerializer; BaseStreamingService.AppHost = this; BaseStreamingService.HttpClient = HttpClient; + Utilities.CryptographyProvider = CryptographyProvider; } /// diff --git a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj index 245231ecaf..042366e887 100644 --- a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj +++ b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj @@ -137,6 +137,10 @@ {23499896-b135-4527-8574-c26e926ea99e} MediaBrowser.XbmcMetadata + + {4a4402d4-e910-443b-b8fc-2c18286a2ca0} + OpenSubtitlesHandler + diff --git a/OpenSubtitlesHandler/Interfaces/IMethodResponse.cs b/OpenSubtitlesHandler/Interfaces/IMethodResponse.cs index b8e24f12bd..9c05e357b9 100644 --- a/OpenSubtitlesHandler/Interfaces/IMethodResponse.cs +++ b/OpenSubtitlesHandler/Interfaces/IMethodResponse.cs @@ -37,17 +37,17 @@ namespace OpenSubtitlesHandler protected double seconds; protected string status; - protected virtual void LoadAttributes() + protected void LoadAttributes() { - foreach (Attribute attr in Attribute.GetCustomAttributes(this.GetType())) - { - if (attr.GetType() == typeof(MethodResponseDescription)) - { - this.name = ((MethodResponseDescription)attr).Name; - this.message = ((MethodResponseDescription)attr).Message; - break; - } - } + //foreach (Attribute attr in Attribute.GetCustomAttributes(this.GetType())) + //{ + // if (attr.GetType() == typeof(MethodResponseDescription)) + // { + // this.name = ((MethodResponseDescription)attr).Name; + // this.message = ((MethodResponseDescription)attr).Message; + // break; + // } + //} } [Description("The name of this response"), Category("MethodResponse")] @@ -59,4 +59,14 @@ namespace OpenSubtitlesHandler [Description("The status"), Category("MethodResponse")] public string Status { get { return status; } set { status = value; } } } + + public class DescriptionAttribute : Attribute + { + public DescriptionAttribute(string text) { } + } + + public class CategoryAttribute : Attribute + { + public CategoryAttribute(string text) { } + } } diff --git a/OpenSubtitlesHandler/OpenSubtitlesHandler.csproj b/OpenSubtitlesHandler/OpenSubtitlesHandler.csproj index 095c9236b4..59ac866e4f 100644 --- a/OpenSubtitlesHandler/OpenSubtitlesHandler.csproj +++ b/OpenSubtitlesHandler/OpenSubtitlesHandler.csproj @@ -12,7 +12,11 @@ v4.6 512 ..\ - + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + + + v5.0 + 14.0 true @@ -36,15 +40,6 @@ bin\Release Mono 4 - - - - - - - - - @@ -119,7 +114,10 @@ - + + + +