From 0a7dd126e8b311dc6ccbd3f42c0359b6b5855de8 Mon Sep 17 00:00:00 2001 From: Lucas Date: Sat, 2 May 2020 19:39:59 +0000 Subject: [PATCH] invidious: rewrite - Use API cleverly - Allow specifying a provider different than invidio.us - Use torsocks by default --- bin/invidious.sh | 62 +++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/bin/invidious.sh b/bin/invidious.sh index bd1ddba..f50a14d 100644 --- a/bin/invidious.sh +++ b/bin/invidious.sh @@ -1,7 +1,7 @@ #!/bin/sh # invidious # Written in 2019 by Leslie -# Modified in 2019 by Lucas +# Modified in 2019-2020 by Lucas # CC0 1.0 Universal/Public domain - No rights reserved # # To the extent possible under law, the author(s) have dedicated all @@ -13,7 +13,7 @@ usage() { - printf "Usage: %s url\n" "${0##*/}" >&2 + printf "Usage: [-T] %s url\n" "${0##*/}" >&2 exit 1 } @@ -23,33 +23,45 @@ err() exit 1 } +api() +{ + printf "https://%s%s\n" "$INVIDIOUS" "$*" +} + +: ${INVIDIOUS:=invidious.snopyta.org} + +torsocks=torsocks +while getopts T flag; do + case $flag in + T) torsocks= + ;; + *) usage + ;; + esac +done +shift $((OPTIND - 1)) [ $# -eq 1 ] || usage -case $1 in -"https://invidio.us/watch?v="*) - ;; -*) err "Not an invidio.us url." - ;; -esac +# XXX check URL for known sites +url=$1 -video_id= -for param in $(printf "%s\n" "${1##*"?"}" | tr "&" "\n"); do - k=${param%%=*} - [ "$k" = v ] || continue +oldIFS=$IFS +IFS="&" +set -- ${url##*"?"} +IFS=$oldIFS - v=${param#*=} - if [ ${#v} -ne 11 ]; then - printf "%s: \"%s\": not a video ID." "${0##*/}" "$v" >&2 - continue - fi - video_id=$v - break +id= +for param; do + case $param in + v=*) id=${param#v=} + [ ${#id} -eq 11 ] || err "invalid video ID" + ;; + esac done -[ -n "$video_id" ] || err "no video ID in URL." +[ -n "$id" ] || err "no video ID in URL" -dl_option=$(ftp -o - "$1" 2>/dev/null | grep -F "