update opensubtitles portable targeting

This commit is contained in:
Luke Pulverenti 2016-10-30 02:36:38 -04:00
parent b5673f4e16
commit 3c305512c0
5 changed files with 42 additions and 17294 deletions

View File

@ -9,14 +9,12 @@
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OpenSubtitlesHandler</RootNamespace> <RootNamespace>OpenSubtitlesHandler</RootNamespace>
<AssemblyName>OpenSubtitlesHandler</AssemblyName> <AssemblyName>OpenSubtitlesHandler</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir> <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkProfile> <TargetFrameworkProfile>Profile7</TargetFrameworkProfile>
</TargetFrameworkProfile> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion> <MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>

View File

@ -24,6 +24,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Model.Cryptography; using MediaBrowser.Model.Cryptography;
using MediaBrowser.Model.TextEncoding;
namespace OpenSubtitlesHandler namespace OpenSubtitlesHandler
{ {
@ -33,6 +34,9 @@ namespace OpenSubtitlesHandler
public sealed class Utilities public sealed class Utilities
{ {
public static ICryptographyProvider CryptographyProvider { get; set; } public static ICryptographyProvider CryptographyProvider { get; set; }
public static IHttpClient HttpClient { get; set; }
public static IEncoding EncodingHelper { get; set; }
private const string XML_RPC_SERVER = "https://api.opensubtitles.org/xml-rpc"; private const string XML_RPC_SERVER = "https://api.opensubtitles.org/xml-rpc";
/// <summary> /// <summary>
@ -105,10 +109,8 @@ namespace OpenSubtitlesHandler
/// <summary> /// <summary>
/// Handle server response stream and decode it as given encoding string. /// Handle server response stream and decode it as given encoding string.
/// </summary> /// </summary>
/// <param name="responseStream">The response stream. Expects a stream that doesn't support seek.</param>
/// <param name="encoding">The encoding that should be used to decode buffer</param>
/// <returns>The string of the stream after decode using given encoding</returns> /// <returns>The string of the stream after decode using given encoding</returns>
public static string GetStreamString(Stream responseStream, Encoding encoding) public static string GetStreamString(Stream responseStream)
{ {
using (responseStream) using (responseStream)
{ {
@ -121,20 +123,15 @@ namespace OpenSubtitlesHandler
break; break;
data.Add((byte)r); data.Add((byte)r);
} }
return encoding.GetString(data.ToArray()); var bytes = data.ToArray();
return EncodingHelper.GetASCIIString(bytes, 0, bytes.Length);
} }
} }
/// <summary>
/// Handle server response stream and decode it as ASCII encoding string.
/// </summary>
/// <param name="responseStream">The response stream. Expects a stream that doesn't support seek.</param>
/// <returns>The string of the stream after decode using ASCII encoding</returns>
public static string GetStreamString(Stream responseStream)
{
return GetStreamString(responseStream, Encoding.ASCII);
}
public static IHttpClient HttpClient { get; set; } public static byte[] GetASCIIBytes(string text)
{
return EncodingHelper.GetASCIIBytes(text);
}
/// <summary> /// <summary>
/// Send a request to the server /// Send a request to the server

View File

@ -22,6 +22,8 @@ using System.Text;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Xml; using System.Xml;
using OpenSubtitlesHandler;
namespace XmlRpcHandler namespace XmlRpcHandler
{ {
/// <summary> /// <summary>
@ -103,26 +105,33 @@ namespace XmlRpcHandler
XmlReaderSettings sett = new XmlReaderSettings(); XmlReaderSettings sett = new XmlReaderSettings();
sett.DtdProcessing = DtdProcessing.Ignore; sett.DtdProcessing = DtdProcessing.Ignore;
sett.IgnoreWhitespace = true; sett.IgnoreWhitespace = true;
MemoryStream str = new MemoryStream(Encoding.ASCII.GetBytes(xmlResponse)); MemoryStream str;
if (xmlResponse.Contains(@"encoding=""utf-8""")) if (xmlResponse.Contains(@"encoding=""utf-8"""))
{ {
str = new MemoryStream(Encoding.UTF8.GetBytes(xmlResponse)); str = new MemoryStream(Encoding.UTF8.GetBytes(xmlResponse));
} }
using (XmlReader XMLread = XmlReader.Create(str, sett)) else
{ {
XmlRpcMethodCall call = new XmlRpcMethodCall("methodResponse"); str = new MemoryStream(Utilities.GetASCIIBytes(xmlResponse));
// Read parameters }
while (XMLread.Read()) using (str)
{
using (XmlReader XMLread = XmlReader.Create(str, sett))
{ {
if (XMLread.Name == "param" && XMLread.IsStartElement()) XmlRpcMethodCall call = new XmlRpcMethodCall("methodResponse");
// Read parameters
while (XMLread.Read())
{ {
IXmlRpcValue val = ReadValue(XMLread); if (XMLread.Name == "param" && XMLread.IsStartElement())
if (val != null) {
call.Parameters.Add(val); IXmlRpcValue val = ReadValue(XMLread);
if (val != null)
call.Parameters.Add(val);
}
} }
methods.Add(call);
return methods.ToArray();
} }
methods.Add(call);
return methods.ToArray();
} }
} }

View File

@ -1,16 +1,7 @@
{ {
"supports": { "supports": {},
"net46.app": {}, "dependencies": {},
"uwp.10.0.app": {},
"dnxcore50.app": {}
},
"dependencies": {
"Microsoft.NETCore": "5.0.0",
"Microsoft.NETCore.Portable.Compatibility": "1.0.1"
},
"frameworks": { "frameworks": {
"dotnet": { ".NETPortable,Version=v4.5,Profile=Profile7": {}
"imports": "portable-net452+win81"
}
} }
} }

File diff suppressed because it is too large Load Diff