summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorBobby <[email protected]>2025-04-13 19:42:38 +0530
committerBobby <[email protected]>2025-04-13 19:42:38 +0530
commit703eee6eb2802c126c529f8b74e7b740ca84831b (patch)
tree6f969878512569b6631aa84c782178c457780db7 /utils
parent95c1d34a544a54c3881d09de1d7d5a914e681d8a (diff)
downloadai-703eee6eb2802c126c529f8b74e7b740ca84831b.tar.xz
ai-703eee6eb2802c126c529f8b74e7b740ca84831b.zip
added yt-dlp logging
Diffstat (limited to 'utils')
-rw-r--r--utils/music/voice.go68
1 files changed, 55 insertions, 13 deletions
diff --git a/utils/music/voice.go b/utils/music/voice.go
index 99e27b1..f5ac03a 100644
--- a/utils/music/voice.go
+++ b/utils/music/voice.go
@@ -190,31 +190,73 @@ func (v *VoiceInstance) PlayYouTube(videoURL, videoID string) error {
Level: types.Debug,
})
- // Check if the cookies file exists
var downloadCmd *exec.Cmd
cookiesFile := "./cookies/cookies.txt"
if _, err := os.Stat(cookiesFile); err == nil {
- // Cookies file exists, pass it to yt-dlp
downloadCmd = exec.Command("yt-dlp", "--no-warnings", "--quiet", "-x", "--audio-format", "mp3",
"--audio-quality", "0", "--no-playlist", "--cookies", cookiesFile, "--output", fileName, videoURL)
} else {
- // No cookies file, just run yt-dlp without it
downloadCmd = exec.Command("yt-dlp", "--no-warnings", "--quiet", "-x", "--audio-format", "mp3",
"--audio-quality", "0", "--no-playlist", "--output", fileName, videoURL)
}
- // Completely suppress output
- devNull, _ := os.OpenFile(os.DevNull, os.O_WRONLY, 0)
- defer devNull.Close()
- downloadCmd.Stdout = devNull
- downloadCmd.Stderr = devNull
+ // Create logs for stdout and stderr to capture yt-dlp output
+ stdout, err := downloadCmd.StdoutPipe()
+ if err != nil {
+ logger.Log("Error creating StdoutPipe: "+err.Error(), types.LogOptions{
+ Prefix: "Music Player",
+ Level: types.Error,
+ })
+ return err
+ }
+ stderr, err := downloadCmd.StderrPipe()
+ if err != nil {
+ logger.Log("Error creating StderrPipe: "+err.Error(), types.LogOptions{
+ Prefix: "Music Player",
+ Level: types.Error,
+ })
+ return err
+ }
- logger.Log("Starting download", types.LogOptions{
- Prefix: "Music Player",
- Level: types.Debug,
- })
+ // Start the download process
+ err = downloadCmd.Start()
+ if err != nil {
+ logger.Log("Error starting yt-dlp command: "+err.Error(), types.LogOptions{
+ Prefix: "Music Player",
+ Level: types.Error,
+ })
+ return err
+ }
+
+ // Log the stdout and stderr
+ go func() {
+ stdoutLogs := make([]byte, 1024)
+ for {
+ n, err := stdout.Read(stdoutLogs)
+ if err != nil {
+ break
+ }
+ logger.Log("yt-dlp stdout: "+string(stdoutLogs[:n]), types.LogOptions{
+ Prefix: "Music Player",
+ Level: types.Debug,
+ })
+ }
+ }()
+ go func() {
+ stderrLogs := make([]byte, 1024)
+ for {
+ n, err := stderr.Read(stderrLogs)
+ if err != nil {
+ break
+ }
+ logger.Log("yt-dlp stderr: "+string(stderrLogs[:n]), types.LogOptions{
+ Prefix: "Music Player",
+ Level: types.Error,
+ })
+ }
+ }()
- err = downloadCmd.Run()
+ err = downloadCmd.Wait()
if err != nil {
logger.Log("Download error: "+err.Error(), types.LogOptions{
Prefix: "Music Player",