Skip to content

Instantly share code, notes, and snippets.

@LuchoLopez
Created March 14, 2024 16:04
Show Gist options
  • Save LuchoLopez/99e1856e99fb3486588f89da69dfc0fa to your computer and use it in GitHub Desktop.
Save LuchoLopez/99e1856e99fb3486588f89da69dfc0fa to your computer and use it in GitHub Desktop.
Download MP3 music from YT
#!/bin/bash
# Please, make sure you have: python3, pytube and ffmpeg before running this script
DOWNLOAD_DIR="./downloads"
mkdir -p "${DOWNLOAD_DIR}"
pytube3 -a mp4 -t "${DOWNLOAD_DIR}" "${1}"
pushd "${DOWNLOAD_DIR}"
find . -type f -iname '*.mp4' -exec sh -c 'ffmpeg -i "$1" "${1%.*}.mp3"' sh {} \;
find . -type f -iname '*.mp4' -exec rm {} \+
popd
ls "${DOWNLOAD_DIR}"
@LuchoLopez
Copy link
Author

LuchoLopez commented Mar 14, 2024

Usage:

Single video:

bash yt-download.sh 'https://www.youtube.com/watch?v=pAgnJDJN4VA'

Playlists:

bash yt-download.sh  'https://www.youtube.com/playlist?list=PL6Lt9p1lIRZ311J9ZHuzkR5A3xesae2pk'

NOTE: Please, note that I made some changes to the original link (https://www.youtube.com/watch?v=kXYiU_JCYtU&list=PL6Lt9p1lIRZ311J9ZHuzkR5A3xesae2pk). Replace watch? with playlist? and remove the v=...& parameter

2024-03-14_13-13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment