name refactor

This commit is contained in:
raziman 2020-07-12 17:04:33 +08:00
parent 54332e7966
commit 0a1bcc99d1
3 changed files with 10 additions and 7 deletions

View File

@ -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) {
}()
}

View File

@ -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))

View File

@ -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)