diff options
| author | Bobby <[email protected]> | 2025-04-13 19:14:23 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2025-04-13 19:14:23 +0530 |
| commit | 35abc793567dddb5c2df8ac2f2944c35399d6e6f (patch) | |
| tree | ee5a6435ce554f438e05b69148f70fd72b63f1aa | |
| parent | 47307124cf224590d0ce62faa933cf3b50c6ff91 (diff) | |
| download | ai-35abc793567dddb5c2df8ac2f2944c35399d6e6f.tar.xz ai-35abc793567dddb5c2df8ac2f2944c35399d6e6f.zip | |
add extra logging to yt-dlp to catch errors
| -rw-r--r-- | utils/music/voice.go | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/utils/music/voice.go b/utils/music/voice.go index ab0a3f2..ea8ffc0 100644 --- a/utils/music/voice.go +++ b/utils/music/voice.go @@ -3,6 +3,7 @@ package music import ( "ai/types" "ai/utils/logger" + "bytes" "encoding/binary" "fmt" "io" @@ -184,20 +185,24 @@ func (v *VoiceInstance) PlayYouTube(videoURL, videoID string) error { return err } - fileName := fmt.Sprintf("./temp/%s_%d.mp3", videoID, time.Now().Unix()) - logger.Log("Downloading to: "+fileName, types.LogOptions{ + baseName := fmt.Sprintf("./temp/%s_%d", videoID, time.Now().Unix()) + outputPath := baseName + ".mp3" + + logger.Log("Downloading to: "+outputPath, types.LogOptions{ Prefix: "Music Player", Level: types.Debug, }) - 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 + var stderrOutput bytes.Buffer + downloadCmd := exec.Command("yt-dlp", + "--no-warnings", "--quiet", "-x", + "--audio-format", "mp3", + "--audio-quality", "0", + "--no-playlist", + "--output", baseName+".%(ext)s", + videoURL, + ) + downloadCmd.Stderr = &stderrOutput logger.Log("Starting download", types.LogOptions{ Prefix: "Music Player", @@ -210,6 +215,10 @@ func (v *VoiceInstance) PlayYouTube(videoURL, videoID string) error { Prefix: "Music Player", Level: types.Error, }) + logger.Log("yt-dlp stderr: "+stderrOutput.String(), types.LogOptions{ + Prefix: "Music Player", + Level: types.Error, + }) v.mu.Lock() v.Playing = false v.mu.Unlock() @@ -221,7 +230,7 @@ func (v *VoiceInstance) PlayYouTube(videoURL, videoID string) error { Level: types.Info, }) - fileInfo, err := os.Stat(fileName) + fileInfo, err := os.Stat(outputPath) if err != nil { logger.Log("File stat error: "+err.Error(), types.LogOptions{ Prefix: "Music Player", @@ -238,9 +247,9 @@ func (v *VoiceInstance) PlayYouTube(videoURL, videoID string) error { Level: types.Debug, }) - defer os.Remove(fileName) + defer os.Remove(outputPath) - err = v.playAudioFile(fileName, stopChan) + err = v.playAudioFile(outputPath, stopChan) if err != nil { logger.Log("Playback error: "+err.Error(), types.LogOptions{ Prefix: "Music Player", |
