commit 5ab43a88657c41eab6130a55e15d336ddf0ae8ff parent 2c594366add68f26fcd1b059bf9569a12bade763 Author: Wim Dupont <wim@wimdupont.com> Date: Sat, 25 Feb 2023 10:55:57 +0100 dl-album rename and switch to yt-dlp for speed Diffstat:
M | README.adoc | | | 4 | ++-- |
D | bin/dl-album | | | 90 | ------------------------------------------------------------------------------- |
A | bin/ytd-album | | | 92 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
3 files changed, 94 insertions(+), 92 deletions(-)
diff --git a/README.adoc b/README.adoc @@ -86,13 +86,13 @@ Uses yt-dlp to easily download videos from youtube. Has options for audio-only f * yt-dlp (https://github.com/yt-dlp/yt-dlp) -== ./bin/dl-album +== ./bin/ytd-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. .Requires: -* youtube-dl (https://github.com/ytdl-org/youtube-dl) +* yt-dlp (https://github.com/yt-dlp/yt-dlp) * ffmpeg (https://git.ffmpeg.org/ffmpeg.git) * id3 (https://github.com/squell/id3) diff --git a/bin/dl-album b/bin/dl-album @@ -1,90 +0,0 @@ -#!/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/bin/ytd-album b/bin/ytd-album @@ -0,0 +1,92 @@ +#!/bin/bash + +#requires yt-dlp 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 && yt-dlp -x -f bestaudio -i -o "%(playlist_index)s - %(title)s.%(ext)s" "$URL" + +#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