5 Commits

Author SHA1 Message Date
Meiam
b0427939fa 修复: 统一滚动测试版名称 2026-09-17 15:15:44 +08:00
Meiam
5176b552e2 发布: 更新滚动预发布版至 v1.0.17.1 2026-09-17 11:17:42 +08:00
Meiam
66a132ceb3 构建: 区分正式与预发布流程 2026-09-17 11:15:48 +08:00
Meiam
c40d83eb8d 修复: 统一迅雷字幕编码为 UTF-8 2026-09-17 10:45:22 +08:00
Meiam
f811632e8a 文档: 更新当前框架徽章 2026-09-17 10:45:22 +08:00
13 changed files with 364 additions and 54 deletions

View File

@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyVersion>1.0.17.0</AssemblyVersion>
<FileVersion>1.0.17.0</FileVersion>
<Version>1.0.17.0</Version>
<AssemblyVersion>1.0.17.1</AssemblyVersion>
<FileVersion>1.0.17.1</FileVersion>
<Version>1.0.17.1</Version>
</PropertyGroup>
<PropertyGroup>

View File

@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyVersion>1.0.17.0</AssemblyVersion>
<FileVersion>1.0.17.0</FileVersion>
<Version>1.0.17.0</Version>
<AssemblyVersion>1.0.17.1</AssemblyVersion>
<FileVersion>1.0.17.1</FileVersion>
<Version>1.0.17.1</Version>
</PropertyGroup>
<PropertyGroup>
@@ -27,6 +27,7 @@
<!-- 使用旧版宿主可解析的 SDK,避免插件要求 4.9.1.90 程序集。 -->
<PackageReference Include="MediaBrowser.Common" Version="4.8.10" />
<PackageReference Include="MediaBrowser.Server.Core" Version="4.8.10" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="8.0.0" />
</ItemGroup>

View File

@@ -286,14 +286,14 @@ namespace Emby.MeiamSub.Thunder
await response.Content.CopyToAsync(stream, 81920, cancellationToken);
var data = stream.ToArray();
stream.Dispose();
SubtitleContentValidator.Validate(data, format, response.ContentType);
var utf8Data = SubtitleContentValidator.ValidateAndConvertToUtf8(data, format, response.ContentType);
return new SubtitleResponse()
{
Language = downloadSub.Language,
IsForced = downloadSub.IsForced ?? false,
Format = format,
Stream = new MemoryStream(data, writable: false),
Stream = new MemoryStream(utf8Data, writable: false),
};
}
}

View File

@@ -3,9 +3,9 @@
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Version>1.0.17.0</Version>
<AssemblyVersion>1.0.17.0</AssemblyVersion>
<FileVersion>1.0.17.0</FileVersion>
<Version>1.0.17.1</Version>
<AssemblyVersion>1.0.17.1</AssemblyVersion>
<FileVersion>1.0.17.1</FileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">

View File

@@ -5,8 +5,8 @@
"name": "MeiamSub.Assrt",
"owner": "Meiam",
"targetAbi": "10.10.7.0",
"timestamp": "2026-09-16T08:13:02.0000000Z",
"version": "1.0.17.0",
"timestamp": "2026-09-17T03:17:33.0000000Z",
"version": "1.0.17.1",
"status": "Active",
"imagePath": "thumb.png"
}

View File

@@ -3,8 +3,8 @@
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Version>1.0.17.0</Version>
<AssemblyVersion>1.0.17.0</AssemblyVersion>
<Version>1.0.17.1</Version>
<AssemblyVersion>1.0.17.1</AssemblyVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
@@ -14,6 +14,7 @@
<ItemGroup>
<!-- 使用已验证的最低兼容基线,保持同一 DLL 可运行于 Jellyfin 10.10.7、10.11.11 和 12.1。 -->
<PackageReference Include="Jellyfin.Controller" Version="10.10.7" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="8.0.0" />
</ItemGroup>
<ItemGroup>

View File

