Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create a youtube video link with a portion of the video only
package main
import (
"fmt"
"log"
"net/url"
"os"
"time"
)
func main() {
embededLink, _ := url.Parse(`https://www.youtube.com/embed/`)
u, err := url.Parse(os.Args[1])
if err != nil {
log.Fatal(err)
}
v := u.Query()["v"]
if len(v) == 0 {
log.Fatal("bad request")
}
embededLink.Path = embededLink.Path + v[0]
start, err := time.ParseDuration(os.Args[2])
if err != nil {
log.Fatal(err)
}
end, err := time.ParseDuration(os.Args[3])
if err != nil {
log.Fatal(err)
}
q := u.Query()
q.Set("start", fmt.Sprintf("%.0f", start.Seconds()))
q.Set("end", fmt.Sprintf("%.0f", end.Seconds()))
embededLink.RawQuery = q.Encode()
fmt.Println(embededLink)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment