your script is just a fancy wrapper around this command:
Code:
wget $url -O $(date '+%Y-%m-%d_%H%M%S')_$filename
judging from the commented out url, i assume it was designed to capture images from a still image webcam; these still exist all over the web, but really it's just the URL to an image, and that image changes every time you reload the URL.
downloading a frame from a youtube video is a whole different piece of cake, and cannot be done in this way!!!
fwiw, i am watching 2 ospreys on my desktop right now, with mpv (*).
so it is possible, and i guess the 402 error means youtube kicked you out because too many requests.
close your browser, wait an hour or two, and try again.
(*) mpv uses youtube-dl for youtube videos. youtube-dl in turn uses ffmpeg.
here's a rough idea to capture one frame: restart the download every minute, only use the first frame.
(maybe that's precisely what caused the 402 error :-(