@@ -283,8 +283,11 @@ namespace Jellyfin.MeiamSub.Thunder
var format = NormalizeFormat(downloadSub.Format)
?? throw new InvalidDataException($"Unsupported subtitle format: {downloadSub.Format}");
var data = await response.Content.ReadAsByteArrayAsync(cancellationToken);
SubtitleContentValidator.Validate(data, format, response.Content.Headers.ContentType?.MediaType);
var stream = new MemoryStream(data, writable: false);
var utf8Data = SubtitleContentValidator.ValidateAndConvertToUtf8(
data,
format,
response.Content.Headers.ContentType?.MediaType);
var stream = new MemoryStream(utf8Data, writable: false);
return new SubtitleResponse()
{

View File

@@ -5,8 +5,8 @@
"name": "MeiamSub.Thunder",
"owner": "Meiam",
"targetAbi": "10.10.7.0",
"timestamp": "2026-09-16T08:13:02.0000000Z",
"version": "1.0.17.0",
"timestamp": "2026-09-17T03:17:33.0000000Z",
"version": "1.0.17.1",
"status": "Active",
"imagePath": "thumb.png"
}

View File

@@ -4,7 +4,7 @@
<p align="left">
<a href="https://github.com/91270/MeiamSubtitles/releases/latest"><img src="https://img.shields.io/github/v/release/91270/MeiamSubtitles" alt="Release"></a>
<img src="https://img.shields.io/badge/.NET-Standard%202.1%20%7C%209.0-blueviolet.svg" alt=".NET Status">
<img src="https://img.shields.io/badge/.NET-Standard%202.1%20%7C%208.0-blueviolet.svg" alt=".NET Status">
<a href="#插件与兼容性"><img src="https://img.shields.io/badge/Platform-Linux%20%7C%20Windows%20%7C%20macOS-brightgreen.svg" alt="Platform"></a>
<a href="LICENSE"><img src="https://img.shields.io/badge/license-Apache%202.0-blue.svg" alt="License"></a>
<a href="https://www.592.la/"><img src="https://img.shields.io/badge/博客-Meiam's%20Home-brightgreen.svg" alt="博客"></a>
@@ -51,6 +51,15 @@
| Emby | 4.8.10.0 至 4.10.0.40 |
| Jellyfin | 10.10.7 至 12.1 |
## 版本渠道
- **正式版**:版本号末位为 `0`,例如 `1.0.18.0`。正式版会发布到 GitHub Releases,并同步到 Jellyfin 稳定插件仓库。
- **测试版(Preview)**:GitHub 只保留一个滚动更新的“测试版(滚动更新)”,固定使用 `preview` 标签和 `Emby_preview.zip`、`Jellyfin_preview.zip` 两个附件。GitHub 中仍标记为 Pre-release,以区别于稳定发布。
- 每次更新测试版时,插件内部版本末位继续递增,例如 `1.0.17.1`、`1.0.17.2`,用于识别用户实际安装的测试批次;旧测试包会被新包替换。
- 测试版不会写入稳定插件仓库,测试用户需要从 GitHub 的 `preview` Release 手动下载安装。
- 正式版版本号必须高于同一轮全部测试版。例如 `1.0.17.1`、`1.0.17.2` 验证完成后发布 `1.0.18.0`。
- 正式版发布后,滚动测试 Release 会转为草稿保留;开始下一轮测试时再更新并重新公开。
## 安装
### Jellyfin 存储库

View File

