GoDown/app/handlers/ytdl/20_DlAudio.go
2022-04-29 01:00:04 +02:00

28 lines
510 B
Go

package ytdl
import (
"fmt"
"io"
"os"
"github.com/kkdai/youtube/v2"
)
func DlAudio(ytid string) {
Filepath = fmt.Sprintf(Cache_Path + ytid + ".mp4")
ytdl := youtube.Client{}
video, err := ytdl.GetVideo(ytid)
check(err)
formats := video.Formats.WithAudioChannels()
stream, _, err := ytdl.GetStream(video, &formats[0])
check(err)
_ = os.Mkdir(Cache_Path, 0755)
file, err := os.Create(Filepath)
check(err)
fmt.Println(Filepath)
defer file.Close()
_, err = io.Copy(file, stream)
check(err)
}