From 63c500e9d5a060e7ef56decc9b0fdff0e1f59c01 Mon Sep 17 00:00:00 2001 From: Colin P. McCabe Date: Wed, 4 Jan 2023 06:43:06 -0800 Subject: [PATCH] add mtube.sh --- mtube.sh | 21 +++++++++++++++++++++ 1 files changed, 21 insertions(+), 0 deletions(-) create mode 100755 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" -- 1.6.6.rc1.39.g9a42