Skip to content

Commit

Permalink
more compiled regex
Browse files Browse the repository at this point in the history
  • Loading branch information
hez2010 committed Jul 13, 2022
1 parent bd904da commit 1253632
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 6 additions & 3 deletions BBDown/BBDownMuxer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace BBDown
{
class BBDownMuxer
partial class BBDownMuxer
{
public static string FFMPEG = "ffmpeg";
public static string MP4BOX = "mp4box";
Expand Down Expand Up @@ -48,7 +48,7 @@ public static int MuxByMp4box(string videoPath, string audioPath, string outPath
StringBuilder metaArg = new();
inputArg.Append(" -inter 500 -noprog ");
if (!string.IsNullOrEmpty(videoPath))
inputArg.Append($" -add \"{videoPath}#trackID={((audioOnly && audioPath == "") ? "2" : "1")}:name=\" ");
inputArg.Append($" -add \"{videoPath}#trackID={(audioOnly && audioPath == "" ? "2" : "1")}:name=\" ");
if (!string.IsNullOrEmpty(audioPath))
inputArg.Append($" -add \"{audioPath}:lang={(lang == "" ? "und" : lang)}\" ");
if (points != null && points.Count > 0)
Expand Down Expand Up @@ -123,7 +123,7 @@ public static int MuxAV(bool useMp4box, string videoPath, string audioPath, stri

if (!string.IsNullOrEmpty(pic))
metaArg.Append($" -disposition:v:{(audioOnly ? "0" : "1")} attached_pic ");
var inputCount = Regex.Matches(inputArg.ToString(), "-i \"").Count;
var inputCount = InputRegex().Matches(inputArg.ToString()).Count;

if (points != null && points.Count > 0)
{
Expand Down Expand Up @@ -173,5 +173,8 @@ public static void MergeFLV(string[] files, string outPath)
foreach (var s in f) File.Delete(s);
}
}

[RegexGenerator("-i \"")]
private static partial Regex InputRegex();
}
}
9 changes: 7 additions & 2 deletions BBDown/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ private static async Task DoWorkAsync(MyOption myOption)
LogColor($"[音频] [{audioTracks[aIndex].codecs}] [{audioTracks[aIndex].bandwith} kbps] [~{FormatFileSize(audioTracks[aIndex].dur * audioTracks[aIndex].bandwith * 1024 / 8)}]", false);

//处理PCDN
var pcdnReg = new Regex("://.*:\\d+/");
var pcdnReg = PcdnRegex();
if (videoTracks.Count > 0 && pcdnReg.IsMatch(videoTracks[vIndex].baseUrl))
{
LogWarn($"检测到视频流为PCDN,尝试强制替换为{BACKUP_HOST}……");
Expand Down Expand Up @@ -1132,7 +1132,7 @@ private static List<Video> SortTracks(List<Video> videoTracks, Dictionary<string
private static string FormatSavePath(string savePathFormat, string title, Video? videoTrack, Audio? audioTrack, Page p, int pagesCount)
{
var result = savePathFormat.Replace('\\', '/');
var regex = new Regex("<(\\w+?)>");
var regex = InfoRegex();
foreach (Match m in regex.Matches(result).Cast<Match>())
{
var key = m.Groups[1].Value;
Expand Down Expand Up @@ -1269,5 +1269,10 @@ private static async Task LoginTV()
}
catch (Exception e) { LogError(e.Message); }
}

[RegexGenerator("://.*:\\d+/")]
private static partial Regex PcdnRegex();
[RegexGenerator("<(\\w+?)>")]
private static partial Regex InfoRegex();
}
}

0 comments on commit 1253632

Please sign in to comment.