Embedding a YouTube video in Markdown format is cumbersome. This project aims to help with that.
If you want to embed a video using standard markdown, you need to do this:
[![IMAGE ALT TEXT](http://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg)](http://www.youtube.com/watch?v=YOUTUBE_VIDEO_ID_HERE "Video Title")
Trying to remember the correct syntax, plus copy and pasting the needed values is a bit of a hassle.
Ideally, I want to use a link to a YouTube video and let a program figure out the rest.
Built with
The project is a command line program that uses the YouTube API and returns markdown-formatted text as stdout
.
You can use this tool in conjunction with other utilities, like xclip or pbpaste.
go-embed-youtube -y 'https://youtube.com/watch?v=ScMzIvxBSi4' -k <google developer API key>
Output:
[![Placeholder Video](https://i.ytimg.com/vi/ScMzIvxBSi4/sddefault.jpg)](https://youtube.com/watch?v=ScMzIvxBSi4 "Placeholder Video")
Rendered Markdown:
-
Get a Google Developer API key.
-
You need Go on your machine. Then clone the repository:
git clone https://github.com/sophiabrandt/go-embed-youtube.git
-
Build binary:
cd go-embed-youtube go build -o go-embed-youtube
go-embed-youtube -h
Usage of embed-youtube:
-k string
Google Developers API Key (required)
-t duration
Client timeout (default 30s)
-y string
Youtube Video to embed as Markdown (default "https://youtube.com/watch?v=ScMzIvxBSi4")
Use pass to store your Google API Developer Key:
pass add google-dev/youtube-api-key
Use xargs
to pipe the API key to go-embed-youtube
:
pass show google-dev/youtube-api-key | xargs -I % ./go-embed-youtube -k % -y 'https://youtube.com/watch?v=ScMzIvxBSi4'
Bonus tip: If you use the fish shell, you can create a wrapper function:
function embedyoutube
pass show google-dev/youtube-api-key | xargs -I % go-embed-youtube -k % -y $argv
end
(The function assumes that you have go-embed-youtube
in your $PATH
.)
Don't forget to save it:
funcsave embedyoutube
Use it:
embedyoutube 'https://youtube.com/watch?v=ScMzIvxBSi4'
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
The project owns its thanks to Carl M. Johnson's blog Writing Go CLIs With Just Enough Architecture and accompanying code.
Distributed under the MIT License. See LICENSE for details.