diff --git a/AutoImport.cs b/AutoImport.cs index ed0276c..0316fd5 100644 --- a/AutoImport.cs +++ b/AutoImport.cs @@ -15,12 +15,9 @@ internal class AutoImport /// todo: /// /// handle complexnotsimple and temp streamwriters better - /// the linknumbercounters are increased for complex links as well - /// + /// /// handle youtube shorts in both download and check /// - /// folders.linknumber refers to all links or youtube links in autoimport (Writelinkstotxt is not returning the changed values) - /// /// there is some bug with checkformissing, out of range maybe? /// allfailed.txt wrong place and name /// create archive.shouldbe.txt and compare to archive that way? @@ -31,10 +28,8 @@ internal class AutoImport /// /// check browser paths for flatpaks:maybe https://github.com/flatpak/flatpak/issues/1214#issuecomment-347752940 /// - /// add safari and opera and edge support - /// - /// check vivaldi linux path? - /// edge linux, osx? + /// add safari support + /// opera edge osx path? /// /// handle folders with empty names /// @@ -70,7 +65,7 @@ public static void AutoMain() deepestdepth = folders[q].depth; } } - Writelinkstotxt(folders, numberoffolders, rootdir, wantcomplex); + folders = Writelinkstotxt(folders, numberoffolders, rootdir, wantcomplex); Methods.Dumptoconsole(folders, numberoffolders, Globals.totalyoutubelinknumber); string ytdlp_path = Methods.Yt_dlp_pathfinder(rootdir); //finding path to yt-dlp binary Methods.Scriptwriter(folders, numberoffolders, ytdlp_path); //writing the scripts that call yt-dlp and add .txt with the links in the arguments //NOT the method that creates the .txt files @@ -83,10 +78,10 @@ public static void AutoMain() System.Environment.Exit(1); //leaving the program, so it does not contiue running according to Program.cs } - public static void Writelinkstotxt(Folderclass[] folders, int numberoffolders, string rootdir, bool wantcomplex) + public static Folderclass[] Writelinkstotxt(Folderclass[] folders, int numberoffolders, string rootdir, bool wantcomplex) { StreamWriter temp = new StreamWriter(Path.Combine(rootdir, "temp.txt"), append: true); //writing into temp.txt all the youtube links that are not for videos (but for channels, playlists, etc.) - int i = 0; + int i = 0; //totalyoutubelinknumber later for (int j = 0; j < numberoffolders + 1; j++) { StreamWriter writer = new StreamWriter(Path.Combine(folders[j].folderpath, folders[j].name + ".txt"), append: false); @@ -137,9 +132,17 @@ public static void Writelinkstotxt(Folderclass[] folders, int numberoffolders, s if (iscomplicated == false) { writer.WriteLine(linkthatisbeingexamined); + if (!wantcomplex) + { + i++; + linknumbercounter++; + } + } + if (wantcomplex) + { + i++; + linknumbercounter++; } - i++; - linknumbercounter++; } } writer.Flush(); @@ -165,6 +168,7 @@ public static void Writelinkstotxt(Folderclass[] folders, int numberoffolders, s temp.Close(); Globals.totalyoutubelinknumber = i; Console.WriteLine("Total number of youtube links found: " + i); + return folders; } public static Folderclass[] Createfolderstructure(Folderclass[] folders, string rootdir) @@ -273,6 +277,8 @@ public static string FindfilePath() { browsername = "Microsoft Edge", windows_profilespath = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft\\Edge\\User Data"), + linux_profilespath = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "microsoft-edge") + //.config/microsoft-edge/Default/Bookmarks // C:\Users\\AppData\Local\Microsoft\Edge\User Data\Default. }; BrowserLocations Opera = new BrowserLocations() @@ -280,16 +286,23 @@ public static string FindfilePath() browsername = "Opera", //C:\Users\%username%\AppData\Roaming\Opera Software\Opera Stable\Bookmarks is the Bookmarks file windows_profilespath = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Opera Software"), - //rest has to be checked manually + //opera: .config/opera/Bookmarks + hardcodedpaths = new List() + { + Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "opera/Bookmarks"), + } + //osx has to be checked }; List browserLocations = new List { Chrome, - Brave, - Chromium, Chrome_beta, Chrome_canary, - Vivaldi + Brave, + Chromium, + Vivaldi, + Edge, + Opera }; /* //use default location for bookmarks file @@ -545,6 +558,23 @@ public static string FindfilePath() Console.WriteLine(($"No Bookmarks file found in " + browser.browsername)); } } + else if (browser.hardcodedpaths.Count != 0) + { + foreach (string hardpath in browser.hardcodedpaths) + { + if (File.Exists(hardpath)) + { + filepaths.Add(hardpath); + Console.WriteLine("File found! Filepath in " + browser.browsername + ": " + hardpath); + browser.linksfound++; + } + + } + if (browser.linksfound == 0) + { + Console.WriteLine(($"No Bookmarks file found in " + browser.browsername)); + } + } else { Console.WriteLine(browser.browsername + " install folder not found"); @@ -566,6 +596,23 @@ public static string FindfilePath() } if (browser.linksfound == 0) { Console.WriteLine(($"Bookmarks file not found in " + browser.browsername)); } } + else if (browser.hardcodedpaths.Count != 0) + { + foreach (string hardpath in browser.hardcodedpaths) + { + if (File.Exists(hardpath)) + { + filepaths.Add(hardpath); + Console.WriteLine("File found! Filepath in " + browser.browsername + ": " + hardpath); + browser.linksfound++; + } + + } + if (browser.linksfound == 0) + { + Console.WriteLine(($"No Bookmarks file found in " + browser.browsername)); + } + } else { Console.WriteLine(browser.browsername + " install folder not found"); @@ -586,6 +633,23 @@ public static string FindfilePath() } if (browser.linksfound == 0) { Console.WriteLine(($"Bookmarks file not found in " + browser.browsername)); } } + else if (browser.hardcodedpaths.Count != 0) + { + foreach (string hardpath in browser.hardcodedpaths) + { + if (File.Exists(hardpath)) + { + filepaths.Add(hardpath); + Console.WriteLine("File found! Filepath in " + browser.browsername + ": " + hardpath); + browser.linksfound++; + } + + } + if (browser.linksfound == 0) + { + Console.WriteLine(($"No Bookmarks file found in " + browser.browsername)); + } + } else { Console.WriteLine(browser.browsername + " install folder not found"); @@ -800,6 +864,16 @@ public static Folderclass[] Intake(string filePath) Globals.endingline++; Globals.folderclasses.Add(thisBookmark); Folderclass[] folders = Convertlisttoarray(Globals.folderclasses); + foreach (Folderclass folder in folders) + { + foreach (Folderclass ffold in folders) + { + if (folder.depth == ffold.depth - 1 && folder.startline < ffold.startline && folder.endingline < ffold.endingline) + { + folder.parent = ffold.id; + } + } + } return folders; } @@ -808,6 +882,7 @@ public static Folderclass Childfinder(Bookmark current, int depth) Folderclass thisBookmark = new Folderclass(); Globals.folderid++; thisBookmark.startline = Globals.folderid; + thisBookmark.id = Globals.folderid; thisBookmark.urls = new List(); //Console.WriteLine("Started childfinder with current folder: {1}, id:{0}, depth:{2}", globals.folderid, current.name, depth); int numberoflinks = 0; @@ -848,17 +923,15 @@ public static Folderclass[] Convertlisttoarray(List folderclasses) { if (folderclass.startline == i) { - //Console.WriteLine(folderclass.startline + "==" + i); folders[i].name = folderclass.name; folders[i].depth = folderclass.depth; folders[i].startline = folderclass.startline; folders[i].endingline = folderclass.endingline; folders[i].numberoflinks = folderclass.numberoflinks; folders[i].urls = folderclass.urls; - //Console.WriteLine("name " + folders[i].name + "==" + folderclass.name); - //Console.WriteLine("depth " + folders[i].depth + "==" + folderclass.depth); - //Console.WriteLine("startline " + folders[i].startline + "==" + folderclass.startline); - //Console.WriteLine("numberoflinks " + folders[i].numberoflinks + "==" + folderclass.numberoflinks); + folders[i].id = folderclass.id; + folders[i].parent = folderclass.parent; + folders[i].children = folderclass.children; } } } @@ -900,4 +973,5 @@ public class BrowserLocations public string linux_profilespath = ""; public string osx_profilespath = ""; public Int16 linksfound = 0; + public List hardcodedpaths = new List(); } \ No newline at end of file diff --git a/Methods.cs b/Methods.cs index d47c9e5..a957c69 100644 --- a/Methods.cs +++ b/Methods.cs @@ -28,6 +28,7 @@ public static Folderclass[] Bookmarktofolderclasses(List bookmarks, in foreach (Bookmark bookmark in bookmarks) { int i = bookmark.id; + folders[folderid].id = folderid; //i refers to the id (from the sql) of the folder that is being examined. folderid will be its new id, so every folderid refers to folders and there is no gap between them: //examples: //folder toolbars id: 2 folderid: 1 @@ -39,6 +40,7 @@ public static Folderclass[] Bookmarktofolderclasses(List bookmarks, in if (index != -1) { //i - id of the examined folder, parentid[i] - id of the examined folder's parent : we are looking for the folder[] that has this parentid[i] as its startingline (refers to the original id), so "folders.SingleOrDefault(a => a.startline == parentid[i])" refers to the parent of the examined folder folders[folderid].depth = folders.SingleOrDefault(a => a.startline == parentid[i]).depth + 1; //the given folders depth is the depth of their parent folder + 1 + folders[folderid].parent = folders.SingleOrDefault(a => a.startline == parentid[i]).id; } else //if (index == -1) { @@ -56,6 +58,7 @@ public static Folderclass[] Bookmarktofolderclasses(List bookmarks, in folderid++; } AutoImport.Globals.folderid = folderid - 1; //helps for setting numberoffolders later + folders[1].name = "root"; return folders; } @@ -255,7 +258,7 @@ public static void Dumptoconsole(Folderclass[] folders, int numberoffolders = 0, Console.ForegroundColor = ConsoleColor.Red; Console.Write(folders[m].numberoflinks); Console.ResetColor(); - Console.Write(" youtube links." + m); + Console.Write(" youtube links. m:" + m + " id: " + folders[m].id + " parent: " + folders[m].parent); if (folders[m].numberofmissinglinks != 0) { Console.Write(" (missing: "); diff --git a/Program.cs b/Program.cs index 326a78a..73c4ac6 100644 --- a/Program.cs +++ b/Program.cs @@ -67,7 +67,7 @@ static void Main() { numberoffolders++; folders[numberoffolders].startline = j; - + folders[numberoffolders].id = numberoffolders; } } Console.WriteLine(numberoffolders + " folders were found in the bookmarks"); @@ -234,9 +234,17 @@ static void Main() if (iscomplicated == false) { writer.WriteLine(linkthatisbeingexamined); + if (!wantcomplex) + { + i++; + linknumbercounter++; + } + } + if (wantcomplex) + { + i++; + linknumbercounter++; } - i++; - linknumbercounter++; } line = inputarray[qq].Trim().Split('>'); //writer.WriteLine(line[2].Substring(0,line[2].Length-3)); //writes the name of the bookmark //to write into same line use writer.Write() @@ -299,5 +307,8 @@ public class Folderclass //defining the folderclass class to create an object ar public int numberoflinks; public int numberofmissinglinks; public List urls = new List(); + public int id; //same as array index + public int parent; + public List children = new List(); } }