dndmusicbot/ytdl.go

54 lines
927 B
Go
Raw Normal View History

2022-11-19 17:05:02 +00:00
package main
2022-11-18 21:18:12 +00:00
import (
"fmt"
"os/exec"
"path/filepath"
)
var yturl = "https://youtu.be/%s"
func NewYTdl(vid string) ([]byte, error) {
2022-11-19 17:05:02 +00:00
ytdl := config.GetString("youtube.ytdl")
uri, err := exec.Command(
2022-11-19 17:05:02 +00:00
ytdl,
fmt.Sprintf(yturl, vid),
"--cookies", "./cookies.txt",
"--no-call-home",
"--no-cache-dir",
"--ignore-errors",
"--newline",
"--restrict-filenames",
"-f", "140",
"--get-url",
).Output()
2022-11-18 21:18:12 +00:00
if err != nil {
return nil, err
}
return uri[:len(uri)-1], nil
2022-11-18 21:18:12 +00:00
}
func DownloadAmbiance(uri string, name string) error {
2022-11-19 17:05:02 +00:00
ytdl := config.GetString("youtube.ytdl")
2022-11-18 21:18:12 +00:00
err := exec.Command(
2022-11-19 17:05:02 +00:00
ytdl,
2022-11-18 21:18:12 +00:00
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
}