Search code examples
terminalyoutube-dl

youtube_dl: Download files synchronously via terminal


I'm using the linux terminal to download files using youtube_dl.

youtube-dl <link>

However, the file is downloaded asynchronously.

Is there a simple way to have the above command block until download is complete. (The other way would have been to check for downloaded file creation)


Solution

  • My crystal ball tells me that your URL contains ampersands, like https://www.youtube.com/watch?v=BaW_jenozKc&t=1s&end=9. In a shell, the ampersand makes the program run in the background (asynchronously).

    Escape ampersands in URLs, by putting the whole URL in quotes:

    youtube-dl 'https://www.youtube.com/watch?v=BaW_jenozKc&t=1s&end=9'
    

    On Windows cmd, use double quotes instead:

    youtube-dl "https://www.youtube.com/watch?v=BaW_jenozKc&t=1s&end=9"
    

    Alternatively, escsape all problematic characters. Consult your shell handbook on which characters have special meanings and how to escape them. Oftentimes, a backslash will work:

     youtube-dl https://www.youtube.com/watch?v=BaW_jenozKc\&t=1s\&end=9