POSIX_Scripts/plumber

42 lines
1.3 KiB
Bash
Executable File

#!/bin/sh -e
rand_inst() # Choose a random invidious instance to distribute load.
# Good digital citizenship is important, you know.
{
case $(($(dd bs=2 count=1 if=/dev/random of=/dev/stdout | od - | \
sed -ne 's/ */ /gp' | cut -d ' ' -f2) % 3)) in
0) printf "vid.puffyan.us" ;;
1) printf "ytprivate.com" ;;
2) printf "yewtu.be" ;;
esac
}
if [ "$(printf "%s" "${1}"|cut -b 1,2,3,4)" = "http" ]
then
case "${1}" in
*youtu*) exec Links "$(printf "%s" "${1}"|sed -ne \
"s/\(http.*:\/\/\).*\(\/.*\)/\1$(rand_inst)\2/p")" & ;;
*reddit*) exec Links "$(printf "%s" "${1}"|sed -ne \
"s/\(http.*:\/\/\).*\(\/.*\/\)/\1libredd.it\2/p")" & ;;
https://4chan.org*) exec Links "$(printf "%s" "${1}"|sed -ne \
"s/4chan/4channel/p")" ;;
*) exec Links "${1}" & ;;
esac
else
mime=$(file --mime-type -b "${1}")
case ${mime} in
*html*) exec Links "${1}" & ;;
text*) exec xless "${1}" & ;;
video*) exec fpv "${1}" & ;;
audio*) exec fpm "${1}" & ;;
image*) exec iview "${1}" & ;;
*pdf) exec gv "${1}" & ;;
*) printf "Plumber ran into an edge case with the following string/mime\n%s"\
"${1}"|xmessage -file - & ;;
esac
fi
exit