This commit is contained in:
raziman 2020-08-11 22:17:00 +08:00
commit 7c43c051b0
4 changed files with 42 additions and 10 deletions

1
config
View File

@ -13,3 +13,4 @@ general:
music_dir: ~/music
popup_timeout: 5s
volume: 100
emoji: true

View File

@ -362,7 +362,8 @@ func (p *Playlist) addSongToPlaylist(
defer f.Close()
node := tview.NewTreeNode(getName(audioPath))
songName := getName(audioPath)
node := tview.NewTreeNode(songName)
audioLength, err := getLength(audioPath)
@ -378,7 +379,14 @@ func (p *Playlist) addSongToPlaylist(
parent: selPlaylist,
}
displayText := songName
if viper.GetBool("general.emoji") {
displayText = fmt.Sprintf("🎵 %s", songName)
}
node.SetReference(audioFile)
node.SetText(displayText)
selPlaylist.AddChild(node)
gomu.app.Draw()
@ -730,8 +738,13 @@ func populate(root *tview.TreeNode, rootPath string) error {
parent: root,
}
displayText := songName
if viper.GetBool("general.emoji") {
displayText = fmt.Sprintf("🎵 %s", songName)
}
child.SetReference(audioFile)
child.SetText(fmt.Sprintf("🎵 %s", songName))
child.SetText(displayText)
root.AddChild(child)
}
@ -744,9 +757,15 @@ func populate(root *tview.TreeNode, rootPath string) error {
node: child,
parent: root,
}
displayText := songName
if viper.GetBool("general.emoji") {
displayText = fmt.Sprintf("📁 %s", songName)
}
child.SetReference(audioFile)
child.SetColor(gomu.accentColor)
child.SetText(fmt.Sprintf("📁 %s", songName))
child.SetText(displayText)
root.AddChild(child)
populate(child, path)

View File

@ -4,6 +4,7 @@ package main
import (
"fmt"
"regexp"
"time"
"github.com/gdamore/tcell"
@ -119,7 +120,8 @@ func topRight(p tview.Primitive, width, height int) tview.Primitive {
AddItem(nil, 0, 1, false)
}
// Width and height parameter is optional. It defaults to 70 and 7 respectively.
// Width and height parameter are optional, provide 0 for both to use deault values.
// It defaults to 70 and 7 respectively.
func timedPopup(
title string, desc string, timeout time.Duration, width, height int,
) {
@ -256,8 +258,10 @@ func helpPopup(panel Panel) {
// Input popup. Takes video url from youtube to be downloaded
func downloadMusicPopup(selPlaylist *tview.TreeNode) {
re := regexp.MustCompile(`^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?$`)
inputField := tview.NewInputField().
SetLabel("Enter a url: ").
SetLabel("Youtube url: ").
SetFieldWidth(0).
SetAcceptanceFunc(tview.InputFieldMaxLength(50)).
SetFieldBackgroundColor(gomu.accentColor).
@ -272,11 +276,18 @@ func downloadMusicPopup(selPlaylist *tview.TreeNode) {
case tcell.KeyEnter:
url := inputField.GetText()
go func() {
if err := ytdl(url, selPlaylist); err != nil {
logError(err)
}
}()
// check if valid youtube url was given
if re.MatchString(url) {
go func() {
if err := ytdl(url, selPlaylist); err != nil {
logError(err)
}
}()
} else {
timedPopup("Invalid url", "Invalid youtube url was given",
getPopupTimeout(), 0, 0)
}
gomu.pages.RemovePage("download-input-popup")
gomu.popups.pop()

View File

@ -70,6 +70,7 @@ func readConfig(args Args) {
viper.SetDefault("general.popup_timeout", "5s")
viper.SetDefault("general.volume", 100)
viper.SetDefault("general.load_prev_queue", true)
viper.SetDefault("general.use_emoji", true)
// Colors
for k, v := range colors {