mirror of
https://github.com/issadarkthing/gomu.git
synced 2025-05-02 22:17:09 +08:00
Merge branch 'master' of https://github.com/issadarkthing/gomu
This commit is contained in:
commit
7c43c051b0
1
config
1
config
@ -13,3 +13,4 @@ general:
|
||||
music_dir: ~/music
|
||||
popup_timeout: 5s
|
||||
volume: 100
|
||||
emoji: true
|
||||
|
25
playlist.go
25
playlist.go
@ -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)
|
||||
|
||||
|
15
popup.go
15
popup.go
@ -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()
|
||||
|
||||
// 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()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user