Cleanup sxmo_youtube.sh, shellcheck, indent properly, and remove unused cndtn

master
Miles Alan 4 years ago
parent e424bfe85b
commit f57cc7db8b
  1. 46
      scripts/appscripts/sxmo_youtube.sh

@ -4,29 +4,29 @@ NRESULTS=5
AUDIOONLY=0 AUDIOONLY=0
jsonfieldextract() { jsonfieldextract() {
FIELDNAME="$1" FIELDNAME="$1"
TYPE="$2" TYPE="$2"
# TODO: be less lazy and use a JSON parser, need to add json2tsv as dep.. # TODO: be less lazy and use a JSON parser, need to add json2tsv as dep..
if [ "$TYPE" = "number" ]; then if [ "$TYPE" = "number" ]; then
GREPED="$(grep -oE '"'"$FIELDNAME"'"[ ]*:[ ]*[0-9+]+[ ]*,')" GREPED="$(grep -oE '"'"$FIELDNAME"'"[ ]*:[ ]*[0-9+]+[ ]*,')"
else else
GREPED="$(grep -oE '"'"$FIELDNAME"'"[ ]*:[ ]*"[^"]+"[ ]*,')" GREPED="$(grep -oE '"'"$FIELDNAME"'"[ ]*:[ ]*"[^"]+"[ ]*,')"
fi fi
echo "$GREPED" | cut -d: -f2- | tr -d '",' | sed -E 's#^[ ]+##' | head -n1 echo "$GREPED" | cut -d: -f2- | tr -d '",' | sed -E 's#^[ ]+##' | head -n1
} }
youtubesearch() { youtubesearch() {
QUERY="$1" QUERY="$1"
NRESULTS="$2" NRESULTS="$2"
RESULTS="$(youtube-dl -j ytsearch"$NRESULTS":"${QUERY}")" RESULTS="$(youtube-dl -j ytsearch"$NRESULTS":"${QUERY}")"
i=1 i=1
while [ $i -lt "$(echo "$NRESULTS" + 1 | bc)" ]; do while [ $i -lt "$(echo "$NRESULTS" + 1 | bc)" ]; do
TITLE="$(echo "$RESULTS" | awk NR==$i | jsonfieldextract fulltitle string)" TITLE="$(echo "$RESULTS" | awk NR==$i | jsonfieldextract fulltitle string)"
URL="$(echo "$RESULTS" | awk NR==$i | jsonfieldextract webpage_url string)" URL="$(echo "$RESULTS" | awk NR==$i | jsonfieldextract webpage_url string)"
DURATION="$(echo "$RESULTS" | awk NR==$i | jsonfieldextract duration number)s" DURATION="$(echo "$RESULTS" | awk NR==$i | jsonfieldextract duration number)s"
echo "$DURATION: $TITLE - $URL" echo "$DURATION: $TITLE - $URL"
i="$(echo $i + 1 | bc)" i="$(echo $i + 1 | bc)"
done done
} }
searchmenu() { searchmenu() {
@ -83,12 +83,6 @@ resultsmenu() {
return return
elif [ "Close Menu" = "$PICKED" ]; then elif [ "Close Menu" = "$PICKED" ]; then
exit 0 exit 0
elif echo $PICKED | grep "Audio & Video or"; then
if [ "$AUDIOONLY" = 0 ]; then
AUDIOONLY=1
else
AUDIOONLY=0
fi
elif [ "$AUDIOONLY" = 1 ]; then elif [ "$AUDIOONLY" = 1 ]; then
URL="$(echo "$PICKED" | awk -F " " '{print $NF}')" URL="$(echo "$PICKED" | awk -F " " '{print $NF}')"
st -e mpv -ao=alsa -v --no-video "$URL" & st -e mpv -ao=alsa -v --no-video "$URL" &

Loading…
Cancel
Save