//Happens when the download button is finnaly pressed private void DownloadAll_Click(object sender, RoutedEventArgs e) { //Loop trough all the videos that the user saved foreach (KeyValuePair <String, String> pair in videoAndPath) { /* * For each video to download we create a new proccess * and use the saveVideoToDiskAsync method provided by * the YoutubeApi class to start downloading specified * video to the specified path the file from Youtube */ new Task( async() => { String key = pair.Key; String value = pair.Value; YoutubeApi.saveVideoToDiskAsync("https://www.youtube.com/watch?v=" + key, value); } ).RunSynchronously(); } /* Clear the list and reset the index after downloading * everything so the proccess can be correctly done again */ videoAndPath.Clear(); currentLinksSaved = 0; }
private void searchKeyUpEvent(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { /* * Checks if there is need to display * the downloads */ if (indexing == 0) { canvas.Children.Add(downloadAll); canvas.Children.Add(downloadListLabel); } /* * Checks if there have already been videos * displayed to clear the canvas and reset * the index * If not, the animation for lifting the searchbar * is played */ if (videoOnScreenList.Count == 0) { story = new Animation( searchBar.Margin.Top / 2 - 150, -searchBar.Margin.Top + 20, TimeSpan.FromSeconds(0.5), 1, new CubicEase(), new PropertyPath(TopProperty), searchBar ); } else { cleanCanvas(); indexing = 0; } /* Creates a list to save the videos that the * Youtube Api finds with the user input and then * for each video found it displays it */ List <string> videos = new List <string>(); videos = YoutubeApi.searchForVideo(searchBar.Text); foreach (string searchResult in videos) { displayOneVideo(new SearchResultObject(indexing++, searchResult)); } } }