Skip to content

Commit

Permalink
Ikkoku/convert: decode pgs to bmp
Browse files Browse the repository at this point in the history
  • Loading branch information
MIRIMIRIM committed Jun 3, 2024
1 parent 6ece9ce commit 3f4307a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
36 changes: 21 additions & 15 deletions Ikkoku/src/CommandLine/ConvertCmd.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Mobsub.Ikkoku.SubtileProcess;
using Mobsub.SubtitleParse.AssTypes;
using Mobsub.SubtitleParse.PGS;
using System.CommandLine;

namespace Mobsub.Ikkoku.CommandLine;
Expand Down Expand Up @@ -62,11 +63,6 @@ internal static void ConvertSubtitle(FileInfo fromFile, FileSystemInfo? optPath,
break;
}

var optFile = Utils.ChangeSuffix(fromFile, optDir, convertSuffix);
var fs = new FileStream(optFile.FullName, FileMode.Create, FileAccess.Write);
using var memStream = new MemoryStream();
using var sw = new StreamWriter(memStream, SubtitleParse.Utils.EncodingRefOS());

switch (fromFile.Extension)
{
case ".ass":
Expand All @@ -76,23 +72,33 @@ internal static void ConvertSubtitle(FileInfo fromFile, FileSystemInfo? optPath,
switch (convertSuffix)
{
case ".txt":
ConvertSub.ConvertAssToTxt(sw, ass);
var optFile = Utils.ChangeSuffix(fromFile, optDir, convertSuffix);
var fs = new FileStream(optFile.FullName, FileMode.Create, FileAccess.Write);
using (var memStream = new MemoryStream())
{
using var sw = new StreamWriter(memStream, SubtitleParse.Utils.EncodingRefOS());
ConvertSub.ConvertAssToTxt(sw, ass);
sw.Flush();
memStream.Seek(0, SeekOrigin.Begin);
memStream.CopyTo(fs);
}
break;
default:
throw new NotImplementedException($"Unsupport: {fromFile.Extension} convert to {convertSuffix}.");
}
break;
case ".sup":
switch (convertSuffix)
{
case ".bmp":
PGSData.DecodeImages(fromFile.FullName, optDir.FullName);
break;
default:
// fs.Close();
throw new NotImplementedException($"Unsupport: {fromFile.Extension} convert to {convertSuffix}.");
}

break;
default:
// fs.Close();
throw new NotImplementedException($"Unsupport: {fromFile.Extension}.");
}

sw.Flush();

memStream.Seek(0, SeekOrigin.Begin);
memStream.CopyTo(fs);
// fs.Close();
}
}
2 changes: 1 addition & 1 deletion Ikkoku/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static async Task<int> Main(string[] args)
switch (p)
{
case FileInfo f:
if (!(f.Name.EndsWith(".ass") || f.Name.EndsWith(".txt")))
if (!(f.Name.EndsWith(".ass") || f.Name.EndsWith(".txt") || f.Name.EndsWith(".sup")))
{
result.ErrorMessage = "You should input .ass or txt file or a directory.";
}
Expand Down

0 comments on commit 3f4307a

Please sign in to comment.