mirror of
https://github.com/issadarkthing/gomu.git
synced 2025-04-26 13:49:21 +08:00
name refactor
This commit is contained in:
parent
54332e7966
commit
0a1bcc99d1
11
playlist.go
11
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) {
|
||||
}()
|
||||
|
||||
}
|
||||
|
||||
|
4
utils.go
4
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))
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user