#!/bin/sh # pass this in the command-line #--script-opts ytdl_hook-ytdl_path=/path/to/this-file/yt-dlp-and-sleep.sh # or, in configuration ~/.config/mpv/mpv.conf #script-opts=ytdl_hook-ytdl_path=/path/to/this-file/yt-dlp-and-sleep.sh ( yt-dlp "$@" \ | tee /dev/fd/3 \ | jq '[ .formats | .[] | .available_at | select(. != null) | (. - now) | select(. > 0) ]|max + 0' \ | (read t && sleep $t; :) ) 3>&1