My First Linux Program
Whirltube is the successor to voda (video on demand assistant), a QB64 program I made to interface with youtube-dl on Windows. I was correct about bash syntax being annoying--double brackets? Mandatory white space? Weird equality symbols? "fi"? Ugh--but I made a program.
#!/usr/bin/env bash
#requires: yt-dlp, ffmpeg, VLC
ans=0
while [[ $ans -lt 1 || $ans -gt 3 ]]; do
clear
echo "whirltube 1.0"
echo
echo "1. Download video"
echo "2. Extract Mp3"
echo "3. Play in VLC"
echo
echo -n "Choice? "
read -n 1 ans
done
echo && echo
echo -n "Enter URL: "
read -r url
if [[ $ans -eq 1 ]]; then
yt-dlp $url -S vcodec:h264,fps,res:720,acodec:m4a
exit
elif [[ $ans -eq 2 ]]; then
yt-dlp --audio-format mp3 $url -x
exit
elif [[ $ans -eq 3 ]]; then
yt-dlp -o - --downloader ffmpeg -f "bv*+ba/b" - $url | vlc -
exit
fi
It was frustrating because I didn't know the first line (the "hashbang"1) was necessary. I thought as long as I invoked the program from bash, it would run as a bash script. How silly of me. If that line isn't there, it instead runs in dash, which is like bash but less useful? I discovered this when read -n 1
was throwing an "illegal option" error and it took me some searxing to figure out why. All of the answers said it was because I was using dash, but when I did echo $0
it said I was using bash, so I was stumped. But once I added the hashbang it started working.
I guess once the script starts, it switches from bash to dash unless I tell it not to?? Additionally confusing was the fact that a lot of sources said to use #!/bin/bash
, which didn't work for me. I assume that's the one you're supposed to use with ubuntu, because everyone who's responded to questions about linux since the beginning of time assumes you're using ubuntu. The following is an actual conversation from the year 40,000 BC:
🧔♂️ Bash
What Mash 👴
🧔♂️ Why club no kill food
What you say 👴
🧔♂️ I hit food with club. Food no die
Let me 👴
👴🦴BASH💥🐊
👴🍖 Work for me ubuntu 🧔♂️💢
Anyway, the program does the three things I will ever want to do with yt-dlp without the need to memorize arcane invocations:
- Download a video (max res 720p)
- Extract the audio as an Mp3
- Stream the video in VLC
I'd probably add more options if I thought anyone else would ever want to use it, but this ain't Windows, everyone's got their own stuff figured out. But hey, it works for me and it's still a milestone 🦝
Apr 20 2025
: Whirltube 1.0.4 released. Added option for downloading English subtitles. Added ability to launch with default settings withwt.sh [url]
. Follow project on github for future updates.
The official name for this appears to be "shebang", but come on. "Hashbang" is obviously better.↩