From 993cb6d281e167e89192567ffcaa3e204a89764f Mon Sep 17 00:00:00 2001 From: tramhao Date: Thu, 1 Apr 2021 00:07:42 +0800 Subject: [PATCH] add config option rename_bytag, fix bug cannot play when queue is empty --- command.go | 6 +++++- start.go | 4 +++- tageditor.go | 50 ++++++++++++++++++++++++++++++++++++++------------ 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/command.go b/command.go index 451e42c..51f999b 100644 --- a/command.go +++ b/command.go @@ -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() + } } }) diff --git a/start.go b/start.go index d73da69..8b3c84f 100644 --- a/start.go +++ b/start.go @@ -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 { diff --git a/tageditor.go b/tageditor.go index 55d0364..814b0f8 100644 --- a/tageditor.go +++ b/tageditor.go @@ -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) }