public void RAR_EachFileInDir(RadProgressBar radProgress, string DirPath, bool NewThread = true, bool EpNumRARName = true, string Prefix = "") { _AHK ahk = new _AHK(); if (NewThread) { Thread imdbTVParseThread = new Thread(() => RAR_EachFileInDir(radProgress, DirPath, false, EpNumRARName, Prefix)); imdbTVParseThread.Start(); } else { _TelerikLib.RadProgress pro = new _TelerikLib.RadProgress(); _Lists lst = new _Lists(); _Parse prs = new _Parse(); string rar = @"C:\_Code\LucidProjects\ADBindex\ComPress\bin\Debug\Lib\rar.exe"; List <string> files = lst.FileList(DirPath); pro.SetupProgressBar(radProgress, files.Count); string RelativePath = "-ep"; string fileDir = ahk.FileDir(DirPath); int i = 0; foreach (string file in files) { if (ahk.FileExt(file).ToUpper() == ".URL") { continue; } // extract season/ep number from file name string epNum = prs.SeasonEpNums(file); i++; pro.UpdateProgress(radProgress, ahk.FileName(file) + " " + i + "/" + files.Count); string newRAR = fileDir + "\\" + Prefix + epNum + ".rar"; // use the file name as the zip file name if (!EpNumRARName) { newRAR = fileDir + "\\" + ahk.FileNameNoExt(file) + ".rar"; } if (File.Exists(newRAR)) { continue; } string FIle = file.Replace(",", "`,"); string cmd = rar + " A -m0 " + RelativePath + " " + "\"" + newRAR + "\" \"" + FIle + "\""; ahk.RunWait(cmd, "", "Hide"); } ahk.MsgBox("Finished RARing " + files.Count + " Files"); } }
/// <summary>Separates a file path - returns file name (no extension)</summary> /// <param name="FilePath">File Location to Parse</param> /// <param name="CheckIfExists">Option to check to see if FilePath exists - FileNameNoExt returns blank if file not found</param> public static string FileNameNoExt(this string FilePath, bool CheckIfExists = false) { _AHK ahk = new _AHK(); return(ahk.FileNameNoExt(FilePath, CheckIfExists)); }
/// <summary> /// FFMpeg Create Preview Images From Video Dir /// </summary> /// <param name="VideoDir"></param> /// <param name="SaveDir"></param> public void VideoScreenCaps(string VideoDir, ProgressBar progressB, bool NewThread = true, string SaveDir = "", int TilesWide = 3, int TilesTall = 3, string Scale = "320:240", string SaveFormat = "jpg", bool OverWriteExisting = false, string CaptureOpt = "1000") { if (NewThread) { Thread newThread = new Thread(() => VideoScreenCaps(VideoDir, progressB, false, SaveDir, TilesWide, TilesTall, Scale, SaveFormat, OverWriteExisting, CaptureOpt)); thr.Start(newThread, "VidThread"); //newThread.Start(); } else { // string videoFilePath, string saveDir = "", int TilesWide = 3, int TilesTall = 3, string Scale = "320:240", string SaveFormat = "jpg" if (!pathDefined) { pathDefined = FFMpeg_DefinePaths(); if (!pathDefined) { return; } } List <string> files = new List <string>(); if (ahk.isFile(VideoDir)) { files.Add(VideoDir); } else { files = lst.FileList(VideoDir, "*.*", true, false, true); } if (progressB.InvokeRequired) { progressB.BeginInvoke((MethodInvoker) delegate() { progressB.Maximum = files.Count(); }); } else { progressB.Maximum = files.Count(); } SaveDir = VideoDir + "\\Previews"; Dir_Watch(SaveDir); // monitor dir for new images and display as created Stopwatch watch = new Stopwatch(); int i = 0; foreach (string file in files) { watch.Start(); sb(file); i++; sb(i + "/" + files.Count.ToString(), 2); if (progressB.InvokeRequired) { progressB.BeginInvoke((MethodInvoker) delegate() { progressB.Value = i; }); } else { progressB.Value = i; } ahk.DisplayText(ahk.FileName(file) + " | " + i + "/" + files.Count, txtCurrentProgress); // calculate time left until folder completed // number of files left in dir to vidCap // reemaining jobs times last job time = time remaining int remaining = files.Count() - i; remaining = remaining * lastJobTime; TimeSpan t = TimeSpan.FromSeconds(remaining); string remains = t.TotalMinutes.ToString(); if (txtRemainingMin.InvokeRequired) { txtRemainingMin.BeginInvoke((MethodInvoker) delegate() { txtRemainingMin.Text = remains + " Min Left"; }); } else { txtRemainingMin.Text = remains + " Min Left"; } // check to see if preview image already exists string PreviewImage = SaveDir + "\\" + ahk.FileNameNoExt(file) + "." + SaveFormat; if (!OverWriteExisting) { if (!File.Exists(PreviewImage)) { sb("Generating Video Preview Image... " + ahk.FileName(PreviewImage)); string previewImg = VidCap_Tiles(file, "", TilesWide, TilesTall, Scale, SaveFormat, CaptureOpt); //if (pictureBox != null) { pictureBox.Image = previewImg.ToImg(); } // display preview image if viewer visible } } else { ahk.FileDelete(PreviewImage); sb("Generating Video Preview Image... " + ahk.FileName(PreviewImage)); string previewImg = VidCap_Tiles(file, "", TilesWide, TilesTall, Scale, SaveFormat, CaptureOpt); //if (pictureBox != null) { pictureBox.Image = previewImg.ToImg(); } // display preview image if viewer visible } string stopWatchTime = watch.Elapsed.Seconds.ToString(); lastJobTime = watch.Elapsed.Seconds; ahk.DisplayText(stopWatchTime + " seconds", txtJobTimeDisp); watch.Reset(); } ahk.OpenDir(SaveDir); ahk.MsgBox("Finished Creating VideoScreenCaps"); } }
/// <summary> /// Extract Season/EpNum Format from FilePath (or string) and Return S00E00 Format /// </summary> /// <param name="FilePath">FilePath or String Containing Season/EpNum Info to Parse</param> /// <param name="RenameFile">Option to Replace Unformatted Season/EpNum with Standard S00E00 Naming Convention</param> /// <returns></returns> public string SeasonEpNums(string FilePath, bool RenameFile = false) { _AHK ahk = new _AHK(); bool msgDisp = false; string FileNameNoExt = ""; bool FileFound = false; string dir = ""; string ext = ""; if (RenameFile) { if (File.Exists(FilePath)) { FileNameNoExt = ahk.FileNameNoExt(FilePath); ext = ahk.FileExt(FilePath); dir = ahk.FileDir(FilePath); FileFound = true; } } else { if (FilePath.Contains(":")) { FilePath = FilePath.Replace(":", "-"); FileNameNoExt = ahk.FileNameNoExt(FilePath); } else { FileNameNoExt = FilePath; } } FileNameNoExt = FileNameNoExt.Replace("x264", ""); FileNameNoExt = FileNameNoExt.Replace("x265", ""); FileNameNoExt = FileNameNoExt.Replace("720p", ""); FileNameNoExt = FileNameNoExt.Replace("1080p", ""); FileNameNoExt = FileNameNoExt.ToUpper(); // nothing to do, name already matches format Regex regex = new Regex(@"S\d{2}E\d{2}"); // hawaii.five-0.2010.S08E01 Match match = regex.Match(FileNameNoExt); if (match.Success) { //if (msgDisp) { ahk.MsgBox(match.Value); } return(match.Value); } // find 3 digit season/ep format, rename file to S00E00 Format regex = new Regex(@"(\.|_)\d{3}(\.|_)"); // "hawaii.five-0.2010.805.hdtv-lol" match = regex.Match(FileNameNoExt); if (match.Success) { string MatchText = match.Value; string seasonEp = match.Value.Replace(".", ""); seasonEp = match.Value.Replace("_", ""); string season = ahk.FirstCharacters(seasonEp, 1); string ep = ahk.LastCharacters(seasonEp, 2); seasonEp = "S0" + season + "E" + ep; if (FileFound && RenameFile) { FileNameNoExt = FileNameNoExt.Replace(MatchText, "." + seasonEp + "."); string newName = dir + "\\" + FileNameNoExt + ext; bool renamed = ahk.FileRename(FilePath, newName); if (msgDisp) { ahk.MsgBox("Renamed = " + renamed.ToString() + "\n\n" + FilePath + "\n\n" + newName); } } return(seasonEp); } // find 3 digit season/ep format, rename file to S00E00 Format regex = new Regex(@"\.\d{1,2}X\d{2}(\.|_)"); // .4x23. OR .4x23_ match = regex.Match(FileNameNoExt); if (match.Success) { string MatchText = match.Value; string seasonEp = match.Value.Replace(".", ""); seasonEp = match.Value.Replace("_", ""); string season = ahk.FirstCharacters(seasonEp, 1); string ep = ahk.LastCharacters(seasonEp, 2); seasonEp = "S0" + season + "E" + ep; if (FileFound && RenameFile) { FileNameNoExt = FileNameNoExt.Replace(MatchText, "." + seasonEp + "."); string newName = dir + "\\" + FileNameNoExt + ext; bool renamed = false; renamed = ahk.FileRename(FilePath, newName); if (msgDisp) { ahk.MsgBox("Renamed = " + renamed.ToString() + "\n\n" + FilePath + "\n\n" + newName); } } return(seasonEp); } regex = new Regex(@"\.\d{1-2}X\d{1-2}\."); // 7th_heaven.6x02.teased.dvdrip_xvid-fov match = regex.Match(FileNameNoExt); if (match.Success) { string seasonEp = match.Value.Replace(".", ""); string season = ahk.FirstCharacters(seasonEp, 1); string ep = ahk.LastCharacters(seasonEp, 2); seasonEp = "S0" + season + "E" + ep.AddLeadingZeros(2); if (msgDisp) { ahk.MsgBox(seasonEp); } return(seasonEp); } regex = new Regex(@"\d{4}.\d{2}.d{2}"); // conan.2018.01.18.gerard.butler.720p.web.x264 - tbs match = regex.Match(FileNameNoExt); if (match.Success) { if (msgDisp) { ahk.MsgBox(match.Value); } //string seasonEp = match.Value.Replace(".", ""); string seasonEp = match.Value; return(seasonEp); } regex = new Regex(@"\d{4}\s\d{2}\s\d{2}"); // conan 2018 01 18 gerard butler 720p web x264 - tbs match = regex.Match(FileNameNoExt); if (match.Success) { if (msgDisp) { ahk.MsgBox(match.Value); } return(match.Value); } regex = new Regex(@"\d{4}"); // hap.and.leonard.0304-yestv match = regex.Match(FileNameNoExt); if (match.Success) { string seasonEp = match.Value.Replace(".", ""); string season = ahk.FirstCharacters(seasonEp, 2); string ep = ahk.LastCharacters(seasonEp, 2); seasonEp = "S" + season + "E" + ep.AddLeadingZeros(2); if (msgDisp) { ahk.MsgBox(seasonEp); } return(seasonEp); } return(""); }