From: Colin P. McCabe Date: Wed, 4 Jan 2023 14:43:06 +0000 (-0800) Subject: add mtube.sh X-Git-Url: http://club.cc.cmu.edu/~cmccabe/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=63c500e9d5a060e7ef56decc9b0fdff0e1f59c01;p=cmccabe-bin add mtube.sh --- diff --git a/mtube.sh b/mtube.sh new file mode 100755 index 0000000..2343649 --- /dev/null +++ b/mtube.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +die() { + echo $@ + exit 1 +} + +MTUBE_ARGS=$@ +MTUBE_DIR="./mtube-$$" +ABSPATH_MTUBE_DIR="$(pwd)/${MTUBE_DIR}" +mkdir "${MTUBE_DIR}" || die "failed to mkdir ${MTUBE_DIR}" +trap "rm -rf -- \"${ABSPATH_MTUBE_DIR}\"" EXIT +pushd "${MTUBE_DIR}" || die "failed to pushed ${MTUBE_DIR}" +youtube-dl -f bestaudio -- ${MTUBE_ARGS} || die "youtube-dl failed" +music-to-mp3.sh * || die "music-to-mp3.sh failed" +shopt -s extglob +rm !(*.mp3) || die "rm of non-mp3 files failed" +set -x +mv *.mp3 .. +set +x +popd || die "failed to popd"