add config option rename_bytag, fix bug cannot play when queue is empty

This commit is contained in:
tramhao 2021-04-01 00:07:42 +08:00
parent 887026a58d
commit 993cb6d281
3 changed files with 46 additions and 14 deletions

View File

@ -205,7 +205,11 @@ func (c Command) defineCommands() {
}
gomu.queue.pushFront(a)
gomu.player.Skip()
if gomu.player.IsRunning() {
gomu.player.Skip()
} else {
gomu.queue.playQueue()
}
}
})

View File

@ -241,9 +241,11 @@ module General {
invidious_instance = "https://vid.puffyan.us"
# Prefered language for lyrics to be displayed, if not available, english version
# will be displayed.
# Available tags: en,el,ko,es,th,vi,zh-Hans,zh-Hant, and can be separated with comma.
# Available tags: en,el,ko,es,th,vi,zh-Hans,zh-Hant,zh-CN and can be separated with comma.
# find more tags: youtube-dl --skip-download --list-subs "url"
lang_lyric = "en"
# When save tag, could rename the file by tag info: artist-songname-album
rename_bytag = false
}
module Emoji {

View File

@ -64,6 +64,14 @@ func tagPopup(node *AudioFile) (err error) {
SetText(tag.Album()).
SetFieldBackgroundColor(gomu.colors.popup)
leftBox := tview.NewBox().
SetBorder(true).
SetTitle(node.name).
SetBackgroundColor(gomu.colors.popup).
SetBorderColor(gomu.colors.accent).
SetTitleColor(gomu.colors.accent).
SetBorderPadding(1, 1, 2, 2)
getTagButton.SetSelectedFunc(func() {
var titles []string
audioFile := node
@ -111,6 +119,16 @@ func tagPopup(node *AudioFile) (err error) {
errorPopup(err)
return
}
if gomu.anko.GetBool("General.rename_bytag") {
newName := fmt.Sprintf("%s-%s", newTag.Artist, newTag.Title)
err = gomu.playlist.rename(newName)
if err != nil {
errorPopup(err)
return
}
gomu.playlist.refresh()
leftBox.SetTitle(newName)
}
defaultTimedPopup(" Success ", "Tag update successfully")
})
}()
@ -129,14 +147,28 @@ func tagPopup(node *AudioFile) (err error) {
return
}
defer tag.Close()
tag.SetArtist(artistInputField.GetText())
tag.SetTitle(titleInputField.GetText())
tag.SetAlbum(albumInputField.GetText())
newArtist := artistInputField.GetText()
newTitle := titleInputField.GetText()
newAlbum := albumInputField.GetText()
tag.SetArtist(newArtist)
tag.SetTitle(newTitle)
tag.SetAlbum(newAlbum)
err = tag.Save()
if err != nil {
errorPopup(err)
return
}
if gomu.anko.GetBool("General.rename_bytag") {
newName := fmt.Sprintf("%s-%s", newArtist, newTitle)
err = gomu.playlist.rename(newName)
if err != nil {
errorPopup(err)
return
}
gomu.playlist.refresh()
leftBox.SetTitle(newName)
}
defaultTimedPopup(" Success ", "Tag update successfully")
}).
@ -331,13 +363,7 @@ func tagPopup(node *AudioFile) (err error) {
AddItem(rightFlex, 0, 3, true),
nil,
nil,
tview.NewBox().
SetBorder(true).
SetTitle(node.name).
SetBackgroundColor(gomu.colors.popup).
SetBorderColor(gomu.colors.accent).
SetTitleColor(gomu.colors.accent).
SetBorderPadding(1, 1, 2, 2),
leftBox,
}
leftGrid.Box = lyricFlex.box
@ -369,9 +395,9 @@ func tagPopup(node *AudioFile) (err error) {
lyricFlex.cycleFocus(gomu.app, false)
case tcell.KeyBacktab, tcell.KeyCtrlP, tcell.KeyCtrlK:
lyricFlex.cycleFocus(gomu.app, true)
case tcell.KeyRight:
case tcell.KeyDown:
lyricFlex.cycleFocus(gomu.app, false)
case tcell.KeyLeft:
case tcell.KeyUp:
lyricFlex.cycleFocus(gomu.app, true)
}