Add proper invidious support. - annna - Annna the nice friendly bot. HTML git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/annna/ DIR Log DIR Files DIR Refs DIR Tags DIR README --- DIR commit 61cec39d3cc7836c1740f8f291b05456e5788866 DIR parent eda939b0ce9759565c6850bc8c4966cfd60fa2c2 HTML Author: Annna Robert-Houdin <annna@bitreich.org> Date: Tue, 26 Dec 2023 21:13:56 +0100 Add proper invidious support. Diffstat: M annna-message-common | 14 +++++++++++--- A dl-invidious-instances | 13 +++++++++++++ A get-invidious-instance | 5 +++++ A is-invidious-instance | 21 +++++++++++++++++++++ 4 files changed, 50 insertions(+), 3 deletions(-) --- DIR diff --git a/annna-message-common b/annna-message-common @@ -92,6 +92,14 @@ case "${text}" in titleend=0 outputstr="" + if is-invidious-instance "${uri}"; + then + host="$(printf "%s\n" "${uri}" \ + | sed 's,.*://\([^/]*\).*,\1,')" + uri="$(printf "%s\n" "${uri}" \ + | sed "s,${host},youtube.com,")" + fi + case "${urititle}" in "") ;; @@ -188,7 +196,7 @@ case "${text}" in nocuri=0 fi ;; - *youtube.com/*|*youtu.be/*|*yewtu.be/*) + *youtube.com/*|*youtu.be/*) if [ -z "${uri##*youtu.be/*}" ] || [ -z "${uri##*/watch?v=*}" ] || [ -z "${uri##*/embed/*}" ] || [ -z "${uri##*/shorts/*}" ]; then ytid="${uri#https*://*/watch?v=}" @@ -197,7 +205,7 @@ case "${text}" in ytid="${ytid##*youtu.be/}" ytid="${ytid%%\?*}" ytid="${ytid%%&*}" - nuri="https://yewtu.be/watch?v=${ytid}" + nuri="$(get-invidious-instance)/watch?v=${ytid}" ytt="$(printf '%s\n' "${uri}" | sed -n 's/.*[&?]t=\([^&]\{1,\}\).*/\1/p')" if [ -n "${ytt}" ]; then @@ -205,7 +213,7 @@ case "${text}" in fi else ytid="" - nuri="https://yewtu.be/${uri#https*://*/}" + nuri="$(get-invidious-instance)/${uri#https*://*/}" fi fetch-uri "${nuri}" > "${tmpf}" urititle="$(curl-grabtitle "${nuri}")" DIR diff --git a/dl-invidious-instances b/dl-invidious-instances @@ -0,0 +1,13 @@ +#!/bin/sh + +cd $HOME/bin/modules/invidious + +apiuri="https://api.invidious.io/instances.json" + +curl -s "${apiuri}" 2>/dev/null \ + | sed 's,"uri",\n,g' \ + | sed 's,:"\([^"]*\)".*,\1,' \ + | grep "^http" \ + | grep -v ".onion" \ + | grep -v ".i2p" > invidious-instances.txt + DIR diff --git a/get-invidious-instance b/get-invidious-instance @@ -0,0 +1,5 @@ +#!/bin/sh + +cd $HOME/bin/modules/invidious +shuf -n 1 invidious-instances.txt 2>/dev/null + DIR diff --git a/is-invidious-instance b/is-invidious-instance @@ -0,0 +1,21 @@ +#!/bin/sh + +if [ $# -lt 1 ]; +then + printf "usage: %s host\n" "$(basename "${0}")" >&2 + exit 1 +fi +instance="${1}" + +cd $HOME/bin/modules/invidious + +printf "%s\n" "${instance}" \ + | sed 's,.*://\([^/]*\).*,\1,' \ + | grep "${instance}" invidious-instances.txt 2>&1 >/dev/null +if [ $? -eq 0 ]; +then + exit 1 +else + exit 0 +fi +