commit 6de91407008983a8a215a44529ba2340663227ce parent 5b692235713323c556ee99cc51cbbb6daad0fcb5 Author: Anders Damsgaard <anders@adamsgaard.dk> Date: Wed, 20 Jun 2018 10:06:38 -0400 Use single script for youtube-dl-music Diffstat:
D | links/bin/youtube-dl-music-playlist.sh | | | 81 | ------------------------------------------------------------------------------- |
M | links/bin/youtube-dl-music.sh | | | 53 | ++++++++++++++++++++++++++++++++++++++--------------- |
2 files changed, 38 insertions(+), 96 deletions(-)
diff --git a/links/bin/youtube-dl-music-playlist.sh b/links/bin/youtube-dl-music-playlist.sh @@ -1,81 +0,0 @@ -#!/bin/bash -set -e -set -u - -read -p "torify? [Y/n] " -n 1 -r -echo -if [[ $REPLY =~ ^[Nn]$ ]]; then - prefix="" -else - prefix="torify" -fi - -outputdir=$TMPDIR/ytdl-playlist -mkdir -p "$outputdir" -cd "$outputdir" - -$prefix youtube-dl \ - --format bestaudio \ - --extract-audio \ - --audio-quality 0 \ - --audio-format mp3 \ - --output "%(playlist_index)s-%(title)s.%(ext)s" \ - "$1" - -read -p "add metadata? [y/N] " -n 1 -r -echo -if [[ $REPLY =~ ^[Yy]$ ]]; then - - artist="Unknown Artist" - album="Unknown Album" - track=1 - - # Loop over files with spaces - SAVEIFS=$IFS - IFS=$(echo -en "\n\b") - for f in *.mp3; do - - echo -e "\033[0;31m$f\033[0m" - - song=$(echo "$f" | sed 's/.*-//' | sed 's/^ //' | sed 's/\.mp3//') - read -r -p "song [$song]: " input - song="${input:-$song}" - - read -r -p "track [$track]: " input - track="${input:-$track}" - - read -r -p "album [$album]: " input - album="${input:-$album}" - - read -r -p "artist [$artist]: " input - artist="${input:-$artist}" - - id3v2 --artist "$artist" --album "$album" \ - --song "$song" --track "$track" \ - "$f" - (( track += 1 )) - done - # Revert default behavior - IFS=$SAVEIFS - - read -p "move to music folder? [y/N] " -n 1 -r - echo - if [[ $REPLY =~ ^[Yy]$ ]]; then - - if [[ "$(uname)" == 'Darwin' ]]; then - musicroot="$HOME/Music/iTunes/iTunes Media/Music/" - else - musicroot="$HOME/music/" - fi - - outdir="$musicroot/$artist/$album" - mkdir -p "$outdir" - mv ./*.mp3 "$outdir" - - echo "updating mpd" - mpc update > /dev/null - - rmdir "$outputdir" - cd - - fi -fi diff --git a/links/bin/youtube-dl-music.sh b/links/bin/youtube-dl-music.sh @@ -10,33 +10,53 @@ else prefix="torify" fi +outputdir=$TMPDIR/ytdl-playlist +mkdir -p "$outputdir" +cd "$outputdir" + $prefix youtube-dl \ --format bestaudio \ --extract-audio \ --audio-quality 0 \ --audio-format mp3 \ + --output "%(playlist_index)s-%(title)s.%(ext)s" \ "$1" read -p "add metadata? [y/N] " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]]; then - filename=$(youtube-dl \ - --get-filename \ - --format bestaudio \ - --extract-audio \ - --audio-quality 0 \ - --audio-format mp3 \ - "$1") - filename=$(echo "$filename" | sed "s/\..*$/.mp3/") + artist="Unknown Artist" + album="Unknown Album" + track=1 + + # Loop over files with spaces + SAVEIFS=$IFS + IFS=$(echo -en "\n\b") + for f in *.mp3; do + + echo -e "\033[0;31m$f\033[0m" + + song=$(echo "$f" | sed 's/.*-//' | sed 's/^ //' | sed 's/\.mp3//') + read -r -p "song [$song]: " input + song="${input:-$song}" - read -r -p "artist: " artist - read -r -p "album: " album - read -r -p "song: " song - read -r -p "track [e.g. 01]: " track + read -r -p "track [$track]: " input + track="${input:-$track}" - id3v2 --artist "$artist" --album "$album" --song "$song" --track "$track" \ - "$filename" + read -r -p "album [$album]: " input + album="${input:-$album}" + + read -r -p "artist [$artist]: " input + artist="${input:-$artist}" + + id3v2 --artist "$artist" --album "$album" \ + --song "$song" --track "$track" \ + "$f" + (( track += 1 )) + done + # Revert default behavior + IFS=$SAVEIFS read -p "move to music folder? [y/N] " -n 1 -r echo @@ -50,9 +70,12 @@ if [[ $REPLY =~ ^[Yy]$ ]]; then outdir="$musicroot/$artist/$album" mkdir -p "$outdir" - mv "$filename" "$outdir/$song.mp3" + mv ./*.mp3 "$outdir" echo "updating mpd" mpc update > /dev/null + + rmdir "$outputdir" + cd - fi fi