mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-05-31 12:58:28 +01:00
added UniversalDetector.dll
This commit is contained in:
@@ -467,7 +467,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
{
|
||||
if (job.SubtitleStream.IsExternal && !job.SubtitleStream.IsTextSubtitleStream)
|
||||
{
|
||||
arg += " -i " + job.SubtitleStream.Path;
|
||||
arg += " -i \"" + job.SubtitleStream.Path + "\"";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,9 @@
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="UniversalDetector">
|
||||
<HintPath>..\ThirdParty\UniversalDetector\UniversalDetector.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\SharedVersion.cs">
|
||||
|
||||
@@ -17,6 +17,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using UniversalDetector;
|
||||
|
||||
namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
{
|
||||
@@ -611,7 +612,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
@@ -699,6 +700,18 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
/// <returns>System.String.</returns>
|
||||
public string GetSubtitleFileCharacterSet(string path, string language)
|
||||
{
|
||||
var charset = DetectCharset(path);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(charset))
|
||||
{
|
||||
if (string.Equals(charset, "utf-8", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
//return null;
|
||||
}
|
||||
|
||||
//return charset;
|
||||
}
|
||||
|
||||
if (GetFileEncoding(path).Equals(Encoding.UTF8))
|
||||
{
|
||||
return string.Empty;
|
||||
@@ -743,6 +756,34 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
}
|
||||
}
|
||||
|
||||
private string DetectCharset(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var file = new FileStream(path, FileMode.Open))
|
||||
{
|
||||
var detector = new CharsetDetector();
|
||||
detector.Feed(file);
|
||||
detector.DataEnd();
|
||||
|
||||
var charset = detector.Charset;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(charset))
|
||||
{
|
||||
_logger.Info("UniversalDetector detected charset {0} for {1}", charset, path);
|
||||
}
|
||||
|
||||
return charset;
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
_logger.ErrorException("Error attempting to determine subtitle charset from {0}", ex, path);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Encoding GetFileEncoding(string srcFile)
|
||||
{
|
||||
// *** Detect byte order mark if any - otherwise assume default
|
||||
|
||||
Reference in New Issue
Block a user