mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-07-15 10:43:30 +01:00
make open subtitle project portable
This commit is contained in:
@@ -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) { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,11 @@
|
||||
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
||||
<TargetFrameworkProfile />
|
||||
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
|
||||
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -36,15 +40,6 @@
|
||||
<OutputPath>bin\Release Mono</OutputPath>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Console\OSHConsole.cs" />
|
||||
<Compile Include="Interfaces\IMethodResponse.cs" />
|
||||
@@ -119,7 +114,10 @@
|
||||
<ItemGroup>
|
||||
<Content Include="XML-RPC\Docs\XML-RPC.txt" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
<None Include="project.json" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
|
||||
@@ -20,10 +20,10 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Model.Cryptography;
|
||||
|
||||
namespace OpenSubtitlesHandler
|
||||
{
|
||||
@@ -32,50 +32,33 @@ namespace OpenSubtitlesHandler
|
||||
/// </summary>
|
||||
public sealed class Utilities
|
||||
{
|
||||
public static ICryptographyProvider CryptographyProvider { get; set; }
|
||||
private const string XML_RPC_SERVER = "https://api.opensubtitles.org/xml-rpc";
|
||||
|
||||
/// <summary>
|
||||
/// Compute movie hash
|
||||
/// </summary>
|
||||
/// <param name="fileName">The complete media file path</param>
|
||||
/// <returns>The hash as Hexadecimal string</returns>
|
||||
public static string ComputeHash(string fileName)
|
||||
public static string ComputeHash(Stream stream)
|
||||
{
|
||||
byte[] hash = MovieHasher.ComputeMovieHash(File.OpenRead(fileName));
|
||||
byte[] hash = MovieHasher.ComputeMovieHash(stream);
|
||||
return MovieHasher.ToHexadecimal(hash);
|
||||
}
|
||||
/// <summary>
|
||||
/// Compute md5 for a file
|
||||
/// </summary>
|
||||
/// <param name="filename">The complete file path</param>
|
||||
/// <returns>MD5 of the file</returns>
|
||||
public static string ComputeMd5(string filename)
|
||||
{
|
||||
var md5 = MD5.Create();
|
||||
var sb = new StringBuilder();
|
||||
Stream str = new FileStream(filename, FileMode.Open, FileAccess.Read);
|
||||
|
||||
foreach (var b in md5.ComputeHash(str))
|
||||
sb.Append(b.ToString("x2").ToLower());
|
||||
str.Close();
|
||||
return sb.ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// Decompress data using GZip
|
||||
/// </summary>
|
||||
/// <param name="dataToDecompress">The stream that hold the data</param>
|
||||
/// <returns>Bytes array of decompressed data</returns>
|
||||
public static byte[] Decompress(Stream dataToDecompress)
|
||||
{
|
||||
MemoryStream target = new MemoryStream();
|
||||
|
||||
using (System.IO.Compression.GZipStream decompressionStream = new System.IO.Compression.GZipStream(dataToDecompress,
|
||||
System.IO.Compression.CompressionMode.Decompress))
|
||||
using (MemoryStream target = new MemoryStream())
|
||||
{
|
||||
decompressionStream.CopyTo(target);
|
||||
using (System.IO.Compression.GZipStream decompressionStream = new System.IO.Compression.GZipStream(dataToDecompress, System.IO.Compression.CompressionMode.Decompress))
|
||||
{
|
||||
decompressionStream.CopyTo(target);
|
||||
}
|
||||
return target.ToArray();
|
||||
}
|
||||
return target.GetBuffer();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -127,17 +110,19 @@ namespace OpenSubtitlesHandler
|
||||
/// <returns>The string of the stream after decode using given encoding</returns>
|
||||
public static string GetStreamString(Stream responseStream, Encoding encoding)
|
||||
{
|
||||
// Handle response, should be XML text.
|
||||
List<byte> data = new List<byte>();
|
||||
while (true)
|
||||
using (responseStream)
|
||||
{
|
||||
int r = responseStream.ReadByte();
|
||||
if (r < 0)
|
||||
break;
|
||||
data.Add((byte)r);
|
||||
// Handle response, should be XML text.
|
||||
List<byte> data = new List<byte>();
|
||||
while (true)
|
||||
{
|
||||
int r = responseStream.ReadByte();
|
||||
if (r < 0)
|
||||
break;
|
||||
data.Add((byte)r);
|
||||
}
|
||||
return encoding.GetString(data.ToArray());
|
||||
}
|
||||
responseStream.Close();
|
||||
return encoding.GetString(data.ToArray());
|
||||
}
|
||||
/// <summary>
|
||||
/// Handle server response stream and decode it as ASCII encoding string.
|
||||
|
||||
@@ -232,33 +232,42 @@ namespace XmlRpcHandler
|
||||
XMLwrt.WriteEndElement();//value
|
||||
}
|
||||
private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
|
||||
|
||||
private static IXmlRpcValue ReadValue(XmlReader xmlReader)
|
||||
|
||||
private static string ReadString(XmlReader reader)
|
||||
{
|
||||
while (xmlReader.Read())
|
||||
if (reader.NodeType == XmlNodeType.Element)
|
||||
{
|
||||
return reader.ReadElementContentAsString();
|
||||
}
|
||||
return reader.ReadContentAsString();
|
||||
}
|
||||
|
||||
private static IXmlRpcValue ReadValue(XmlReader xmlReader, bool skipRead = false)
|
||||
{
|
||||
while (skipRead || xmlReader.Read())
|
||||
{
|
||||
if (xmlReader.Name == "value" && xmlReader.IsStartElement())
|
||||
{
|
||||
xmlReader.Read();
|
||||
if (xmlReader.Name == "string" && xmlReader.IsStartElement())
|
||||
{
|
||||
return new XmlRpcValueBasic(xmlReader.ReadString(), XmlRpcBasicValueType.String);
|
||||
return new XmlRpcValueBasic(ReadString(xmlReader), XmlRpcBasicValueType.String);
|
||||
}
|
||||
else if (xmlReader.Name == "int" && xmlReader.IsStartElement())
|
||||
{
|
||||
return new XmlRpcValueBasic(int.Parse(xmlReader.ReadString(), UsCulture), XmlRpcBasicValueType.Int);
|
||||
return new XmlRpcValueBasic(int.Parse(ReadString(xmlReader), UsCulture), XmlRpcBasicValueType.Int);
|
||||
}
|
||||
else if (xmlReader.Name == "boolean" && xmlReader.IsStartElement())
|
||||
{
|
||||
return new XmlRpcValueBasic(xmlReader.ReadString() == "1", XmlRpcBasicValueType.Boolean);
|
||||
return new XmlRpcValueBasic(ReadString(xmlReader) == "1", XmlRpcBasicValueType.Boolean);
|
||||
}
|
||||
else if (xmlReader.Name == "double" && xmlReader.IsStartElement())
|
||||
{
|
||||
return new XmlRpcValueBasic(double.Parse(xmlReader.ReadString(), UsCulture), XmlRpcBasicValueType.Double);
|
||||
return new XmlRpcValueBasic(double.Parse(ReadString(xmlReader), UsCulture), XmlRpcBasicValueType.Double);
|
||||
}
|
||||
else if (xmlReader.Name == "dateTime.iso8601" && xmlReader.IsStartElement())
|
||||
{
|
||||
string date = xmlReader.ReadString();
|
||||
string date = ReadString(xmlReader);
|
||||
int year = int.Parse(date.Substring(0, 4), UsCulture);
|
||||
int month = int.Parse(date.Substring(4, 2), UsCulture);
|
||||
int day = int.Parse(date.Substring(6, 2), UsCulture);
|
||||
@@ -270,7 +279,7 @@ namespace XmlRpcHandler
|
||||
}
|
||||
else if (xmlReader.Name == "base64" && xmlReader.IsStartElement())
|
||||
{
|
||||
return new XmlRpcValueBasic(BitConverter.ToInt64(Convert.FromBase64String(xmlReader.ReadString()), 0)
|
||||
return new XmlRpcValueBasic(BitConverter.ToInt64(Convert.FromBase64String(ReadString(xmlReader)), 0)
|
||||
, XmlRpcBasicValueType.Double);
|
||||
}
|
||||
else if (xmlReader.Name == "struct" && xmlReader.IsStartElement())
|
||||
@@ -283,9 +292,9 @@ namespace XmlRpcHandler
|
||||
{
|
||||
XmlRpcStructMember member = new XmlRpcStructMember("", null);
|
||||
xmlReader.Read();// read name
|
||||
member.Name = xmlReader.ReadString();
|
||||
member.Name = ReadString(xmlReader);
|
||||
|
||||
IXmlRpcValue val = ReadValue(xmlReader);
|
||||
IXmlRpcValue val = ReadValue(xmlReader, true);
|
||||
if (val != null)
|
||||
{
|
||||
member.Data = val;
|
||||
@@ -320,6 +329,11 @@ namespace XmlRpcHandler
|
||||
}
|
||||
}
|
||||
else break;
|
||||
|
||||
if (skipRead)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
15
OpenSubtitlesHandler/project.json
Normal file
15
OpenSubtitlesHandler/project.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"supports": {
|
||||
"net46.app": {},
|
||||
"dnxcore50.app": {}
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore": "5.0.0",
|
||||
"Microsoft.NETCore.Portable.Compatibility": "1.0.0"
|
||||
},
|
||||
"frameworks": {
|
||||
"dotnet": {
|
||||
"imports": "portable-net452"
|
||||
}
|
||||
}
|
||||
}
|
||||
9048
OpenSubtitlesHandler/project.lock.json
Normal file
9048
OpenSubtitlesHandler/project.lock.json
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user