From 99dd02979bd263b80fad9b4859ddcaed58e46cc0 Mon Sep 17 00:00:00 2001
From: Case Duckworth
Date: Mon, 18 Jul 2022 09:33:09 -0500
Subject: Convert youtube -> invidious
---
runsfeed | 9 +++++++++
sfeed_html.sh | 8 +++++++-
sfeedrc | 2 +-
3 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/runsfeed b/runsfeed
index 7bafcc0..f108031 100755
--- a/runsfeed
+++ b/runsfeed
@@ -19,6 +19,8 @@ main() {
test -d "$(dirname "$sfeedrc")" || mkdir -p "$(dirname "$sfeedrc")"
test -d "$sfeedpath" || mkdir -p "$sfeedpath"
+ log Finding Invidious host...
+ get_invidious_url "https://api.invidious.io/instances.json?sort_by=health"
log Updating feeds...
update "$sfeedrc"
log Generating HTML...
@@ -36,6 +38,13 @@ main() {
log Done.
}
+get_invidious_url() {
+ curl -sL "$1" |
+ jq -r .[][1].uri |
+ grep -v onion |
+ head -n1 | tee /tmp/invidious.host
+}
+
log() {
printf '%s\n' "$*" >&2
}
diff --git a/sfeed_html.sh b/sfeed_html.sh
index 86aad43..321d451 100755
--- a/sfeed_html.sh
+++ b/sfeed_html.sh
@@ -67,6 +67,12 @@ $(for file in "$@"; do html_feed "$file"; done)
EOF
}
+filter_invidious() {
+ # Convert youtube links to invidious links
+ host="$(cat /tmp/invidious.host)"
+ sed "s@https://www\.youtube\.com@${host}@"
+}
+
html_feed() { # html_feed FEED(file) => HTML
filename="$(basename "$1")"
now="$(date +%s)"
@@ -136,7 +142,7 @@ html_feed() { # html_feed FEED(file) => HTML
printf "%s\n", NAME, NAME >> ASIDE
}
printf "%s", (stamp ? stamp : ".") > "/dev/stderr"
- }' "$1")"
+ }' "$1" | filter_invidious)"
if [ -z "$entries" ]; then return 1; fi
echo ""
# TODO: Include a link back to the website
diff --git a/sfeedrc b/sfeedrc
index 136eaf9..772f19b 100644
--- a/sfeedrc
+++ b/sfeedrc
@@ -178,7 +178,7 @@ filter_add_empties() {
filter_embed_youtube() {
# replace youtube links with embed links
- sed 's@www.youtube.com/watch?v=@www.youtube.com/embed/@g'
+ sed 's@www\.youtube\.com/watch?v=@www.youtube.com/embed/@g'
}
filter_filter_links() {
--
cgit 1.4.1-21-gabe81