#!/bin/bash

# https://ocv.me/dev/?termux-twitch.sh
# https://ocv.me/termux/
#
# supports VLC; connect to udp://@:4321/
# supports mpv; connect to udp://127.0.0.1:4321/

set -e
printf '\nchecking dependencies\n'
command -v python3 || pkg install python
command -v ffmpeg || pkg install ffmpeg
[ -e $TMPDIR/have.streamlink ] || {
    python3 -m ensurepip
    python3 -m pip install --user -U streamlink
    mkdir $TMPDIR/have.streamlink
}
streamlink -pffmpeg -a'-hide_banner -re -i - -c copy -f mpegts udp://127.0.0.1:4321/' "$1" ${2:-best}



# streamlink -o ~/sd/Movies/twitch.ts https://twitch.tv/hakumai best
# ffmpeg -hide_banner -re -i ~/sd/Movies/twitch.ts -c copy -f mpegts udp://127.0.0.1:4321/
