Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Bash – Download YouTube Music

Posted on August 7, 2018June 30, 2019 By David Kittell
sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl
sudo apt update
sudo apt upgrade -y
sudo apt install youtube-dl python ffmpeg net-tools -y

# Install YouTube Downloader CLI
brew install youtube-dl ffmpeg

# https://github.com/rg3/youtube-dl
# Download YouTube video, convert the video to MP3 and delete the original video
youtube-dl -i -f mp4 -x --audio-format mp3 --audio-quality 0 https://www.youtube.com/watch?v=A9XtDyDUjIU

# Download YouTube video, convert the video to MP3 and keep the original video as MP4 format
youtube-dl -k -i -f mp4 -x --audio-format mp3 --audio-quality 0 https://www.youtube.com/watch?v=A9XtDyDUjIU

# Download YouTube video as MP4 format
youtube-dl -i -f mp4 https://www.youtube.com/watch?v=A9XtDyDUjIU

Alternate option, read a text file.

#!/bin/bash

while IFS='' read -r line || [ -n "$line" ]; do
    echo "Downloading $line"
    youtube-dl -i -f mp4 -k -x --audio-format mp3 --audio-quality 0 $line
done < "$1"

#youtube-dl -i -f mp4 --yes-playlist $1

# -i, --ignore-errors
# -f, --format
# -x, --extract-audio
# --audio-format
# --yes-playlist
# -k to keep the video

# mkdir music
# mkdir video

count=`ls -1 *.mp3 2>/dev/null | wc -l`
if [ $count != 0 ]
then 
    mv *.mp3 music
fi 

count=`ls -1 *.mp4 2>/dev/null | wc -l`
if [ $count != 0 ]
then 
    mv *.mp4 video
fi

Create a text file with the YouTube links with a line break between each. The links can be a single video or a playlist URL, the downloader will parse the playlist and download each of the videos in the playlist and convert to MP3

sh youtube-dl.sh music.txt
Originally Posted on August 7, 2018
Last Updated on June 30, 2019
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code Debian Raspbian (Raspberry Pi OS) Ubuntu UNIX UNIX Shell Scripts Zorin OS

Post navigation

Previous post
Next post

Related Posts

Page View Details

Posted on July 9, 2013October 26, 2015

DISCLAIMER: Before you put this script in place make sure you have some kind of disclaimer on your site to state what kind of data you record from the visitor. SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[pageview] ( [id] [int] IDENTITY(1, 1)…

Read More

ProgressBar Control

Posted on September 18, 2013October 26, 2015

Imports System Imports System.Collections Imports System.Data Imports System.Drawing Imports System.Windows.Forms Imports System.ComponentModel Imports System.Drawing.Drawing2D Imports System.IO Public Class MainClass Shared Sub Main() Dim form1 As Form = New Form1 Application.Run(form1) End Sub End Class Public Class Progress Inherits System.Windows.Forms.UserControl #Region " Windows Form Designer generated code " Public Sub New()…

Read More

Bash – Trim/Remove White Space

Posted on May 4, 2017August 25, 2019

sed ‘s/^[ \t]*//’ sed ‘s/[ \t]*$//’ sed ‘s/^[ \t]*//;s/[ \t]*$//’ Originally Posted on May 4, 2017Last Updated on August 25, 2019 All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes
 

Loading Comments...
 

You must be logged in to post a comment.