From 7e8764ddb88f62c436f88b8d6aa835f6475f538f Mon Sep 17 00:00:00 2001 From: Jade Levesque Date: Sun, 19 Feb 2017 13:06:56 -0600 Subject: [PATCH] Better arg handling yt-meta --- lib/yt-meta | 75 ++++++++++++++++++++++++++++++++--------------------- shelltube | 48 ++++++++++++++++++++++++---------- 2 files changed, 79 insertions(+), 44 deletions(-) diff --git a/lib/yt-meta b/lib/yt-meta index 0e91e91..9f4d9fd 100755 --- a/lib/yt-meta +++ b/lib/yt-meta @@ -15,35 +15,45 @@ optnum=0 for argument in $@ do - case $argument in - -c) - options="$options c" - optnum=$((optnum+1)) - ;; - -d) # duration - options="$options d" - optnum=$((optnum+1)) - ;; - -D) # date - options="$options D" - optnum=$((optnum+1)) - ;; - -v) - options="$options v" - optnum=$((optnum+1)) - ;; - -t) - options="$options t" - optnum=$((optnum+1)) - ;; - *) + if echo $argument | grep "^-" > /dev/null + then + charcount=$(echo "$argument" | echo "$(wc -c) - 1" | bc) + while [ $charcount -gt 0 ] + do + character=$(echo "$argument" | head -c1) + argument=$(echo "$argument" | sed 's/^.//') + case $character in + c) + options="$options c" + optnum=$((optnum+1)) ;; + d) # duration + options="$options d" + optnum=$((optnum+1)) ;; + D) # date + options="$options D" + optnum=$((optnum+1)) ;; + v) + options="$options v" + optnum=$((optnum+1)) ;; + t) + options="$options t" + optnum=$((optnum+1)) ;; + i) + options="$options i" + optnum=$((optnum+1)) ;; + -) ;; + esac + charcount=$((charcount-1)) + done + else preid="$argument" - esac -done - -if echo "$preid" | grep "youtube.com" + fi +done + + +if echo "$preid" | grep "youtube.com" > /dev/null then - id="$(echo $1 | sed 's/.*video_id=//')" + id="$(echo $preid | sed 's/.*v=//')" elif [ -z $preid ] then echo "No video specified." @@ -81,8 +91,11 @@ author="$(grep "\"author\":\"" $video_file | sed 's/.*"author":"//' | sed 's/".* views="$(grep "\"view_count\":\"" $video_file | sed 's/.*"view_count":"//' | sed 's/".*//')" duration="$(grep " /tmp/yt-queue.tmp + itemid="$(echo "$LINE" | sed 's/.*\| //')" + echo $itemid + sleep 3 + yt-down -D "$itemid" + grep -v "$itemid" /tmp/yt-queue > /tmp/yt-queue.tmp mv /tmp/yt-queue.tmp /tmp/yt-queue done ;; squeue | sq ) for LINE in $(cat /tmp/yt-queue) do - yt-down -S "$LINE" - grep -v "$LINE" /tmp/yt-queue > /tmp/yt-queue.tmp + itemid="$(echo "$LINE" | sed 's/.*| //')" + echo $itemid + sleep 3 + yt-down -S "$itemid" + grep -v "$itemid" /tmp/yt-queue > /tmp/yt-queue.tmp mv /tmp/yt-queue.tmp /tmp/yt-queue done ;;