@@ -7,7 +7,27 @@ namespace MeiamSubtitles.Shared
{
internal static class SubtitleContentValidator
{
private static readonly Encoding StrictUtf8 = new UTF8Encoding(false, true);
private static readonly Encoding StrictUtf16Le = new UnicodeEncoding(false, true, true);
private static readonly Encoding StrictUtf16Be = new UnicodeEncoding(true, true, true);
static SubtitleContentValidator()
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
}
public static void Validate(byte[] data, string format, string mediaType)
{
DecodeAndValidate(data, format, mediaType);
}
public static byte[] ValidateAndConvertToUtf8(byte[] data, string format, string mediaType)
{
var text = DecodeAndValidate(data, format, mediaType);
return Encoding.UTF8.GetBytes(text);
}
private static string DecodeAndValidate(byte[] data, string format, string mediaType)
{
if (data == null || data.Length < 8)
{
@@ -38,7 +58,7 @@ namespace MeiamSubtitles.Shared
if (IsValidSubtitle(sample, format))
{
return;
return sample;
}
if (sample.StartsWith("[", StringComparison.Ordinal))
@@ -65,35 +85,52 @@ namespace MeiamSubtitles.Shared
private static IEnumerable<string> DecodeSamples(byte[] data)
{
var length = Math.Min(data.Length, 4096);
// Decode the complete subtitle because the selected text is returned to
// the host after validation and must not be truncated to a probe window.
var length = data.Length;
if (data.Length >= 2)
{
if (data[0] == 0xFF && data[1] == 0xFE)
{
yield return DecodeSample(data, length, Encoding.Unicode);
yield return DecodeSample(data, length, StrictUtf16Le);
yield break;
}
if (data[0] == 0xFE && data[1] == 0xFF)
{
yield return DecodeSample(data, length, Encoding.BigEndianUnicode);
yield return DecodeSample(data, length, StrictUtf16Be);
yield break;
}
}
if (data.Length >= 3 && data[0] == 0xEF && data[1] == 0xBB && data[2] == 0xBF)
{
yield return DecodeSample(data, length, Encoding.UTF8);
yield return DecodeSample(data, length, StrictUtf8);
yield break;
}
// Thunder may return UTF-16 subtitles without a BOM. Try the common
// single-byte/UTF-8 representation and both UTF-16 byte orders, then
// accept only a candidate that contains the expected subtitle syntax.
yield return DecodeSample(data, length, new UTF8Encoding(false, false));
yield return DecodeSample(data, length, Encoding.Unicode);
yield return DecodeSample(data, length, Encoding.BigEndianUnicode);
// Thunder may return UTF-16 or GB18030 subtitles without a BOM. Decode
// strictly so invalid UTF-8 cannot hide the actual legacy encoding.
foreach (var encoding in new[] { StrictUtf8, StrictUtf16Le, StrictUtf16Be, GetGb18030Encoding() })
{
string sample;
try
{
sample = DecodeSample(data, length, encoding);
}
catch (DecoderFallbackException)
{
continue;
}
yield return sample;
}
}
private static Encoding GetGb18030Encoding()
{
return Encoding.GetEncoding(54936, EncoderFallback.ExceptionFallback, DecoderFallback.ExceptionFallback);
}
private static string DecodeSample(byte[] data, int length, Encoding encoding)

View File

@@ -1,6 +1,10 @@
param (
[Parameter(Mandatory=$true)]
[string]$Version,
[Parameter(Mandatory=$false)]
[ValidateSet("Stable", "Preview")]
[string]$Channel = "Stable",
[Parameter(Mandatory=$false)]
[string]$JellyfinVersion,
@@ -12,18 +16,18 @@ param (
[string]$Notes,
[Parameter(Mandatory=$false)]
[switch]$PublishToGitHub
[switch]$PublishToGitHub,
[Parameter(Mandatory=$false)]
[switch]$ValidateOnly
)
$ErrorActionPreference = "Stop"
$SupportedEmbySdkVersion = "4.8.10"
$SupportedJellyfinSdkVersion = "10.10.7"
Write-Host "=== Start Release Process, Target Version: $Version ===" -ForegroundColor Cyan
# 1. Get current UTC timestamp
$Timestamp = [DateTime]::UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.0000000Z")
Write-Host "Current package timestamp (UTC): $Timestamp" -ForegroundColor Gray
$RepositoryRoot = (Resolve-Path $PSScriptRoot).Path.Replace('\', '/')
$GitArguments = @("-c", "safe.directory=$RepositoryRoot")
$PreviewTag = "preview"
# Define paths
$ThunderCsproj = "Jellyfin.MeiamSub.Thunder\Jellyfin.MeiamSub.Thunder.csproj"
@@ -33,6 +37,75 @@ $AssrtMeta = "Jellyfin.MeiamSub.Assrt\meta.json"
$EmbyThunderCsproj = "Emby.MeiamSub.Thunder\Emby.MeiamSub.Thunder.csproj"
$EmbyAssrtCsproj = "Emby.MeiamSub.Assrt\Emby.MeiamSub.Assrt.csproj"
if ($Version -notmatch '^\d+\.\d+\.\d+\.\d+$') {
throw "版本号必须使用四段数字格式,例如 1.0.18.0 或 1.0.17.1。"
}
$VersionParts = $Version.Split('.') | ForEach-Object { [int]$_ }
$Revision = $VersionParts[3]
if ($Channel -eq "Stable" -and $Revision -ne 0) {
throw "正式版版本号末位必须为 0,例如 1.0.18.0。"
}
if ($Channel -eq "Preview" -and $Revision -eq 0) {
throw "测试版版本号末位必须大于 0,例如 1.0.17.1。"
}
if ($Channel -eq "Preview" -and $PublishToGitHub -and [string]::IsNullOrWhiteSpace($Notes)) {
throw "发布滚动测试版时必须通过 -Notes 说明本轮测试重点。"
}
$CurrentVersionMatch = [regex]::Match((Get-Content -LiteralPath $ThunderCsproj -Raw), '<Version>([\d\.]+)</Version>')
if (-not $CurrentVersionMatch.Success) {
throw "无法读取当前插件版本。"
}
$CurrentVersion = [version]$CurrentVersionMatch.Groups[1].Value
if ([version]$Version -le $CurrentVersion) {
throw "目标版本 $Version 必须高于当前版本 $CurrentVersion。"
}
$WorkingTreeChanges = @(git @GitArguments status --porcelain)
if ($LASTEXITCODE -ne 0) {
throw "无法检查 Git 工作树状态。"
}
if ($WorkingTreeChanges.Count -gt 0) {
throw "发布前工作树必须保持干净,请先提交或处理现有变更。"
}
if ($Channel -eq "Stable") {
$ExistingLocalTag = git @GitArguments tag --list "v$Version"
if ($LASTEXITCODE -ne 0) {
throw "无法检查本地 Git 标签。"
}
if ($ExistingLocalTag) {
throw "本地标签 v$Version 已存在,禁止覆盖已经使用的正式版本。"
}
if ($PublishToGitHub) {
git @GitArguments ls-remote --exit-code --tags origin "refs/tags/v$Version" | Out-Null
if ($LASTEXITCODE -eq 0) {
throw "远端标签 v$Version 已存在,禁止覆盖已经公开的正式版本。"
}
if ($LASTEXITCODE -ne 2) {
throw "无法检查远端标签,请检查网络或 Git 认证。"
}
}
}
$ChannelLabel = if ($Channel -eq "Preview") { "测试版发布" } else { "正式发布" }
Write-Host "=== 开始${ChannelLabel}流程,目标版本:$Version ===" -ForegroundColor Cyan
if ($ValidateOnly) {
Write-Host "发布参数、工作树和标签检查通过。" -ForegroundColor Green
return
}
# 1. Get current UTC timestamp
$Timestamp = [DateTime]::UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.0000000Z")
Write-Host "Current package timestamp (UTC): $Timestamp" -ForegroundColor Gray
# Update NuGet package version if specified
if ($JellyfinVersion -and $JellyfinVersion -ne $SupportedJellyfinSdkVersion) {
throw "Jellyfin SDK must remain at $SupportedJellyfinSdkVersion for the verified 10.10.7-12.1 compatibility range. Update the compatibility matrix before changing it."
@@ -88,6 +161,15 @@ Write-Host "Versions and timestamps updated successfully!" -ForegroundColor Gree
# 2. Compile solution
Write-Host "Compiling solution in Release mode..." -ForegroundColor Yellow
dotnet build MeiamSubtitles.sln -c Release
if ($LASTEXITCODE -ne 0) {
throw "解决方案编译失败。"
}
Write-Host "Running automated tests..." -ForegroundColor Yellow
dotnet test tests\MeiamSubtitles.Tests\MeiamSubtitles.Tests.csproj -c Release --no-restore
if ($LASTEXITCODE -ne 0) {
throw "自动测试失败。"
}
# 3. Create zip archives
Write-Host "Packaging zip archives..." -ForegroundColor Yellow
@@ -117,9 +199,15 @@ Copy-Item Release\dependencies\Jellyfin\* $JellyfinAssrtPackDir\
Copy-Item Jellyfin.MeiamSub.Assrt\meta.json $JellyfinAssrtPackDir\
Copy-Item Jellyfin.MeiamSub.Assrt\thumb.png $JellyfinAssrtPackDir\
# Archive target paths
$EmbyZip = "Release\Emby_v$Version.zip"
$JellyfinZip = "Release\Jellyfin_v$Version.zip"
# Archive target paths. Preview assets use stable names because the single
# rolling preview release replaces them on every test iteration.
if ($Channel -eq "Preview") {
$EmbyZip = "Release\Emby_preview.zip"
$JellyfinZip = "Release\Jellyfin_preview.zip"
} else {
$EmbyZip = "Release\Emby_v$Version.zip"
$JellyfinZip = "Release\Jellyfin_v$Version.zip"
}
if (Test-Path $EmbyZip) { Remove-Item -Force $EmbyZip }
if (Test-Path $JellyfinZip) { Remove-Item -Force $JellyfinZip }
@@ -140,23 +228,132 @@ if ($PublishToGitHub) {
Write-Host "=== Start GitHub Release process ===" -ForegroundColor Cyan
Write-Host "Staging and committing release changes..." -ForegroundColor Yellow
git add .
git commit -m "release: v$Version"
$ReleaseMetadataFiles = @(
$ThunderCsproj,
$ThunderMeta,
$AssrtCsproj,
$AssrtMeta,
$EmbyThunderCsproj,
$EmbyAssrtCsproj
)
git @GitArguments add -- $ReleaseMetadataFiles
if ($LASTEXITCODE -ne 0) {
throw "暂存发布版本文件失败。"
}
git @GitArguments diff --cached --check
if ($LASTEXITCODE -ne 0) {
throw "暂存内容存在空白错误。"
}
$CommitMessage = if ($Channel -eq "Preview") {
"发布: 更新滚动测试版至 v$Version"
} else {
"发布: v$Version"
}
git @GitArguments commit -m $CommitMessage
if ($LASTEXITCODE -ne 0) {
throw "创建发布提交失败。"
}
Write-Host "Pushing changes to remote repository..." -ForegroundColor Yellow
git push origin master
git @GitArguments push origin master
if ($LASTEXITCODE -ne 0) {
throw "推送发布提交失败。"
}
Write-Host "Creating GitHub Release v$Version and uploading assets..." -ForegroundColor Yellow
if ($Notes) {
$AutoNotes = gh release generate-notes --tag "v$Version"
$NotesContent = "## Release Notes`n`n$Notes`n`n" + $AutoNotes
$NotesFile = "Release\temp_notes.md"
Set-Content -Path $NotesFile -Value $NotesContent
gh release create "v$Version" $EmbyZip $JellyfinZip --title "v$Version" --notes-file $NotesFile
if (Test-Path $NotesFile) { Remove-Item -Force $NotesFile }
if ($Channel -eq "Preview") {
Write-Host "Updating rolling GitHub test release..." -ForegroundColor Yellow
$CommitSha = git @GitArguments rev-parse HEAD
if ($LASTEXITCODE -ne 0) {
throw "无法读取预发布提交哈希。"
}
$EmbyHash = (Get-FileHash -LiteralPath $EmbyZip -Algorithm SHA256).Hash
$JellyfinHash = (Get-FileHash -LiteralPath $JellyfinZip -Algorithm SHA256).Hash
$PreviewNotesFile = "Release\preview-notes.md"
$PreviewNotes = @"
## 当前测试版本
- 插件版本:$Version
- 源码提交:$CommitSha
- Emby 包 SHA-256:$EmbyHash
- Jellyfin 包 SHA-256:$JellyfinHash
## 本轮测试重点
$Notes
## 安装说明
停止 Emby 或 Jellyfin,移除旧版 Thunder DLL 或插件目录,再安装本页最新测试包并重启。反馈问题时请注明插件版本和宿主版本。
"@
Set-Content -LiteralPath $PreviewNotesFile -Value $PreviewNotes -Encoding utf8
try {
# The user requested one rolling preview. Only this dedicated tag
# may be force-moved; branches and formal release tags remain immutable.
git @GitArguments tag --force $PreviewTag $CommitSha
if ($LASTEXITCODE -ne 0) {
throw "更新本地 preview 标签失败。"
}
git @GitArguments push origin "refs/tags/$PreviewTag" --force
if ($LASTEXITCODE -ne 0) {
throw "更新远端 preview 标签失败。"
}
& gh release view $PreviewTag *> $null
$PreviewReleaseExists = $LASTEXITCODE -eq 0
if ($PreviewReleaseExists) {
& gh release upload $PreviewTag $EmbyZip $JellyfinZip --clobber
if ($LASTEXITCODE -ne 0) {
throw "覆盖滚动测试附件失败;请检查仓库是否启用了 Release 不可变保护。"
}
& gh release edit $PreviewTag --title "测试版(滚动更新)" --notes-file $PreviewNotesFile --prerelease --draft=false --latest=false
} else {
& gh release create $PreviewTag $EmbyZip $JellyfinZip --title "测试版(滚动更新)" --verify-tag --notes-file $PreviewNotesFile --prerelease --latest=false
}
if ($LASTEXITCODE -ne 0) {
throw "创建或更新滚动测试 Release 失败。"
}
} finally {
if (Test-Path -LiteralPath $PreviewNotesFile) {
Remove-Item -LiteralPath $PreviewNotesFile -Force
}
}
Write-Host "滚动测试版已更新:不要修改 manifest-stable.json。" -ForegroundColor Yellow
} else {
gh release create "v$Version" $EmbyZip $JellyfinZip --title "v$Version" --generate-notes
Write-Host "Creating stable GitHub Release v$Version and uploading assets..." -ForegroundColor Yellow
$ReleaseArguments = @(
"release", "create", "v$Version",
$EmbyZip,
$JellyfinZip,
"--title", "v$Version",
"--target", "master",
"--latest"
)
if ($Notes) {
$ReleaseArguments += @("--notes", $Notes, "--generate-notes")
} else {
$ReleaseArguments += "--generate-notes"
}
& gh @ReleaseArguments
if ($LASTEXITCODE -ne 0) {
throw "创建正式 GitHub Release 失败。"
}
& gh release view $PreviewTag *> $null
if ($LASTEXITCODE -eq 0) {
& gh release edit $PreviewTag --draft
if ($LASTEXITCODE -ne 0) {
throw "正式版已创建,但隐藏滚动测试 Release 失败。"
}
}
Write-Host "正式版 GitHub Release 已创建,请继续更新 MeiamSubtitles.Release 的稳定清单。" -ForegroundColor Yellow
}
Write-Host "=== GitHub Release finished successfully! ===" -ForegroundColor Green

View File

@@ -10,6 +10,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="8.0.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2" />
</ItemGroup>

View File

@@ -32,6 +32,67 @@ public class SubtitleContentValidatorTests
SubtitleContentValidator.Validate(data, "srt", "application/octet-stream");
}
[Fact]
public void ConvertsGb18030SrtToUtf8ForPreview()
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
var content = "1\r\n00:00:01,000 --> 00:00:02,000\r\n中文字幕\r\n";
var data = Encoding.GetEncoding(54936).GetBytes(content);
var normalized = SubtitleContentValidator.ValidateAndConvertToUtf8(
data,
"srt",
"application/octet-stream");
Assert.Equal(content, Encoding.UTF8.GetString(normalized));
}
[Fact]
public void PreservesCompleteUtf8SubtitleWhenNormalizing()
{
var content = "1\r\n00:00:01,000 --> 00:00:20,000\r\n" + new string('中', 3000) + "\r\n";
var normalized = SubtitleContentValidator.ValidateAndConvertToUtf8(
Encoding.UTF8.GetBytes(content),
"srt",
"application/octet-stream");
Assert.Equal(content, Encoding.UTF8.GetString(normalized));
}
[Theory]
[InlineData(false)]
[InlineData(true)]
public void ConvertsUtf16SrtToUtf8ForPreview(bool bigEndian)
{
var encoding = new UnicodeEncoding(bigEndian, true);
var content = "1\r\n00:00:01,000 --> 00:00:02,000\r\n中文字幕\r\n";
var data = encoding.GetPreamble().Concat(encoding.GetBytes(content)).ToArray();
var normalized = SubtitleContentValidator.ValidateAndConvertToUtf8(
data,
"srt",
"application/octet-stream");
Assert.Equal(content, Encoding.UTF8.GetString(normalized));
}
[Theory]
[InlineData(false)]
[InlineData(true)]
public void ConvertsUtf16WithoutBomToUtf8ForPreview(bool bigEndian)
{
var encoding = new UnicodeEncoding(bigEndian, false);
var content = "1\r\n00:00:01,000 --> 00:00:02,000\r\n中文字幕\r\n";
var normalized = SubtitleContentValidator.ValidateAndConvertToUtf8(
encoding.GetBytes(content),
"srt",
"application/octet-stream");
Assert.Equal(content, Encoding.UTF8.GetString(normalized));
}
[Theory]
[InlineData(false, false)]
[InlineData(false, true)]