dndmusicbot/ytdl.go

54 lines
927 B
Go

package main
import (
"fmt"
"os/exec"
"path/filepath"
)
var yturl = "https://youtu.be/%s"
func NewYTdl(vid string) ([]byte, error) {
ytdl := config.GetString("youtube.ytdl")
uri, err := exec.Command(
ytdl,
fmt.Sprintf(yturl, vid),
"--cookies", "./cookies.txt",
"--no-call-home",
"--no-cache-dir",
"--ignore-errors",
"--newline",
"--restrict-filenames",
"-f", "140",
"--get-url",
).Output()
if err != nil {
return nil, err
}
return uri[:len(uri)-1], nil
}
func DownloadAmbiance(uri string, name string) error {
ytdl := config.GetString("youtube.ytdl")
err := exec.Command(
ytdl,
uri,
"-x",
"--audio-format", "mp3",
"--postprocessor-args", "-ar 48000 -ac 2",
"--cookies", "./cookies.txt",
"--no-call-home",
"--no-cache-dir",
"--restrict-filenames",
"-f", "140",
"-o", filepath.Join("./ambiance/", name+".mp3"),
).Run()
if err != nil {
return nil
}
return nil
}