5 C
Texas
Chrishttp://www.osradar.com
Chris is the Chairman and CEO of GC Media Publishing Management, Business Principal of Freedom Publishers Union and Editor of Tecseek Technology. Chris is also a public advocate for Creative Commons and Tor Project.

Write a Bash Script to Queue Links for youtube-dl

Most people use YouTube. However, if you are like me and don’t like streaming your digital content and instead prefer to have raw media files available on your hard disk which can be played back at much better quality than streaming services offer on unstable or slow internet connections, then you are probably already using the popular youtube-dl tool to download digital content from YouTube.

youtube-dl allows a user to download video and audio (or split the audio/video into separate files) from YouTube links by simply pasting the shared URL into the terminal console following the youtube-dl syntax. That’s the easy part. But what do you do if you have more than one or two links?

Sometimes when I am browsing YouTube I collect a bunch of links which I want to download. Sometimes this can be 3-5 links, or sometimes I can end up with an extensive list of 10 or more which I had not originally intended. It can be time consuming manually pasting in links then waiting for each download to complete before pasting in the next link and repeating the process. Thankfully, there is an easier way to do it by writing a neat little Bash script.

Let’s get started.

- Advertisement -

For example purposes, we will use the following fake randomly generated links to download:

https://youtu.be/ACcLsrbigWu
https://youtu.be/BAbg6BnkB3F
https://youtu.be/l0eRloaKxVS

So let’s write ourselves a neat little Bash script to deal with these links, using a combination of Bash and youtube-dl.

I use Emacs for this kind of short-style scripting, but feel free to use whatever code editor you prefer. Let’s just call our script something easy, like “yt-queue.sh”:

> emacs yt-queue.sh

Then in your code editor, enter the following syntax:

#!/bin/bash
#

#start
#links
#end

This provides a basic and sensible script layout for your youtube-dl queue.

Where we have “#links”, press “ENTER” at the end of the line so we get a new blank line. Now we need to paste in the links to download. But remember to write “youtube-dl” before each link. This is effectively telling the Bash script to use youtube-dl to download the link that follows. Once one link has completed downloading, the script then passes onto the next line in the queue, and then the next and so forth. Stupidly simple, yet effective.

After pasting in the links, the script should look something like this:

#!/bin/bash
#

#start
#links
youtube-dl https://youtu.be/ACcLsrbigWu
youtube-dl https://youtu.be/BAbg6BnkB3F
youtube-dl https://youtu.be/l0eRloaKxVS
#end

The script is finished. Now we need to just execute it when we are ready to start it.

This process is particularly useful for downloading extensive lists which can be done overnight – write your script before you go to bed, execute the script and by the morning your files will be completed.

Execute the script by simply running the following:

> bash yt-queue.sh

You have now learned how to write a simple Bash script to queue links for youtube-dl.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

1 COMMENT

  1. Absolutely brilliant, I was hunting around for a bash script to read from a separate file! Shockingly straightforward. Thanks!

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article