package main import ( "io" "log" "os" "github.com/kkdai/youtube/v2" ) const ItagM4AAudio = 140 func main() { var client youtube.Client videoID := "s_oJYdRlrv0" video, err := client.GetVideo(videoID) if err != nil { log.Fatal(err) } format := video.Formats.FindByItag(ItagM4AAudio) stream, _, err := client.GetStream(video, format) if err != nil { log.Fatal(err) } file, err := os.Create("out.m4a") if err != nil { log.Fatal(err) } defer file.Close() _, err = io.Copy(file, stream) if err != nil { log.Fatal(err) } log.Println("done") }