#!/bin/bash 

# download one mp3 
# more options? see e.g. https://ostechnix.com/youtube-dl-tutorial-with-examples-for-beginners/

if [ "1" -ne "$#" ] # only one
then
  echo use: $0 https://url
  exit 1
fi

BIN=$( /usr/bin/which youtube-dl )

if [ -x ${BIN} ]
then 
  ${BIN} -x --audio-format mp3 "$1"
else
  echo ${0}: command youtube-dl not found from PATH
fi

# some cleaning for file names?
# for i in *mp3; do n=$( echo $i | tr ' ' _ | tr -d \' | perl -pe 's,\(.*?\),,g; s,\[.*?\],,' ) ; mv "$i" "$n" ; done

# macOS and MacPorts?
# port install ffmpeg +nonfree
# port install youtube-dl

# only a part?
# youtube-dl --external-downloader ffmpeg --external-downloader-args "-ss 00:01:00.00 -to 00:02:00.00" -f best "https://www...
# https://ostechnix.com/download-a-portion-of-youtube-video-with-youtube-dl-and-ffmpeg/
