本文整理汇总了C#中System.Text.RegularExpressions.Match.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# Match.FirstOrDefault方法的具体用法?C# Match.FirstOrDefault怎么用?C# Match.FirstOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.RegularExpressions.Match
的用法示例。
在下文中一共展示了Match.FirstOrDefault方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//.........这里部分代码省略.........
//Regex r = new Regex("Attachment ID ([0-9]*): type 'application/.+font', size [0-9]+ bytes, file name '(.+)'");
////System.Diagnostics.Debugger.Break();
//foreach (var line in mkvmergeLines)
//{
// var result = r.Match(line);
// if (result.Success)
// {
// ExecuteAndReturn("mkvextract", string.Format("attachments \"{0}\" {1}:\"{2}\"", item, result.Groups[1].Value, result.Groups[2].Value));
// if (!File.Exists("C:\\tools\\ffmpeg\\fonts\\" + result.Groups[2].Value))
// File.Copy(result.Groups[2].Value, "C:\\tools\\ffmpeg\\fonts\\" + result.Groups[2].Value);
// cleanup.Add(result.Groups[2].Value);
// }
//}
tmp = ExecuteAndReturn("ffmpeg", string.Format(" -i \"{0}\"", item));
Regex r = new Regex("Input #0, .+?, from '" + Regex.Escape(item) + "':.+", RegexOptions.Singleline);
var result = r.Match(tmp);
tmp = result.Value;
r = new Regex("\\s{4}Stream #0:(?<TrackID>[0-9])+(\\((?<language>[^()]+)\\))?: (?<Type>Video|Audio|Subtitle|Attachment):[^\\r\\n]+\\r\\n(\\s{4}Metadata:\\r\\n\\s{6}filename\\s*:\\s*(?<FileName>[^\\r\\n]+)\\r\\n\\s{6}mimetype[^\\r\\n]+)?", RegexOptions.Singleline);
var resultCollection = r.Matches(tmp);
//Stream #0:0: Video: mpeg4 (XVID / 0x44495658), yuv420p, 640x480, 23.98 fps, 23.98 tbr, 23.98 tbn, 23.98 tbc
//Stream #0:1(English[eng]): Audio: vorbis, 48000 Hz, stereo, fltp, 176 kb/s
//Stream #0:2(Japanese[jpn]): Audio: vorbis, 48000 Hz, stereo, fltp, 176 kb/s
//Stream #0:3(English[eng]): Subtitle: text
Match[] a = new Match[resultCollection.Count];
resultCollection.CopyTo(a, 0);
string audioTrack = "a";
if (a.Count(g => g.Groups["Type"].Value == "Audio") > 1)
{
var audioResult = a.Where(g => g.Groups["Type"].Value == "Audio").FirstOrDefault(g => g.Value.Contains("jpn") || g.Value.Contains("Japanese"));
if (audioResult != null)
audioTrack = audioResult.Groups["TrackID"].Value;
}
bool hasSubs = false;
var subtitleResult = a.FirstOrDefault(g => g.Groups["Type"].Value == "Subtitle");
if (File.Exists(item+".ass"))
{
hasSubs = true;
subtitlefile = item + ".ass";
}
else if (subtitleResult != null)
{
ExecuteAndReturn("ffmpeg", string.Format("-i \"{0}\" -y -vn -an -codec:s:0.{1} ssa \"{2}\"", item, subtitleResult.Groups["TrackID"].Value, subtitlefile));//-codec:s:0.{1}
hasSubs = true;
cleanup.Add(subtitlefile);
}
if (a.Count(g => g.Groups["Type"].Value == "Attachment") > 0)
{
ExecuteAndReturn("ffmpeg", string.Format("-dump_attachment:t \"\" -i \"{0}\" -y", item), dir);
foreach (var f in a.Where(g => g.Groups["Type"].Value == "Attachment").Select(g => g.Groups["FileName"].Value))
{
cleanup.Add(dir + "\\" + f);
if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + Settings.Default.FontPath + f))
{
if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory+Settings.Default.FontPath))
Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + Settings.Default.FontPath);
File.Copy(dir + "\\" + f, AppDomain.CurrentDomain.BaseDirectory + Settings.Default.FontPath + f);