8

I've been trying to make a simple app that can take a list of youtube URLs and download them as MP3s to a specified folder. However, it's not downloading the files. (I used to be alright at this but I guess the lack of practice over the summer has ruined it)

First of all, the code: https://gist.github.com/ericBG/159debbcdb606647afb8 (I know it's not exactly minimal but its quite small anyways and I'm not too sure where the problem lies)

So, what happens is, it's meant to have some output something like:

Enter folder path where you would like output .mp3 files to be saved:
G:\MusicTemp
Enter any youtube videos you would like downloaded:
https://www.youtube.com/watch?v=N6eUF30HXWY
API requested for http://youtube.com/watch?v=N6eUF30HXWY
Downloading API response for http://youtube.com/watch?v=N6eUF30HXWY
Song requested for http://youtube.com/watch?v=N6eUF30HXWY
Completed download.
Enter any youtube videos you would like downloaded:

(the video is just the shortest video I easily found btw) and the file downloaded as "Video Title".mp3 at the path.

What happens is this however:

Enter folder path where you would like output .mp3 files to be saved:
G:\MusicTemp
Enter any youtube videos you would like downloaded:
https://www.youtube.com/watch?v=N6eUF30HXWY
API requested for http://youtube.com/watch?v=N6eUF30HXWY
Downloading API response for http://youtube.com/watch?v=N6eUF30HXWY
Completed download.
Enter any youtube videos you would like downloaded:

and the file is not at the path.

I have a feeling this is due to some of my async programming. However, I am not sure how to debug this, as I do not know which tools let me step through and see where I've gone wrong, and then correct . Would the VS Community debugger let me debug this code well? Thank you!

12
  • Do you get any exception? Do you have write permission for the directory? Commented Sep 8, 2015 at 11:21
  • How did you create the existing code? What IDE did you use? Commented Sep 8, 2015 at 11:21
  • @ArghyaC No exceptions, just part of the code is skipped. I definitely have write permission for the directory. Commented Sep 8, 2015 at 11:21
  • 1
    @Verarind I am asking how to debug async code because I don't understand how to do it.I know VS Community 2015 has a debugger. Commented Sep 8, 2015 at 11:25
  • 3
    @It'sNotALie. You can debug it like normal code. Set a breakpoint use step into or step over and walk through the code. If you've multiple threads it could be a pain because the debugger jumps from one thread to another. If you only want to debug one thread go to the thread window (debug/windows/threads) find the current one (yello arrow) and freeze all other threads. Commented Sep 8, 2015 at 11:28

2 Answers 2

12

Copy of comment because that's the answer to the question (not the code problem solution):

You can debug it like normal code. Set a breakpoint use step into or step over and walk through the code. If you've multiple threads it could be a pain because the debugger jumps from one thread to another. If you only want to debug one thread go to the thread window (debug/windows/threads) find the current one (yello arrow) and freeze all other threads.

Sign up to request clarification or add additional context in comments.

Comments

1

There was likely an error in saving or downloading the file, but you are not checking for it.

The code:

.ContinueWith(t => Console.WriteLine("Completed download.")));

should check if the antecedent taks has an error.

.ContinueWith(t => 
              {
                 if(t.Exception != null)
                 {
                    // log error
                 }
                 else
                 {
                    Console.WriteLine("Completed download.")));
                 });

The external task added to the list represents the completion of the continuation so it will succeed even if the download failed.

2 Comments

This looks like the solution for the problem that the program has. The question is how to debug it.
It has an exception. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.