/// <summary> /// Moves the downloaded file to the downloads folder of the windows user. /// </summary> /// <param name="videoInfo"></param> private void MoveFileToDownloadsFolder(VideoInformation videoInfo) { try { var downloadsFolder = KnownFolders.GetPath(KnownFolder.Downloads); if (File.Exists($"{downloadsFolder}\\{videoInfo.FileName}")) { Console.WriteLine($"{videoInfo.FileName} already exists within your Download Folder."); Console.WriteLine($"Would you like to overwrite it? (y/n)"); if (ApplicationNavigation.DetermineYesOrNo()) { File.Move(videoInfo.SourceLocation, downloadsFolder, true); } else { Console.WriteLine("Would you like to restart? (y/n)"); if (ApplicationNavigation.DetermineYesOrNo()) { Console.Clear(); ApplicationNavigation.StartApplicationProcess(); } else { ApplicationNavigation.CloseApplication(10); } } } } catch (IOException ioException) { Console.WriteLine(ioException.Message); throw; } }
/// <summary> /// Event Handler that triggers when a download via WebClient is complete. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public static void DownloadCompletedEventHandler(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { if (e.Error == null) { DownloadCompleteMessaging(); } else { Console.Clear(); Console.WriteLine($"Download failed due to {e.Error?.Message}."); ApplicationNavigation.DetermineRetryApplication(); } }
public void BeforeScenario() { if (!ScenarioContext.Current.ContainsKey("CurrentDriver")) { TestFixture.Test_Setup(); ScenarioContext.Current.Add("CurrentDriver", TestFixture.CurrentDriver); Navigation = new ApplicationNavigation(_testFixture.CurrentDriver); ScenarioContext.Current.Add("Navigation", Navigation); } else { Navigation = (ApplicationNavigation)ScenarioContext.Current["Navigation"]; } }
private static async Task StartProgram() { try { ApplicationNavigation.StartApplicationProcess(); await Task.Delay(-1); } catch (Exception ex) { Console.WriteLine("Application exploded. Please locate ErrorReport.txt and send it to my developer."); Log.LogExceptionAsync(ex, ApplicationNavigation.VideoInfo); ApplicationNavigation.RestartApplication(); } }
public static void DownloadCompleteMessaging() { Console.Clear(); Console.WriteLine("Download Complete!"); Console.WriteLine("Would you like to download another? (y/n)"); if (ApplicationNavigation.DetermineYesOrNo()) { Console.Clear(); ApplicationNavigation.StartApplicationProcess(); } else { ApplicationNavigation.CloseApplication(); } }
/// <summary> /// Used HtmlAgilityPack to scrape Streamable and acquire a download URL for the video, then downloads it. /// </summary> public async void DownloadStreamableVideo(VideoSource source) { string videoUrl = null; var httpClient = new HttpClient(); var html = await httpClient.GetStringAsync(new Uri(VideoInfo.VideoUrl)); switch (source) { case VideoSource.Streamable: var htmlDocument = new HtmlDocument(); htmlDocument.LoadHtml(html); List <HtmlNode> urlFound; urlFound = htmlDocument.DocumentNode.Descendants("meta").Where(x => x.GetAttributeValue("property", "").Equals("og:video:url")).ToList(); switch (urlFound.Count) { case 1: { videoUrl = urlFound.FirstOrDefault()?.GetAttributeValue("content", ""); break; } case 0: Console.WriteLine($"No videos found. Website either not supported or contains no video to download."); ApplicationNavigation.DetermineRetryApplication(); break; } break; case VideoSource.TwitchClip: try { WebDriver.Navigate().GoToUrl(VideoInfo.VideoUrl); videoUrl = WebDriver.FindElement(By.XPath("//video")).GetAttribute("src"); TearDown(); } catch (Exception e) { TearDown(); Console.WriteLine($"There was an issue trying to download your twitch clip: {e.Message}"); Log.LogExceptionAsync(e); ApplicationNavigation.DetermineRetryApplication(); } break; case VideoSource.Youtube: var youtube = new YoutubeClient(httpClient); var video = await youtube.Videos.GetAsync(VideoInfo.VideoUrl); var streamManifest = await youtube.Videos.Streams.GetManifestAsync(video.Id); // ...or highest quality MP4 video-only stream var streamInfo = streamManifest .GetMuxed().WithHighestVideoQuality(); if (streamInfo != null) { // Get the actual stream var stream = await youtube.Videos.Streams.GetAsync(streamInfo); // Download the stream to file var youtubeDownload = youtube.Videos.Streams.DownloadAsync(streamInfo, $"{Environment.CurrentDirectory}\\{VideoInfo.FileName}.{streamInfo.Container}").ConfigureAwait(true).GetAwaiter(); youtubeDownload.OnCompleted(EventHandlersManager.DownloadCompleteMessaging); } break; default: throw new ArgumentOutOfRangeException(nameof(source), source, "Currently unsupported."); } if (source != VideoSource.Youtube) { StartDownload(videoUrl); } }
private void Awake() { transferCode = GameObject.FindObjectOfType <TransferCode>(); gameManager = GameObject.FindObjectOfType <GameManager>(); appNavigation = GameObject.FindObjectOfType <ApplicationNavigation>(); }