Browse Source

Apewer-6.0.12:ToDouble、ToDecimal 支持输入百分号。

dev
Elivo 5 years ago
parent
commit
1479553218
  1. 51
      Apewer.Run/Batch.cs
  2. 21
      Apewer.Run/FileRenamer.cs
  3. 1
      Apewer.Run/_Program.cs
  4. 2
      Apewer/Apewer.csproj
  5. 62
      Apewer/Internals/TextConverter.cs
  6. 3
      Apewer/_ChangeLog.md

51
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;
}
}
}
}
}

21
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()

1
Apewer.Run/_Program.cs

@ -18,6 +18,7 @@ namespace Apewer.Run
// RunPublicClass(args);
// new Batch();
// new FileRenamer();
// new HashComputer();

2
Apewer/Apewer.csproj

@ -7,7 +7,7 @@
<AssemblyName>Apewer</AssemblyName>
<PackageId>Apewer</PackageId>
<Title>Apewer</Title>
<Version>6.0.11</Version>
<Version>6.0.12</Version>
</PropertyGroup>
<!-- Info -->

62
Apewer/Internals/TextConverter.cs

@ -235,33 +235,48 @@ namespace Apewer.Internals
}
/// <summary>获取单精度浮点对象。</summary>
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;
}
/// <summary>获取双精度浮点对象。</summary>
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
}
/// <summary>获取 Decimal 对象。</summary>
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;
}
/// <summary>获取 Byte 对象。</summary>

3
Apewer/_ChangeLog.md

@ -5,6 +5,9 @@
### 最新提交
### 6.0.12
- 扩展方法 ToSingle、ToDouble、ToDecimal 支持输入百分号。
### 6.0.11
- 扩展方法 ApiResponse.Respond 支持返回错误信息。

Loading…
Cancel
Save