invidious: handle embed links

This commit is contained in:
Lucas 2020-05-02 20:44:19 +00:00
parent 7f89a0aaf8
commit 3fcbc23542

View File

@ -38,6 +38,41 @@ known_site()
-e "^https://yewtu\.be/"
}
get_id_path()
{
printf "%s\n" "${1##*/}"
}
get_id_query()
{
oldIFS=$IFS
IFS="&"
set -- ${1##*"?"}
IFS=$oldIFS
id=
for param; do
case $param in
v=*) id=${param#v=}
break
;;
esac
done
printf "%s\n" "$id"
}
get_id()
{
case $1 in
"https://youtu.be/" | *"/embed/"*)
get_id_path "$1"
;;
*) get_id_query "$1"
;;
esac
}
: ${INVIDIOUS:=invidious.snopyta.org}
torsocks=torsocks
@ -55,21 +90,8 @@ shift $((OPTIND - 1))
url=$1
known_site "$url" || err "Unknown site: $url"
oldIFS=$IFS
IFS="&"
set -- ${url##*"?"}
IFS=$oldIFS
id=
for param; do
case $param in
v=*) id=${param#v=}
id=$(get_id "$url")
[ ${#id} -eq 11 ] || err "invalid video ID"
;;
esac
done
[ -n "$id" ] || err "no video ID in URL"
# XXX choose in some clever way
itag=$(torsocks ftp -MVo - "$(api "/api/v1/videos/$id")" |