diff options
Diffstat (limited to 'songgrab')
-rwxr-xr-x | songgrab | 58 |
1 files changed, 29 insertions, 29 deletions
@@ -1,7 +1,7 @@ #!/bin/sh # check flags -for i in $@; do +for i; do case "$i" in "-"*) unset GETARTIST GETALBUM GETTITLE esac @@ -55,16 +55,16 @@ for i in $@; do esac done -ARTIST=`echo $ARTIST | sed 's/^ //'` -ALBUM=`echo $ALBUM | sed 's/^ //'` -TITLE=`echo $TITLE | sed 's/^ //'` +ARTIST="$(echo "$ARTIST" | sed 's/^ //')" +ALBUM="$(echo "$ALBUM" | sed 's/^ //')" +TITLE="$(echo "$TITLE" | sed 's/^ //')" printf "Received Tags: -Artist: $ARTIST -Album: $ALBUM -Song: $TITLE -Number: $TRACKNUM -Year: $YEAR\n\n" +Artist: %s +Album: %s +Song: %s +Number: %s +Year: %s\n\n" "$ARTIST" "$ALBUM" "$TITLE" "$TRACKNUM" "$YEAR" notify-send "songgrab started" "Received Tags: Album: $ALBUM @@ -76,44 +76,50 @@ printf "\n" # prompt to determine later tagging if [ -z "$SPLITTER_SELECTION" ]; then printf "Will the link be for a [p]laylist, a[l]bum video, or [s]ong video? " - read SPLITTER_SELECTION + read -r SPLITTER_SELECTION printf "\n" fi # prompt to get the URL if [ -z "$URL" ]; then printf "Enter the link: " - read URL + read -r URL printf "\n" fi # if song, don't download playlist if [ "$SPLITTER_SELECTION" = "s" ]; then - SPLITTER_FLAGS="--no-playlist" + NO_PLAYLIST="yes" fi # download the video(s) notify-send "songgrab" "Starting download..." printf "Starting download..." -ls | grep -q "$(echo $URL | cut -d'=' -f2 | cut -d'&' -f1)" && echo "Already downloaded" || yt-dlp $SPLITTER_FLAGS --format bestaudio --restrict-filenames "$URL" +MATCHSTRING="$(echo "$URL" | cut -d'=' -f2 | cut -d'&' -f1)" +for file in ./*; do + case "$file" in + *${MATCHSTRING}*) true ;; + *) yt-dlp ${NO_PLAYLIST:+"--no-playlist"} --format bestaudio --restrict-filenames "$URL" ;; + esac +done notify-send "songgrab" "Download stopped." printf "Download stopped." # while loop to remove files from list printf "Do you want to remove any tracks?\n\n" while true; do - ls | nl - echo -n "Enter the line number: " - read WHILE_RESPONSE + find ./* | nl + printf "Enter the line number: " + read -r WHILE_RESPONSE [ -z "$WHILE_RESPONSE" ] && break - rm -rf `ls | head -n "$WHILE_RESPONSE" | tail -1` + rm -rf "$(find . | head -n "$WHILE_RESPONSE" | tail -1)" done # convert the downloaded files to mp3 printf "Starting to convert files..." notify-send "songgrab" "Starting to convert files..." -for i in `ls *.m4a *.webm`; do - imp3=`echo "$i" | sed 's/\.m4a$/.mp3/;s/\.webm$/.mp3/'` +for i in *.m4a *.webm; do + imp3=$(echo "$i" | sed 's/\.m4a$/.mp3/;s/\.webm$/.mp3/') notify-send "songgrab" "Converting $i to $imp3" [ ! -f "$imp3" ] && ffmpeg -i "$i" -acodec mp3 "$imp3" || echo "File not converted" done @@ -123,19 +129,13 @@ notify-send "songgrab" "Finished converting files." # fix names for suggestions vimv -# determine tagmp3 flags -FLAGS="" -[ -n "$ARTIST" ] && FLAGS="$FLAGS -a $ARTIST" -[ -n "$ALBUM" ] && FLAGS="$FLAGS -A $ALBUM" -[ -n "$TITLE" ] && FLAGS="$FLAGS -t $TITLE" -[ -n "$TRACKNUM" ] && FLAGS="$FLAGS -T $TRACKNUM" -[ -n "$YEAR" ] && FLAGS="$FLAGS -y $YEAR" - # tag songs with tagmp3 notify-send "songgrab" "Tagging songs..." printf "Tagging songs..." -for i in `ls *.mp3`; do - tagmp3 $FLAGS "$i" +for i in *.mp3; do + tagmp3 ${ARTIST:+"-a"} ${ARTIST:+"$ARTIST"} ${ALBUM:+"-A"} ${ALBUM:+"$ALBUM"} \ + ${TITLE:+"-t"} ${TITLE:+"$TITLE"} ${TRACKNUM:+"-T"} ${TRACKNUM:+"$TRACKNUM"} \ + ${YEAR:+"-y"} ${YEAR:+"$YEAR"} "$i" done notify-send "songgrab" "Done." printf "Done.\n\n" |