-
-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
50 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using N_m3u8DL_RE.Common.Entity; | ||
using N_m3u8DL_RE.Common.Log; | ||
using N_m3u8DL_RE.Common.Resource; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace N_m3u8DL_RE.Util | ||
{ | ||
internal class SubtitleUtil | ||
{ | ||
/// <summary> | ||
/// 写出图形字幕PNG文件 | ||
/// </summary> | ||
/// <param name="finalVtt"></param> | ||
/// <param name="tmpDir">临时目录</param> | ||
/// <returns></returns> | ||
public static async Task<bool> TryWriteImagePngsAsync(WebVttSub? finalVtt, string tmpDir) | ||
{ | ||
if (finalVtt != null && finalVtt.Cues.Any(v => v.Payload.StartsWith("Base64::"))) | ||
{ | ||
Logger.WarnMarkUp(ResString.processImageSub); | ||
var _i = 0; | ||
foreach (var img in finalVtt.Cues.Where(v => v.Payload.StartsWith("Base64::"))) | ||
{ | ||
var name = $"{_i++}.png"; | ||
var dest = ""; | ||
for (; File.Exists(dest = Path.Combine(tmpDir, name)); name = $"{_i++}.png") ; | ||
var base64 = img.Payload[8..]; | ||
await File.WriteAllBytesAsync(dest, Convert.FromBase64String(base64)); | ||
img.Payload = name; | ||
} | ||
return true; | ||
} | ||
else return false; | ||
} | ||
} | ||
} |