Advertisement
MrModest

Scan Processes

May 8th, 2017
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. void ScanProcesses()
  2. {
  3.     System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcesses();
  4.     string titleName = processes.FirstOrDefault(x => x.ProcessName == "mpc-hc64")?.MainWindowTitle;
  5.  
  6.     if (String.IsNullOrWhiteSpace(titleName)) { return; }
  7.  
  8.     Dictionary<string, string> title = new Dictionary<string, string>();
  9.     System.Text.RegularExpressions.Regex reg;
  10.  
  11.     reg = new System.Text.RegularExpressions.Regex(@"- ?(\d+)(\(\d*\))?");
  12.     var match = reg.Match(titleName);
  13.     string ep = "";
  14.     if (match.Index != 0 && match.Length != 0)
  15.     {
  16.         ep = titleName.Substring(match.Index, match.Length).Replace("- ", "");
  17.         titleName = reg.Replace(titleName, "");    
  18.     }
  19.     title.Add("episode", ep);
  20.  
  21.     reg = new System.Text.RegularExpressions.Regex(@"TV(\d*)");
  22.     match = reg.Match(titleName);
  23.     string season = "";
  24.     if (match.Index != 0 && match.Length != 0)
  25.     {
  26.         season = titleName.Substring(match.Index, match.Length).Replace("TV", "");
  27.         titleName = reg.Replace(titleName, "");
  28.     }
  29.     if (String.IsNullOrWhiteSpace(season))
  30.     {
  31.         season = "1";
  32.     }
  33.     title.Add("season", season);
  34.  
  35.     reg = new System.Text.RegularExpressions.Regex(@"\[.*?\]|\(.*?\)");
  36.     string name = reg.Replace(titleName, "");
  37.     title.Add("name", name);
  38.  
  39.     Console.WriteLine("{0} | {1} | {2}", title["name"], title["episode"], title["season"]);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement