private static void RunWithoutConfig() { while (true) { try { var extractor = new Extractor(); Browser selectedBrowser = TUI.GetBrowser(); var initializationTask = extractor.InitializeDriver(selectedBrowser); initializationTask.Start(); string courseUrl = TUI.GetCourseUrl(); while (true) { try { string token = TUI.GetLoginToken(); var loginTask = extractor.Login(token, courseUrl, initializationTask); var courseRootDirectory = TUI.GetPath(); var selectedQuality = TUI.GetQuality(); Console.WriteLine(TUI.continueGlyph + "Logging in..."); loginTask.Wait(); Console.WriteLine(TUI.continueGlyph + "Logged in successfully"); Config config = new Config { AuthenticationToken = token, Browser = selectedBrowser, Quality = selectedQuality, CourseDirectory = courseRootDirectory }; File.WriteAllText("./Config.json", config.ToJson()); Console.WriteLine(TUI.continueGlyph + "Saved entries to config file"); Console.WriteLine(TUI.endGlyph + "Intializing Course Extractor..."); Course course = new Course(); extractor.ExtractCourseStructure(out int videosCount); using (pbarExtractor = new ProgressBar(videosCount, "Extracting Course Links - This will take some time", optionPbarExtractor)) { extractor.ExtractionProgressChanged += Extractor_ExtractionProgressChanged; course = extractor.ExtractCourse(selectedQuality); } CourseDownloader.DownloadCourse(course, courseRootDirectory); return; } catch (InvalidTokenException) { TUI.ShowError("The token you supplied is invalid - Login Failed"); } } } catch (WebDriverException ex) { TUI.ShowError("An error occured in the driver : " + ex.Message); TUI.ShowError("Error details : " + ex.StackTrace); TUI.ShowError("Trying again..."); RunWithoutConfig(); return; } catch (Exception ex) { TUI.ShowError("An error occured : " + ex.Message); TUI.ShowError("Error details : " + ex.StackTrace); RunWithoutConfig(); return; } } }
private static void RunWithoutConfig() { Browser selectedBrowser = TUI.GetBrowser(); Extractor.InitializeDriver(selectedBrowser); string courseUrl = TUI.GetCourseUrl(); string token = TUI.GetLoginToken(); var loginTask = Extractor.Login(token, courseUrl); var courseRootDirectory = TUI.GetPath(); var selectedQuality = TUI.GetQuality(); Log.Information("Logging in..."); Console.WriteLine(TUI.continueGlyph + "Logging in..."); try { loginTask.Wait(); } catch (InvalidTokenException ex) { Log.Error(ex, "Failed to log in with course url : {0} and token of {1} characters", courseUrl, token.Length); TUI.ShowError("The token or the course url you provided is invalid. Please make sure you entered the right token and course url"); RunWithoutConfig(); return; } catch (Exception e) when(e.InnerException is InvalidTokenException ex) { Log.Error(ex, "Failed to log in with course url : {0} and token of {1} characters", courseUrl, token.Length); TUI.ShowError("The token or the course url you provided is invalid. Please make sure you entered the right token and course url"); RunWithoutConfig(); return; } catch (Exception ex) { Log.Error(ex, "Unknown Exception"); TUI.ShowError("Unknown Error occured - " + ex.Message); RunWithoutConfig(); return; } Log.Information("Logged in successfully"); Console.WriteLine(TUI.continueGlyph + "Logged in successfully"); Config config = new Config { AuthenticationToken = token, Browser = selectedBrowser, Quality = selectedQuality, CourseDirectory = courseRootDirectory }; File.WriteAllText("./Config.json", config.ToJson()); Console.WriteLine(TUI.continueGlyph + "Saved entries to config file"); Log.Information("Saved entries to congig file. Intializing Course Extractor"); Console.WriteLine(TUI.endGlyph + "Intializing Course Extractor"); Course course = ExtractCourse(config); if (course is null) { RunWithoutConfig(); return; } Log.Information("Course Extracted. Downloading..."); Console.WriteLine(); CourseDownloader.DownloadCourse(course, courseRootDirectory); }