Use the youtube.com search URL as a playlist
yt-dlp --embed-subs --playlist-items 1:1 \
'http://youtube.com/results?search_query=makeba&sp=EgIoAQ%253D%253D'
That will download just the top result that has closed captions (CC).
Wrapper script for songs/videos
If you feel like that's too much typing, I made a bash script to wrap searching and downloading song audio including the lyrics. You can download it from: https://github.com/hackerb9/getsong/. It is quite easy to use if you have a UNIX box:
getsong -c "A week ago last Thursday"
Note that the script requires the -c
option to restrict the search to results with closed captions. (See the Caveats below for why I kept the default off).
If you rename the script getvideo
, it will download videos, not just the audio.
Caveats
Note, that this answer does not do precisely what was requested: instead of simply preferring results with closed captioning, this makes captions a requirement. Ideally, we'd get an error message if the desired video is not available with captions, but instead YouTube mangles and ignores the search terms until it finds an incorrect video that does have closed captions.
Another possible issue: I had hoped to get lyrics synced with songs this way, but YouTube doesn't look at the quality or even quantity of the captions, only whether they exist or not. Occasionally, I've hit files which contain only a single subtitle which reads, unhelpfully, "🎜 (singing) 🎝". In those cases, using the 2nd or 3rd result usually helps.
Thanks to @Destroy666 for the suggestion to try using the YouTube search URL as the argument for yt-dlp.
yt-dlp https://www.youtube.com/results?search_query="A+year+ago+last+Thursday"&sp=EgIoAQ --embed-subs --max-downloads
. Not too sure it is though.yt-dlp https://www.youtube.com/results?search_query=%22A+year+ago+last+Thursday%22&sp=EgIoAQ%253D%253D --embed-subs --max-downloads 1
--max-downloads 1
doesn't work when--remux-video 'opus>mka'
is also used.)