Skip to content

Latest commit

 

History

History
124 lines (78 loc) · 3.52 KB

README.md

File metadata and controls

124 lines (78 loc) · 3.52 KB

go-embed-youtube

Embedding a YouTube video in Markdown format is cumbersome. This project aims to help with that.

Motivation

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.

Tech/framework used

Built with

Features

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.

Example Usage

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:

Placeholder Video

Installation

  1. Get a Google Developer API key.

  2. You need Go on your machine. Then clone the repository:

    git clone https://github.com/sophiabrandt/go-embed-youtube.git
  3. Build binary:

    cd go-embed-youtube
    go build -o go-embed-youtube

How to use?

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")

Advanced Example

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'

Contribute

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.

Credits

The project owns its thanks to Carl M. Johnson's blog Writing Go CLIs With Just Enough Architecture and accompanying code.

License

Distributed under the MIT License. See LICENSE for details.