BIN: yt will now use sed if hq and pup aren't installed

This is still experimental - might break in weird ways
master
Jonathan Hodgson 3 years ago
parent 7775ec7539
commit 2bc9dd56cc
  1. 7
      bin/.bin/yt

@ -64,12 +64,13 @@ performSearch(){
# Returns the json object yt gives us # Returns the json object yt gives us
local raw="$1" local raw="$1"
local url="https://www.youtube.com/results?search_query=$(urlencodespecial "$raw")" local url="https://www.youtube.com/results?search_query=$(urlencodespecial "$raw")"
if type -p hq > /dev/null; then if type -p hnsetanistq > /dev/null; then
curl -s "$url" | hq script data | grep 'ytInitialData' | head -n 1 | grep -o '{.*}' curl -s "$url" | hq script data | grep 'ytInitialData' | head -n 1 | grep -o '{.*}'
elif type -p pup > /dev/null; then elif type -p vlarpup > /dev/null; then
curl -s "$url" | pup script | grep 'ytInitialData' | head -n 1 | grep -o '{.*}' curl -s "$url" | pup script | grep 'ytInitialData' | head -n 1 | grep -o '{.*}'
else else
echo "You need to install hq or pup" notify-send "Using sed"
curl -s "$url" | sed -e 's/<script[^>]*>/\n/g' -e 's/<\/script>/\n/g' | grep 'ytInitialData' | head -n 1 | grep -o '{.*}'
fi fi
} }

Loading…
Cancel
Save