Using youtube-dl, you can easily download an ongoing live streaming.
$ youtube-dl --hls-use-mpegts <URL>
If the target live stream hasn't been started yet, however, the command exits right away after printing messages like
[youtube] I1gi2ABCDEf: Downloading webpage
ERROR: This live event will begin in a few moments.
Is it possible to make youtube-dl wait until the live stream starts and then record it?
My current workaround is this:
#pseudo code
while (true) {
start = time()
execute youtube-dl
end = time()
if (end - start > 10seconds) { #if recording succeeded
break
}
sleep(some seconds)
}
or this:
#pseudo code
while (true) {
if (check_if_live_is_active_using_curl_or_youtube_api()) {
break
}
sleep(some seconds)
}
execute youtube-dl
Combining the both is working perfectly now (actualy the second one should be enough but I use also the first one as a fallback) but it would be nice if there was a more elegant way.