scripts

Scripts
git clone git://git.wimdupont.com/scripts.git
Log | Files | Refs | LICENSE

commit ee85fce4da3afbf83cd6756caae5545e98bcb26b
parent 52f561a1f3fd97be836b9657602a3b5dd0b36c39
Author: Wim Dupont <wim@wimdupont.com>
Date:   Sat, 11 Feb 2023 22:01:40 +0100

rename

Diffstat:
MREADME.adoc | 2+-
Abin/dl-album | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dyt-dl-album.sh | 86-------------------------------------------------------------------------------
3 files changed, 91 insertions(+), 87 deletions(-)

diff --git a/README.adoc b/README.adoc @@ -78,7 +78,7 @@ Uses mpv and youtube-dl to easily look up videos from command-line with an audio * mpv (https://github.com/mpv-player/mpv) * youtube-dl (https://github.com/ytdl-org/youtube-dl) -== ./yt-dl-album.sh +== ./bin/dl-album Used to download full albums by playlist. The script creates a directory with the bandname followed by a directory with albumname in which the playlist is saved as mp3 files. The downloaded audio files also get tagged by id3 to make them easy to sort by on devices such as mp3-players. diff --git a/bin/dl-album b/bin/dl-album @@ -0,0 +1,90 @@ +#!/bin/bash + +#requires youtube-dl ffmpeg id3 + +URL=$1 + +#=== DOWNLOADING + +if [ -z ${URL} ]; then + echo "Paste Youtube URL" + read URL +fi + +mkdir -pv ~/tmp + +mkdir -pv ~/Downloads/tmp + +echo "Downloading $URL in ~/tmp" + +cd ~/Downloads/tmp && youtube-dl -f bestaudio -i -o "%(playlist_index)s - %(title)s.%(ext)s" "$URL" + +#=== DIR SETUP + +echo "What's the band name?" + +read BAND + +echo "What's the album name?" + +read ALBUM + +echo "What's the genre?" + +read GENRE + +if [ -d "$HOME/tmp/$BAND/$ALBUM" ]; then + echo "Album directory already exists - (y) or (yes) to continue." + read ANSWER + if [[ ! $ANSWER =~ ^(y|yes)$ ]]; then + echo "Exiting." + exit 0; + fi +fi + +mkdir -pv "$HOME/tmp/$BAND/$ALBUM" + +DIR=$HOME/tmp/$BAND/$ALBUM + +mv $HOME/Downloads/tmp/* "$DIR" + +rm -rfv $HOME/Downloads/tmp + +echo Converting files to mp3 + +for f in "$DIR"/*; do + if [[ ! $f =~ (.mp3)$ ]]; then + echo "Converting $f" + ffmpeg -loglevel error -i "$f" "${f%.*}.mp3"; + rm "$f" + fi +done + +for f in "$DIR"/*; do + + #remove path to get songname + SONGNAME=$(echo "$f" | sed 's/.*\///g' | sed 's/.mp3//g') + + + TRACK=$(echo $SONGNAME | cut -d ' ' -f 1) + TITLE=$(echo $SONGNAME | sed "s/$TRACK - //g") + + OLDNAME=$SONGNAME + + echo "Type song name for : ${TITLE}" + echo "Enter/Return to keep as is." + + read NEWNAME + + if [[ ! -z $NEWNAME ]]; then + SONGNAME=$NEWNAME; + + echo $OLDNAME to $SONGNAME + + mv "$DIR/$OLDNAME.mp3" "$DIR/$TRACK - $SONGNAME.mp3" + + id3 -t "$SONGNAME" -a "$BAND" -l "$ALBUM" -n $TRACK -g "$GENRE" "$DIR/$TRACK - $SONGNAME.mp3" + else + id3 -t "$TITLE" -a "$BAND" -l "$ALBUM" -n "$TRACK" -g "$GENRE" "$DIR/$SONGNAME.mp3" + fi +done diff --git a/yt-dl-album.sh b/yt-dl-album.sh @@ -1,86 +0,0 @@ -#!/bin/bash - -#requires youtube-dl ffmpeg id3 - -#=== DOWNLOADING -echo "Paste Youtube URL" - -read URL - -mkdir -pv ~/tmp - -mkdir -pv ~/Downloads/tmp - -echo "Downloading $URL in ~/tmp" - -cd ~/Downloads/tmp && youtube-dl -f bestaudio -i -o "%(playlist_index)s - %(title)s.%(ext)s" "$URL" - -#=== DIR SETUP - -echo "What's the band name?" - -read BAND - -echo "What's the album name?" - -read ALBUM - -echo "What's the genre?" - -read GENRE - -if [ -d "$HOME/tmp/$BAND/$ALBUM" ]; then - echo "Album directory already exists - (y) or (yes) to continue." - read ANSWER - if [[ ! $ANSWER =~ ^(y|yes)$ ]]; then - echo "Exiting." - exit 0; - fi -fi - -mkdir -pv "$HOME/tmp/$BAND/$ALBUM" - -DIR=$HOME/tmp/$BAND/$ALBUM - -mv $HOME/Downloads/tmp/* "$DIR" - -rm -rfv $HOME/Downloads/tmp - -echo Converting files to mp3 - -for f in "$DIR"/*; do - if [[ ! $f =~ (.mp3)$ ]]; then - echo "Converting $f" - ffmpeg -loglevel error -i "$f" "${f%.*}.mp3"; - rm "$f" - fi -done - -for f in "$DIR"/*; do - - #remove path to get songname - SONGNAME=$(echo "$f" | sed 's/.*\///g' | sed 's/.mp3//g') - - - TRACK=$(echo $SONGNAME | cut -d ' ' -f 1) - TITLE=$(echo $SONGNAME | sed "s/$TRACK - //g") - - OLDNAME=$SONGNAME - - echo "Type song name for : ${TITLE}" - echo "Enter/Return to keep as is." - - read NEWNAME - - if [[ ! -z $NEWNAME ]]; then - SONGNAME=$NEWNAME; - - echo $OLDNAME to $SONGNAME - - mv "$DIR/$OLDNAME.mp3" "$DIR/$TRACK - $SONGNAME.mp3" - - id3 -t "$SONGNAME" -a "$BAND" -l "$ALBUM" -n $TRACK -g "$GENRE" "$DIR/$TRACK - $SONGNAME.mp3" - else - id3 -t "$TITLE" -a "$BAND" -l "$ALBUM" -n "$TRACK" -g "$GENRE" "$DIR/$SONGNAME.mp3" - fi -done