Rewrote plumber. Still in progress.
This commit is contained in:
parent
6e93011f0d
commit
26469b1abd
76
plumber
76
plumber
@ -1,18 +1,21 @@
|
|||||||
#!/bin/sh -e
|
#!/bin/sh -e
|
||||||
|
|
||||||
rand_inst() # Choose a random invidious instance to distribute load.
|
web_handler()
|
||||||
# Good digital citizenship is important, you know.
|
|
||||||
{
|
{
|
||||||
case $(($(dd bs=2 count=1 if=/dev/random of=/dev/stdout | od - | \
|
# Choose a random invidious instance to distribute load.
|
||||||
sed -ne 's& *& &gp' | cut -d ' ' -f2) % 3)) in
|
# Good digital citizenship is important, you know.
|
||||||
|
rand_inst()
|
||||||
|
{
|
||||||
|
case $(($(rand)%6)) in
|
||||||
0) printf "vid.puffyan.us" ;;
|
0) printf "vid.puffyan.us" ;;
|
||||||
1) printf "ytprivate.com" ;;
|
1) printf "inv.riverside.rocks" ;;
|
||||||
2) printf "yewtu.be" ;;
|
2) printf "invidious.kavin.rocks" ;;
|
||||||
|
3) printf "invidious-us.kavin.rocks" ;;
|
||||||
|
4) printf "invidious.osi.kr" ;;
|
||||||
|
5) printf "invidio.xamh.de" ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "$(printf "%s" "${1}"|cut -b 1,2,3,4)" = "http" ]
|
|
||||||
then
|
|
||||||
case "${1}" in
|
case "${1}" in
|
||||||
*youtu*) exec Links "$(printf "%s" "${1}"|sed -ne \
|
*youtu*) exec Links "$(printf "%s" "${1}"|sed -ne \
|
||||||
"s&\(http.*://\).*\(/.*\)&\1$(rand_inst)\2&p")" & ;;
|
"s&\(http.*://\).*\(/.*\)&\1$(rand_inst)\2&p")" & ;;
|
||||||
@ -22,20 +25,57 @@ then
|
|||||||
"s&4chan&4channel&p")" & ;;
|
"s&4chan&4channel&p")" & ;;
|
||||||
*) exec Links "${1}" & ;;
|
*) exec Links "${1}" & ;;
|
||||||
esac
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
else
|
|
||||||
|
|
||||||
mime=$(file --mime-type -b "${1}")
|
local_handler()
|
||||||
|
{
|
||||||
|
cleanse_prefix()
|
||||||
|
{
|
||||||
|
printf "%s" "$(echo "${1}" | sed -ne 's&file://&&p')"
|
||||||
|
}
|
||||||
|
|
||||||
|
target="$(cleanse_prefix "${1}")"
|
||||||
|
mime="$(file --mime-type -b "${target}")"
|
||||||
|
|
||||||
case ${mime} in
|
case ${mime} in
|
||||||
*html*) exec Links "${1}" & ;;
|
*html*) exec Links "${target}" & ;;
|
||||||
text*) exec xless "${1}" & ;;
|
text*) exec xless "${target}" & ;;
|
||||||
video*) exec fpv "${1}" & ;;
|
video*) exec fpv "${target}" & ;;
|
||||||
audio*) exec fpm "${1}" & ;;
|
audio*) exec fpm "${target}" & ;;
|
||||||
image*) exec iview "${1}" & ;;
|
image*) exec iview "${target}" & ;;
|
||||||
*pdf) exec gv "${1}" & ;;
|
*pdf) exec gv "${target}" & ;;
|
||||||
*) printf "Plumber ran into an edge case with the following string/mime\n%s"\
|
*) edgecase ;;
|
||||||
"${1}"|xmessage -file - & ;;
|
|
||||||
esac
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
edgecase()
|
||||||
|
{
|
||||||
|
err()
|
||||||
|
{
|
||||||
|
printf "Plumber wasn't able to find a way to handle the following URI.\n%s\n" "${1}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# If first character is / or a ~ and it exists, we're dealing with local data.
|
||||||
|
firstchar=$(echo"${1}"|cut -b1)
|
||||||
|
if [ "${firstchar}" = '~' || "${firstchar}" = '/' ]
|
||||||
|
then
|
||||||
|
local_handler "${1}"
|
||||||
|
else
|
||||||
|
err "${1}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# Commented lines will have support in the future.
|
||||||
|
case "$(printf "%s" "${1}"|cut -b 1,2,3,4)" in
|
||||||
|
# gopher) err "${@}" ;;
|
||||||
|
http) web_handler "${@}" ;;
|
||||||
|
file) local_handler "${@}" ;;
|
||||||
|
# ftp) err "${@}" ;;
|
||||||
|
# ssh) err "${@}" ;;
|
||||||
|
*) edgecase "${2}" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
exit
|
exit
|
||||||
|
Loading…
x
Reference in New Issue
Block a user