Repeat Bash Prompts

By  on  

I'm sure you wont be surprised when I tell you it's my job to automate things in our my household.  My wife is tech savvy but she relies on me to make tech matters easy for everyone; I guess it's flattering that she trusts me to do that.  One easy task she's trusted me with is make it easy to grab music from YouTube so she can put it on her phone or rock to on AudioShield.  I could probably point her to numerous sites that do that conversion but most are filled with disgusting ads and malware.  Since I love youtube-dl, I set out to create a bash script my wife could use to download as much music as she wanted!

Almost a decade ago I wrote about using a text file to download with youtube-dl but even that's a bit annoying for most people.  I could make a web interface but that seemed like too much I created a bash script to repeatedly ask for a YouTube link which to download and convert to MP3:

while true; do
    read -p "What is the YouTube link? " answer
    youtube-dl --extract-audio --audio-format mp3 $answer
done;

The script repeatedly asks for a YouTube link, downloads and converts to mp3, then asks for YouTube link again.  I created a desktop shortcut for this script to make usage even easier.  An easy script to make music download easy!

Of course the script could use some validation (i.e. that it's a link from YouTube) but I trust that we'll paste a valid link.  The key takeaway is that while true; do ...done will allow you to create repeated loop in a bash script!

Recent Features

  • By
    5 Ways that CSS and JavaScript Interact That You May Not Know About

    CSS and JavaScript:  the lines seemingly get blurred by each browser release.  They have always done a very different job but in the end they are both front-end technologies so they need do need to work closely.  We have our .js files and our .css, but...

  • By
    5 HTML5 APIs You Didn’t Know Existed

    When you say or read "HTML5", you half expect exotic dancers and unicorns to walk into the room to the tune of "I'm Sexy and I Know It."  Can you blame us though?  We watched the fundamental APIs stagnate for so long that a basic feature...

Incredible Demos

  • By
    Animated AJAX Record Deletion Using MooTools

    I'm a huge fan of WordPress' method of individual article deletion. You click the delete link, the menu item animates red, and the item disappears. Here's how to achieve that functionality with MooTools JavaScript. The PHP - Content & Header The following snippet goes at the...

  • By
    Create a 3D Panorama Image with A-Frame

    In the five years I've been at Mozilla I've seen some awesome projects.  Some of them very popular, some of them very niche, but none of them has inspired me the way the MozVR team's work with WebVR and A-Frame project have. A-Frame is a community project...

Discussion

  1. test
    
    
    • test

      adsadsad

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!