summaryrefslogtreecommitdiff
path: root/songgrab
diff options
context:
space:
mode:
authorzachir <zachir@librem.one>2022-08-12 04:30:51 -0500
committerzachir <zachir@librem.one>2022-08-12 04:30:51 -0500
commitc4d96716c05c41a3b18f2326cb588cd19246da5f (patch)
treeaa6b16c2e89ee63d37eb05e38577ec0b0bddea59 /songgrab
initial commit
Diffstat (limited to 'songgrab')
-rwxr-xr-xsonggrab105
1 files changed, 105 insertions, 0 deletions
diff --git a/songgrab b/songgrab
new file mode 100755
index 0000000..914a56b
--- /dev/null
+++ b/songgrab
@@ -0,0 +1,105 @@
+#!/sbin/sh
+
+# check flags
+for i in $@; do
+ case "$i" in
+ "-"*) unset GETARTIST GETALBUM GETTITLE
+ esac
+ [ -n "$GETURL" ] && URL="$i" && unset GETURL
+ [ -n "$GETARTIST" ] && ARTIST="$ARTIST $i"
+ [ -n "$GETALBUM" ] && ALBUM="$ALBUM $i"
+ [ -n "$GETTITLE" ] && TITLE="$TITLE $i"
+ [ -n "$GETTRACKNUM" ] && TRACKNUM="$i" && unset GETTRACKNUM
+ [ -n "$GETYEAR" ] && YEAR="$i" && unset GETYEAR
+ case "$i" in
+ "-s")
+ SPLITTER_SELECTION="s"
+ ;;
+ "-l")
+ SPLITTER_SELECTION="a"
+ ;;
+ "-p")
+ SPLITTER_SELECTION="p"
+ ;;
+ "-u")
+ GETURL="y"
+ ;;
+ "-a")
+ GETARTIST="y"
+ ;;
+ "-A")
+ GETALBUM="y"
+ ;;
+ "-t")
+ GETTITLE="y"
+ ;;
+ "-T")
+ GETTRACKNUM="y"
+ ;;
+ "-y")
+ GETYEAR="y"
+ ;;
+ esac
+done
+
+ARTIST=`echo $ARTIST | sed 's/^ //'`
+ALBUM=`echo $ALBUM | sed 's/^ //'`
+TITLE=`echo $TITLE | sed 's/^ //'`
+echo "Artist: $ARTIST
+Album: $ALBUM
+Song: $TITLE
+Number: $TRACKNUM
+Year: $YEAR"
+
+# prompt to determine later tagging
+if [ -z "$SPLITTER_SELECTION" ]; then
+ echo -n "Will the link be for a [p]laylist, a[l]bum video, or [s]ong video? "
+ read SPLITTER_SELECTION
+ echo ""
+fi
+
+# prompt to get the URL
+if [ -z "$URL" ]; then
+ echo -n "Enter the link: "
+ read URL
+ echo ""
+fi
+
+# if song, don't download playlist
+if [ "$SPLITTER_SELECTION" = "s" ]; then
+ SPLITTER_FLAGS="--no-playlist"
+fi
+
+# download the video(s)
+ls | grep -q "$(echo $URL | cut -d'=' -f2 | cut -d'&' -f1)" && echo "Already downloaded" || youtube-dl $SPLITTER_FLAGS --format bestaudio --restrict-filenames "$URL"
+
+# while loop to remove files from list
+while true; do
+ ls | nl
+ echo -n "Enter the line number: "
+ read WHILE_RESPONSE
+ [ -z "$WHILE_RESPONSE" ] && break
+ rm -rf `ls | head -n "$WHILE_RESPONSE" | tail -1`
+done
+
+# convert the m4a files to mp3
+for i in `ls *.m4a *.webm`; do
+ imp3=`echo "$i" | sed 's/\.m4a$/.mp3/;s/\.webm$/.mp3/'`
+ [ ! -f "$imp3" ] && ffmpeg -i "$i" -acodec mp3 "$imp3" || echo "File not converted"
+done
+
+# 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
+for i in `ls *.mp3`; do
+ tagmp3 $FLAGS "$i"
+done