public string ExtractSeason(string Text) // ex: show s01 title { _AHK ahk = new _AHK(); // nothing to do, name already matches format Regex regex = new Regex(@"S\d{2} "); // 4 digit year Match match = regex.Match(Text); if (match.Success) { //if (msgDisp) { ahk.MsgBox(match.Value); } return(match.Value); } regex = new Regex(@"\d{1-2}x\d{1-2}"); // 7th_heaven 6x02 teased.dvdrip_xvid-fov match = regex.Match(Text); if (match.Success) { string seasonEp = match.Value.Trim(); string season = ahk.FirstCharacters(seasonEp, 1); string ep = ahk.LastCharacters(seasonEp, 2); seasonEp = "S0" + season + "E" + ep.AddLeadingZeros(2); return(seasonEp); } return(""); }
/// <summary> Tested ? Working ? </summary> /// <param name="sender"> </param> /// <param name="e"> </param> private void selectedScintilla_CharAdded(object sender, CharAddedEventArgs e) { // Find the word start var currentPos = selectedScintilla.CurrentPosition; var wordStartPos = selectedScintilla.WordStartPosition(currentPos, true); //string AutoCompleteList = "Gen_SQLite Gen_TreeView Gen_Grid List<int> List<TreeNode>"; // list of words to offer autocomplete options //string AutoCompleteString = String.Join(" ", AutoCompleteList.ToArray()); selectedScintilla.AutoCAutoHide = false; // hide popup after text is ruled out string trimmedWordList = ""; // Display the autocompletion list var lenEntered = currentPos - wordStartPos; if (lenEntered > 0) { selectedScintilla.AutoCIgnoreCase = true; selectedScintilla.AutoCChooseSingle = false; selectedScintilla.AutoCMaxHeight = 10; selectedScintilla.AutoCDropRestOfWord = true; string SoFarText = selectedScintilla.GetWordFromPosition(wordStartPos); // word typed so far //ahk.MsgBox(Text); //string[] words = AutoCompleteList.Split(' '); string[] words = autoCompleteList.ToArray(); foreach (string word in words) { string TextInList = ahk.FirstCharacters(word, lenEntered); // returns first X characters in string if (TextInList.ToUpper() == SoFarText.ToUpper()) { trimmedWordList = trimmedWordList + " " + word; } //if (TextInList.ToUpper().Contains(SoFarText.ToUpper())) { trimmedWordList = trimmedWordList + " " + word; } } selectedScintilla.AutoCShow(lenEntered, trimmedWordList.Trim()); //if (lenEntered > 3) { scintilla1.AutoCComplete(); } // autocomplete past X characters selectedScintilla.AutoCCompleted += new EventHandler <AutoCSelectionEventArgs>(selectedScintilla_AutoCompleteAccepted); hit = false; //scintilla1.AutoCShow(lenEntered, AutoCompleteList); // regex pattern matching and highlighting - untested //foreach (Match m in Patterns.Keyword0.Matches(Encoding.ASCII.GetString(e.RawText))) // e.GetRange(m.Index, m.Index + m.Length).SetStyle(1); } }
/// <summary>Converts text from a text file to list <string> /// <param name="TextString">Text String To Parse By New Line Into List Return</param> /// <param name="SkipBlankLines">Option To Skip Blank Lines in List Return</param> /// <param name="Trim">Option To Trim Each Line</param> /// <param name="SkipCommentLines">Skip Lines Starting with '//' (For Excluding C# Comments)</param> public static List <string> ToList(this string TextString, bool SkipBlankLines = true, bool Trim = true, bool SkipCommentLines = true) { _AHK ahk = new _AHK(); List <string> list = new List <string>(); if (TextString == null) { return(list); } // parse by new line { // Creates new StringReader instance from System.IO using (StringReader reader = new StringReader(TextString)) { // Loop over the lines in the string. string line; while ((line = reader.ReadLine()) != null) { if (SkipCommentLines) { string First2 = ahk.FirstCharacters(line, 2); // skip over lines if they are comments if (First2 == @"//") { continue; } } string writeline = line; if (Trim) { writeline = line.Trim(); } // trim leading spaces if (SkipBlankLines) { if (writeline == "") { continue; } } list.Add(writeline); } } } return(list); }
public void ComedianTree(RadTreeView radtree, string rootDir = "S:\\", bool NewThread = true) { _AHK ahk = new _AHK(); _Lists lst = new _Lists(); _TelerikLib tel = new _TelerikLib(); _TelerikLib.RadTree tree = new _TelerikLib.RadTree(); if (NewThread) { Thread imdbTVParseThread = new Thread(() => ComedianTree(radtree, rootDir, false)); imdbTVParseThread.Start(); } else { //string rootDir = "S:\\"; List <string> Comedians = lst.DirList(rootDir, "*.*", false, false); Comedians = lst.SortList(Comedians); // alpha sort list foreach (string com in Comedians) { string first = ahk.FirstCharacters(com, 1); if (first == "_") { continue; } // skip folders starting with "_" // add node for comedian RadTreeNode comNode = new RadTreeNode(); comNode.Text = com; comNode.Tag = rootDir + "\\" + com; //radtree.Nodes.Add(comNode); tree.AddNode(radtree, comNode); // list of shows under comedian dir List <string> shows = lst.DirList(rootDir + "\\" + com, "*.*", false, false); shows = lst.SortList(shows); // alpha sort list foreach (string show in shows) { RadTreeNode showNode = new RadTreeNode(); showNode.Text = show; showNode.Tag = rootDir + "\\" + com + "\\" + show; //comNode.Nodes.Add(showNode); tree.AddSubNode(comNode, showNode, radtree); } } } }
/// <summary>Returns first X characters in string</summary> /// <param name="Text"> </param> /// <param name="NumberOfCharacters"> </param> public static string FirstCharacters(this string Text, int NumberOfCharacters = 1) { _AHK ahk = new _AHK(); return(ahk.FirstCharacters(Text, NumberOfCharacters)); }
/// <summary>Converts text from a text file to list <string> /// <param name="Input">Either Text String of Valid Text File Path</param> /// <param name="SkipBlankLines">Option To Skip Blank Lines in List Return</param> /// <param name="Trim">Option To Trim Each Line</param> /// <param name="SkipCommentLines">Skip Lines Starting with '//' (For Excluding C# Comments)</param> public static List <string> ToList(this string Input, string SplitChar = "NewLine", bool SkipBlankLines = true, bool Trim = true, bool SkipCommentLines = false) { _AHK ahk = new _AHK(); List <string> list = new List <string>(); if (Input == null) { return(list); } if (Input.CharCount() < 259) // valid number of chars for a file path { if (Input.IsFile()) { if (File.Exists(Input)) { Input = ahk.FileRead(Input); } } if (Input.IsDir()) { if (Directory.Exists(Input)) { return(DirList(Input, "*.*", true, true)); } } } if (SplitChar == "NewLine" || SplitChar == "\n" || SplitChar == "\r" || SplitChar == "\n\r") { // Creates new StringReader instance from System.IO using (StringReader reader = new StringReader(Input)) { // Loop over the lines in the string. string line; while ((line = reader.ReadLine()) != null) { if (SkipCommentLines) { string First2 = ahk.FirstCharacters(line, 2); // skip over lines if they are comments if (First2 == @"//") { continue; } } string writeline = line; if (Trim) { writeline = line.Trim(); } // trim leading spaces if (SkipBlankLines) { if (writeline == "") { continue; } } list.Add(writeline); } } } else { return(ahk.StringSplit_List(Input, SplitChar, SkipBlankLines)); } return(list); }
/// <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(""); }