diff --git a/Apewer.Run/Batch.cs b/Apewer.Run/Batch.cs new file mode 100644 index 0000000..db2dd87 --- /dev/null +++ b/Apewer.Run/Batch.cs @@ -0,0 +1,51 @@ +using Apewer; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace Apewer.Run +{ + + public class Batch + { + + public Batch() => ConvertBreakingBad(); + + public void ConvertBreakingBad() + { + var paths = StorageUtility.GetSubFiles(@"E:\Breaking Bad"); + var outdir = @"D:\temp\bb"; + foreach (var path in paths) + { + var name = Path.GetFileName(path); + Console.Title = name; + Console.Clear(); + + if (name.EndsWith(".mkv")) + { + var mp4path = Path.Combine(outdir, name.Replace(".mkv", ".mp4")); + if (StorageUtility.FileExists(mp4path)) continue; + + var cmd = "ffmpeg.exe"; + var arg = $"-i \"{path}\" -vcodec copy -acodec copy \"{mp4path}\""; + WindowsUtility.RunConsole(cmd, arg, (s) => Console.WriteLine(s)); + continue; + } + + if (name.EndsWith(".srt")) + { + continue; + var srtpath = Path.Combine(outdir, name); + var vttpath = Path.Combine(outdir, name.Replace(".srt", ".vtt")); + var text = StorageUtility.ReadFile(path).ToText(Encoding.Default); + StorageUtility.WriteFile(srtpath, text.ToBinary()); + WindowsUtility.RunConsole("ffmpeg.exe", $"-i \"{srtpath}\" \"{vttpath}\"", (s) => Console.WriteLine(s)); + continue; + } + } + } + + } + +} diff --git a/Apewer.Run/FileRenamer.cs b/Apewer.Run/FileRenamer.cs index af87ce6..6bce94c 100644 --- a/Apewer.Run/FileRenamer.cs +++ b/Apewer.Run/FileRenamer.cs @@ -15,22 +15,20 @@ namespace Apewer.Run { // RenameZQSV(); - var paths = StorageUtility.GetSubFiles(@"Y:\telecast\芸汐传", true); + var dir = @"E:\Breaking Bad"; + + var paths = StorageUtility.GetSubFiles(dir, true); + var array = Json.NewArray(); foreach (var path in paths) { var name = Path.GetFileName(path); - // name = name.Replace(" ", ""); - name = name.Replace(".qsv.flv.mp4", ".mp4"); - name = name.Replace(".qsv.flv.mp4", ""); - name = name.Replace("【4K】", ""); - - var split = name.Split(' '); - split[1] = split[1].Replace("第", "").Replace("集", ""); - if (split[1].Length == 1) split[1] = "0" + split[1]; - split[1] = "第 " + split[1] + " 集"; + if (name.EndsWith(".mkv")) continue; + if (name.EndsWith(".json")) continue; - name = string.Join(" - ", split) + ".mp4"; + name = name.Replace("Breaking Bad - ", ""); + array.AddItem(name); + name = name + ".srt"; var newPath = Path.Combine(Path.GetDirectoryName(path), name); if (newPath != path) @@ -40,6 +38,7 @@ namespace Apewer.Run } // else Console.WriteLine(path); } + StorageUtility.WriteFile(Path.Combine(dir, "info.json"), array.ToString(true).ToBinary()); } void RenameZQSV() diff --git a/Apewer.Run/_Program.cs b/Apewer.Run/_Program.cs index d7f348a..d01c14d 100644 --- a/Apewer.Run/_Program.cs +++ b/Apewer.Run/_Program.cs @@ -18,6 +18,7 @@ namespace Apewer.Run // RunPublicClass(args); + // new Batch(); // new FileRenamer(); // new HashComputer(); diff --git a/Apewer/Apewer.csproj b/Apewer/Apewer.csproj index c62c723..17df3fb 100644 --- a/Apewer/Apewer.csproj +++ b/Apewer/Apewer.csproj @@ -7,7 +7,7 @@ Apewer Apewer Apewer - 6.0.11 + 6.0.12 diff --git a/Apewer/Internals/TextConverter.cs b/Apewer/Internals/TextConverter.cs index a1dc48f..4f2d108 100644 --- a/Apewer/Internals/TextConverter.cs +++ b/Apewer/Internals/TextConverter.cs @@ -235,33 +235,48 @@ namespace Apewer.Internals } /// 获取单精度浮点对象。 - public static Single GetSingle(string argValue) + public static Single GetSingle(string text) { - if (!string.IsNullOrEmpty(argValue)) + + if (!string.IsNullOrEmpty(text)) { try { - if (TextVerifier.IsNumber(argValue)) + var t = text.Trim(); + var p = 0; + while (t.Length > 0 && t.EndsWith("%")) { - return Convert.ToSingle(argValue); + t = t.Substring(0, t.Length - 1); + p += 1; } + var v = Convert.ToSingle(t); + if (p > 0) v /= Convert.ToSingle(Math.Pow(100D, p)); + return v; + // if (TextVerifier.IsNumber(argValue)) return Convert.ToSingle(argValue); } catch { } } - return 0; + return 0F; } /// 获取双精度浮点对象。 - public static Double GetDouble(string argValue) + public static Double GetDouble(string text) { - if (!string.IsNullOrEmpty(argValue)) + if (!string.IsNullOrEmpty(text)) { try { - if (TextVerifier.IsNumber(argValue)) + var t = text.Trim(); + var p = 0; + while (t.Length > 0 && t.EndsWith("%")) { - return Convert.ToDouble(argValue); + t = t.Substring(0, t.Length - 1); + p += 1; } + var v = Convert.ToDouble(t); + if (p > 0) v /= Math.Pow(100D, p); + return v; + // if (TextVerifier.IsNumber(text)) return Convert.ToDouble(text); } catch { } } @@ -269,25 +284,42 @@ namespace Apewer.Internals } /// 获取 Decimal 对象。 - public static decimal GetDecimal(string argValue) + public static decimal GetDecimal(string text) { - decimal result = 0; - if (!string.IsNullOrEmpty(argValue)) + if (!string.IsNullOrEmpty(text)) { try { - result = Convert.ToDecimal(argValue); + var t = text.Trim(); + var p = 0; + while (t.Length > 0 && t.EndsWith("%")) + { + t = t.Substring(0, t.Length - 1); + p += 1; + } + var v = Convert.ToDecimal(t); + if (p > 0) v /= Convert.ToDecimal(Math.Pow(100D, p)); + return v; } catch { try { - result = decimal.Parse(argValue, System.Globalization.NumberStyles.Float); + var t = text.Trim(); + var p = 0; + while (t.Length > 0 && t.EndsWith("%")) + { + t = t.Substring(0, t.Length - 1); + p += 1; + } + var v = decimal.Parse(t, System.Globalization.NumberStyles.Float); + if (p > 0) v /= Convert.ToDecimal(Math.Pow(100D, p)); + return v; } catch { } } } - return result; + return 0M; } /// 获取 Byte 对象。 diff --git a/Apewer/_ChangeLog.md b/Apewer/_ChangeLog.md index bc46ec5..3486b86 100644 --- a/Apewer/_ChangeLog.md +++ b/Apewer/_ChangeLog.md @@ -5,6 +5,9 @@ ### 最新提交 +### 6.0.12 +- 扩展方法 ToSingle、ToDouble、ToDecimal 支持输入百分号。 + ### 6.0.11 - 扩展方法 ApiResponse.Respond 支持返回错误信息。