From 8de76cf8b1ea7e19b83b753ffc95dae5ffae446a Mon Sep 17 00:00:00 2001 From: Lucas Date: Sun, 1 Nov 2020 18:51:45 +0000 Subject: [PATCH] Use `curl` if not running on OpenBSD --- bin/invidious.sh | 15 ++++++++++++++- bin/rfcopen.sh | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/bin/invidious.sh b/bin/invidious.sh index dcd9a4e..b1a1cdb 100644 --- a/bin/invidious.sh +++ b/bin/invidious.sh @@ -23,6 +23,19 @@ err() exit 1 } +fetch_file() +{ + # Assumes utility supports `-o output_file` + case $(uname) in + OpenBSD) + $torsocks ftp -MV "$@" + ;; + *) + $torsocks curl -fLSs "$@" + ;; + esac +} + api() { printf "https://%s%s\n" "$INVIDIOUS" "$*" @@ -93,6 +106,6 @@ id=$(get_id "$url") [ ${#id} -eq 11 ] || err "invalid video ID $id" # XXX choose in some clever way -itag=$($torsocks ftp -MVo - "$(api "/api/v1/videos/$id")" | +itag=$(fetch_file -o - "$(api "/api/v1/videos/$id")" | jq -r ".formatStreams[].itag" | head -n 1) api "/latest_version?id=$id&itag=$itag" diff --git a/bin/rfcopen.sh b/bin/rfcopen.sh index ccaef96..dae3b6a 100644 --- a/bin/rfcopen.sh +++ b/bin/rfcopen.sh @@ -22,6 +22,19 @@ err() exit 1 } +fetch_file() +{ + # Assumes utility supports `-o output_file` + case $(uname) in + OpenBSD) + $torsocks ftp -MV "$@" + ;; + *) + $torsocks curl -fLSs "$@" + ;; + esac +} + tonumber() { printf "%u" "$1" 2>/dev/null @@ -44,6 +57,6 @@ url=https://tools.ietf.org/rfc/rfc$n.txt mkdir -p "$RFCDIR" if [ ! -f "$rfcfile" ]; then - $torsocks ftp -Vo "$rfcfile" "$url" || err "couldn't fetch RFC $n" + fetch_file -o "$rfcfile" "$url" || err "couldn't fetch RFC $n" fi ${PAGER:-more} "$rfcfile"