Skip to content

Commit

Permalink
some progress
Browse files Browse the repository at this point in the history
changes for browser default path handling, console write changed somewhat, introduced parent and child to class
  • Loading branch information
Neurofibromin authored Sep 23, 2023
1 parent 661284a commit fe2c42b
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 26 deletions.
118 changes: 96 additions & 22 deletions AutoImport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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
///
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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)
Expand Down Expand Up @@ -273,23 +277,32 @@ 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\<Current-user>\AppData\Local\Microsoft\Edge\User Data\Default.
};
BrowserLocations Opera = new BrowserLocations()
{
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<string>()
{
Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "opera/Bookmarks"),
}
//osx has to be checked
};
List<BrowserLocations> browserLocations = new List<BrowserLocations>
{
Chrome,
Brave,
Chromium,
Chrome_beta,
Chrome_canary,
Vivaldi
Brave,
Chromium,
Vivaldi,
Edge,
Opera
};
/*
//use default location for bookmarks file
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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;
}

Expand All @@ -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<string>();
//Console.WriteLine("Started childfinder with current folder: {1}, id:{0}, depth:{2}", globals.folderid, current.name, depth);
int numberoflinks = 0;
Expand Down Expand Up @@ -848,17 +923,15 @@ public static Folderclass[] Convertlisttoarray(List<Folderclass> 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;
}
}
}
Expand Down Expand Up @@ -900,4 +973,5 @@ public class BrowserLocations
public string linux_profilespath = "";
public string osx_profilespath = "";
public Int16 linksfound = 0;
public List<string> hardcodedpaths = new List<string>();
}
5 changes: 4 additions & 1 deletion Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static Folderclass[] Bookmarktofolderclasses(List<Bookmark> 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
Expand All @@ -39,6 +40,7 @@ public static Folderclass[] Bookmarktofolderclasses(List<Bookmark> 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)
{
Expand All @@ -56,6 +58,7 @@ public static Folderclass[] Bookmarktofolderclasses(List<Bookmark> bookmarks, in
folderid++;
}
AutoImport.Globals.folderid = folderid - 1; //helps for setting numberoffolders later
folders[1].name = "root";
return folders;
}

Expand Down Expand Up @@ -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: ");
Expand Down
17 changes: 14 additions & 3 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -299,5 +307,8 @@ public class Folderclass //defining the folderclass class to create an object ar
public int numberoflinks;
public int numberofmissinglinks;
public List<string> urls = new List<string>();
public int id; //same as array index
public int parent;
public List<int> children = new List<int>();
}
}

0 comments on commit fe2c42b

Please sign in to comment.