Add invcli.

This commit is contained in:
Mid Favila 2021-10-16 19:55:03 -03:00
parent 9f1336dd5a
commit af04269920
2 changed files with 64 additions and 0 deletions

1
README
View File

@ -12,3 +12,4 @@ modem-manager - used to manage laptop PCIe WAN modems. rather dense
netsh - an old experiment that serves as a simple TUI for managing network interfaces... and an example of how not to use AWK
plumber - one of my more sophisticated scripts; plumber creates pipes between programs based on what sort of input it receives, and handles errors (somewhat) intelligently
bach - the Batch Audio Conversion Helper uses FFMPEG to convert large numbers of files at once
invcli - Invidious CLI client. I hacked this together in like an hour and a half, so it's kind of rough at the moment, but it does work!

63
invcli Executable file
View File

@ -0,0 +1,63 @@
#!/bin/sh -e
search()
{
rm -f /tmp/invidious_results
query_sanitized="$(printf "%s\n" "$1"|sed -ne 's/ /%20/gp')"
curl --output /tmp/invidious_results "https://vid.puffyan.us/search?q=$query_sanitized"
}
extract_names()
{
sed -ne 's/<p dir.*>\(.*\)<\/p>/\1/p' /tmp/invidious_results|sed 's/ *//'
}
extract_urls()
{
for id in $(sed -ne 's/ */ /g' -e 's/<a style=.* href="\(\/watch?v=.*\)">/\1/p' /tmp/invidious_results|sed -ne 's/ *//p')
do
printf "https://vid.puffyan.us%s\n" $id
done
}
watch_vid()
{
curl -v "https://vid.puffyan.us/latest_version?id=$id&itag=$itag" 2>>/dev/stdout|sed -ne 's/< Location: \(.*\)/\1/p'
}
fetch_itag()
{
curl --silent $1|sed -ne 's/.*"itag":"\([0-9][0-9]*\)".*/\1/p'
}
fetch_id()
{
curl --silent $(extract_urls|sed $chosen_video!d)|grep itag|sed -ne 's/.*"id":"\(.*\)","itag":.*/\1/p'|sed 1!d
}
generate_locations()
{
for itag in $(fetch_itag $(extract_urls|sed $chosen_video!d)|sed $chosen_video!d)
do
watch_vid
done
}
main()
{
printf "Enter your search terms: "
read -r query
search "$query"
extract_names|nl
printf "Choose the desired media: "
read -r chosen_video
printf "Attempting to retrieve primary source for: "
printf "\"%s\"" "$(extract_names|sed $chosen_video!d)"
printf "...\nPlease wait.\n\n"
itag=$(echo $(fetch_itag $(extract_urls|sed $chosen_video!d))|cut -f$chosen_video -d' ')
id=$(fetch_id)
media="$(generate_locations|sed 1!d)"
printf "Loading %s...\n" "$media"
ffplay "$media"
}
main