Only expand youtube URIs on demand using #spoil. - annna - Annna the nice friendly bot.
(HTM) git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/annna/
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Tags
(DIR) README
---
(DIR) commit 25ca69b65696aa9e81a25da027abff21729c7927
(DIR) parent f74d2c991befa99db57a1302a7fe54b88d3127d4
(HTM) Author: Annna Robert-Houdin <annna@bitreich.org>
Date: Sat, 25 Jan 2025 09:34:08 +0100
Only expand youtube URIs on demand using #spoil.
Youtube is annoying, hates users and the expansion adds no value to the
channel atm.
Diffstat:
M annna-message-common | 63 ++++++++++++++++++++-----------
1 file changed, 41 insertions(+), 22 deletions(-)
---
(DIR) diff --git a/annna-message-common b/annna-message-common
@@ -39,9 +39,15 @@ regeximatch() {
[ "$user" = "${ircuser}" ] && exit 0
+# Flag, if some expansion of some URI happened.
uriexpansion=0
+# Do not spoil at all.
nospoil=0
+# Enforce spoiling in case of hard nospoil filter.
+dospoil=0
+# Expand meme hashtag and show recommendations.
doexpand=0
+
case "${text}" in
*\#nospoil*)
nospoil=1
@@ -71,6 +77,12 @@ case "${text}" in
;;
*http*://*|*ytdl://*)
case "${text}" in
+ *"#spoil"*)
+ dospoil=1
+ ;;
+ esac
+
+ case "${text}" in
*http*://*)
uri="$(printf "%s\n" "${text}" \
| sed -n '/.*\(https\{0,1\}:\/\/[^ ]\{1,\}\).*/s//\1/p')"
@@ -239,33 +251,40 @@ case "${text}" in
fi
;;
*youtube.com/*|*youtu.be/*)
- if [ -z "${uri##*youtu.be/*}" ] || [ -z "${uri##*/watch?v=*}" ] || [ -z "${uri##*/embed/*}" ] || [ -z "${uri##*/shorts/*}" ];
+ # Youtube is so annoying and repeatedly broken;
+ # they hate users, only expand on request.
+ if [ $dospoil -eq 1 ];
then
- ytid="${uri#http*://*/watch?v=}"
- ytid="${ytid##*embed/}"
- ytid="${ytid##*shorts/}"
- ytid="${ytid##*youtu.be/}"
- ytid="${ytid%%\?*}"
- ytid="${ytid%%&*}"
- nuri="$(get-invidious-instance)/watch?v=${ytid}"
- ytt="$(printf '%s\n' "${uri}" | sed -n 's/.*[&?]t=\([^&]\{1,\}\).*/\1/p')"
- if [ -n "${ytt}" ];
+ if [ -z "${uri##*youtu.be/*}" ] \
+ || [ -z "${uri##*/watch?v=*}" ] \
+ || [ -z "${uri##*/embed/*}" ] \
+ || [ -z "${uri##*/shorts/*}" ];
+ then
+ ytid="${uri#http*://*/watch?v=}"
+ ytid="${ytid##*embed/}"
+ ytid="${ytid##*shorts/}"
+ ytid="${ytid##*youtu.be/}"
+ ytid="${ytid%%\?*}"
+ ytid="${ytid%%&*}"
+ nuri="$(get-invidious-instance)/watch?v=${ytid}"
+ ytt="$(printf '%s\n' "${uri}" | sed -n 's/.*[&?]t=\([^&]\{1,\}\).*/\1/p')"
+ [ -n "${ytt}" ] && nuri="${nuri}&t=${ytt}"
+ else
+ ytid=""
+ nuri="$(get-invidious-instance)/${uri#https*://*/}"
+ fi
+ fetch-uri "${nuri}" > "${tmpf}"
+ urititle="$(curl-grabtitle "${nuri}")"
+ nuris="invidious: ${nuri}"
+ if [ -n "${ytid}" ];
then
- nuri="${nuri}&t=${ytt}"
+ sturi="$(subtitle-paste "${uri}")"
+ nuris="${nuris} ; metadata: gophers://codemadness.org/1/idiotbox.cgi?v=${ytid}"
fi
+ nocuri=1
else
- ytid=""
- nuri="$(get-invidious-instance)/${uri#https*://*/}"
+ titleend=1
fi
- fetch-uri "${nuri}" > "${tmpf}"
- urititle="$(curl-grabtitle "${nuri}")"
- nuris="invidious: ${nuri}"
- if [ -n "${ytid}" ];
- then
- sturi="$(subtitle-paste "${uri}")"
- nuris="${nuris} ; metadata: gophers://codemadness.org/1/idiotbox.cgi?v=${ytid}"
- fi
- nocuri=1
;;
*tv.brain.rip/???-???*)
nuris="$(grep 'property="og:video:secure_url' < "${tmpf}" | sed 's,.*content="\([^"]*\)".*,\1,')"