diff --git a/.aliases b/.aliases index 170a93a..74b5184 100644 --- a/.aliases +++ b/.aliases @@ -580,11 +580,45 @@ download_youtube_uploads_list() { } function download_youtube_audio() { - if [[ $1 == "" ]]; then - error "Usage: " + local make_folder="$1" + local url="$2" + shift 2 + local opts="$@" + + if [[ $url == "" ]]; then + error "Usage: " return fi - yt-dlp.exe -f "140" "$1" + + printf "${BOLD}Downloading Youtube audio\n\n${NORMAL}" + + if [[ $make_folder == "1" ]]; then + make_vid_dir_and_cd_into $url "" + if [[ $? -ne 0 ]]; then + return + fi + fi + + local format="140" + local name_format="%(upload_date>%Y-%m-%d)s-%(title)s-yt-%(id)s" + + # Get the audio filename. + local filename=$(yt-dlp.exe --get-filename -f $format -o "$name_format.%(ext)s" $opts $url) + printf "filename: $filename\n" + + local cmd="yt-dlp.exe -f $format -o \"$filename\" $opts $url" + eval $cmd # Need to eval in order to preserve the quotes wrapping the filename format string. + error=$? + + if [[ $error -ne 0 ]]; then + error "Error: Failed to download '$url'" + if [[ $make_folder == "1" ]]; then cd ..; fi + return + fi + + if [[ $make_folder == "1" ]]; then cd ..; fi + + printf "${BOLD}Finished downloading ${YELLOW}$filename${NORMAL}\n" } # Download Twitch chat transcript @@ -1030,6 +1064,7 @@ alias yt-playlist-1440='download_youtube_playlist "620+140"' alias yt-playlist-1080='download_youtube_playlist "137+140"' alias yt-playlist-720='download_youtube_playlist "136+140"' alias yt-playlist-tiny='download_youtube_playlist "160+140"' +#--------------------------- alias yt-audio='download_youtube_audio' #-------------------------------------------------