#!/bin/rc rfork e a = '/api/v1/search?' mode = video while(~ $1 -*){ switch($1){ case -relevance -rating -upload_date -view_count a = $a^sort_by^`{echo $1 | tr - '='}^'&' case -hour -today -week -month -year a = $a^date^`{echo $1 | tr - '='}^'&' case -short -long a = $a^duration^`{echo $1 | tr - '='}^'&' case -playlist -channel mode = `{echo $1 | tr -d -} a = $a^'type='^$mode^'&' case -[A-Z][A-Z] a = $a^region^`{echo $1 | tr - '='}^'&' case * echo unrecognized option $1 >[1=2] echo run with no arguments for help >[1=2] exit badopt } shift } if(~ $#* 0){ echo 'usage: $0 [options] query sort_by options: -relevance -rating -upload_date -view_count date options: -hour -today -week -month -year duration options: -short -long type options: -playlist -channel region options: -NZ (or any other ISO 3166 country code)' >[1=2] exit usage } a = $a^'q='^`{echo -n $* | urlencode} for(i in `{ hget 'https://api.invidious.io/instances.json?sort_by=type' | jb -p | sed -n ' /\.(onion|i2p)\/?$/d s†^\[[0-9]+\]\[1\]/uri: ††p' }) switch($mode){ case video hget $i^$a | jb -p | awk ' /^\[[0-9]+\]\/title: /{ sub(/[^ ]+ /, "\n") print } /^\[[0-9]+\]\/(videoId|author|publishedText): /{ sub(/[^ ]+ /, "") printf "%s ", $0 } /^\[[0-9]+\]\/lengthSeconds: /{ printf "%.2d:%.2d:%.2d\n", $2 / 60 / 60, $2 / 60 % 60, $2 % 60 } ' && exit case playlist hget $i^$a | jb -p | sed -n ' s/^\[[0-9]+\]\/title: /\n/p s/^\[[0-9]+\]\/videoCount: (.*)/\1 videos/p s/^\[[0-9]+\]\/(author|playlistId): //p ' && exit case channel hget $i^$a | jb -p | sed -n ' s/^\[[0-9]+\]\/author: /\n/p s/^\[[0-9]+\]\/(authorId|description): //p ' && exit } echo no working instances found >[1=2] exit failed