diff --git a/playlist.go b/playlist.go index a9a81fd..3206518 100644 --- a/playlist.go +++ b/playlist.go @@ -537,17 +537,19 @@ func Ytdl(url string, selPlaylist *tview.TreeNode) { playlistPath := path.Join(expandTilde(dir), selPlaylistName) - downloadedAudioPath := downloadedFilePath( - stdout.Bytes(), playlistPath) + audioPath := extractFilePath(stdout.Bytes(), playlistPath) - err = gomu.Playlist.AddSongToPlaylist(downloadedAudioPath, selPlaylist) + if err != nil { + appLog(err) + } + err = gomu.Playlist.AddSongToPlaylist(audioPath, selPlaylist) if err != nil { log.Println(err) } downloadFinishedMessage := fmt.Sprintf("Finished downloading\n%s", - path.Base(downloadedAudioPath)) + path.Base(audioPath)) timedPopup( " Ytdl ", @@ -559,3 +561,4 @@ func Ytdl(url string, selPlaylist *tview.TreeNode) { }() } + diff --git a/utils.go b/utils.go index a244686..74743e2 100644 --- a/utils.go +++ b/utils.go @@ -93,13 +93,13 @@ func GetFileContentType(out *os.File) (string, error) { // gets the file name by removing extension and path func GetName(fn string) string { - return strings.TrimSuffix(path.Base(fn), path.Ext(fn)) + return strings.TrimSuffix(path.Base(fn), ".mp3") } // this just parsing the output from the ytdl to get the audio path // this is used because we need to get the song name // example ~/path/to/song/song.mp3 -func downloadedFilePath(output []byte, dir string) string { +func extractFilePath(output []byte, dir string) string { regexSearch := fmt.Sprintf(`\[ffmpeg\] Destination: %s\/.*.mp3`, escapeBackSlash(dir)) diff --git a/utils_test.go b/utils_test.go index 8b148ba..b40948f 100644 --- a/utils_test.go +++ b/utils_test.go @@ -56,7 +56,7 @@ Deleting original file /tmp/Powfu - death bed (coffee for your head) (Official V result := "/tmp/Powfu - death bed (coffee for your head) (Official Video) ft. beabadoobee.mp3" - got := downloadedFilePath([]byte(sample), "/tmp") + got := extractFilePath([]byte(sample), "/tmp") if got != result { t.Errorf("downloadedFilePath(%s); expected %s got %s", sample, result, got)