I have a Hugo website/blog with content written in markdown, and I've added embedded several youtube videos. I'd like to keep an offline archive of videos, in case any of the youtube videos are taken down. How can I make an archive of youtube videos I've linked on my blog?
Once you've installed youtube-dl (e.g. brew install youtube-dl
), you can run this one-liner (build for MacOS but probably also work on Linux or WSL).
This works for Hugo-type youtube embedding, which uses this form
{{< youtube 1UdI_eoDPKQ >}}
Here's the one-liner:
find . -type f -name "*.md" -exec grep -r 'youtube' {} + | awk -F "{{" '{print $NF}' | sed 's/ >}}//g' | sed 's/< youtube//g' | xargs youtube-dl --id
which will download videos to the local directory.
Steps