mirror of
https://github.com/issadarkthing/gomu.git
synced 2025-04-26 13:49:21 +08:00
Tag editor is working
This commit is contained in:
parent
13b8d6b5ba
commit
71c4561a2f
@ -10,11 +10,18 @@ import (
|
||||
"github.com/ztrue/tracerr"
|
||||
)
|
||||
|
||||
type SongTag struct {
|
||||
Artist string
|
||||
Title string
|
||||
Album string
|
||||
}
|
||||
|
||||
// GetLyricOptionsChinese queries available song lyrics. It returns map of title and
|
||||
// id of the lyric.
|
||||
func GetLyricOptionsChinese(search string, serviceProvider string) (map[string]string, error) {
|
||||
func GetLyricOptionsChinese(search string, serviceProvider string) (map[string]string, map[string]SongTag, error) {
|
||||
|
||||
result := make(map[string]string)
|
||||
resultTag := make(map[string]SongTag)
|
||||
p := requests.Params{
|
||||
"site": serviceProvider,
|
||||
"search": search,
|
||||
@ -23,17 +30,21 @@ func GetLyricOptionsChinese(search string, serviceProvider string) (map[string]s
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
resp, err := req.Get("http://api.sunyj.xyz", p)
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
return nil, nil, tracerr.Wrap(err)
|
||||
}
|
||||
|
||||
var dataMap []map[string]interface{}
|
||||
err = resp.Json(&dataMap)
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
return nil, nil, tracerr.Wrap(err)
|
||||
}
|
||||
for _, v := range dataMap {
|
||||
songName := v["name"]
|
||||
resultName := fmt.Sprintf("%s", songName)
|
||||
songArtist := v["artist"]
|
||||
resultArtist := fmt.Sprintf("%s", songArtist)
|
||||
songAlbum := v["album"]
|
||||
resultAlbum := fmt.Sprintf("%s", songAlbum)
|
||||
var lyricID string
|
||||
if serviceProvider == "netease" {
|
||||
lyricIDfloat64 := v["lyric_id"]
|
||||
@ -46,9 +57,14 @@ func GetLyricOptionsChinese(search string, serviceProvider string) (map[string]s
|
||||
continue
|
||||
}
|
||||
result[songTitle] = lyricID
|
||||
var tag SongTag
|
||||
tag.Artist = resultArtist
|
||||
tag.Title = resultName
|
||||
tag.Album = resultAlbum
|
||||
resultTag[lyricID] = tag
|
||||
}
|
||||
|
||||
return result, nil
|
||||
return result, resultTag, nil
|
||||
}
|
||||
|
||||
// GetLyricChinese should receive url that was returned from GetLyricOptions. GetLyric
|
||||
|
2
popup.go
2
popup.go
@ -881,7 +881,7 @@ func lyricPopup(audioFile *AudioFile) error {
|
||||
|
||||
func lyricPopupCN(audioFile *AudioFile, serviceProvider string) error {
|
||||
|
||||
results, err := lyric.GetLyricOptionsChinese(audioFile.name, serviceProvider)
|
||||
results, _, err := lyric.GetLyricOptionsChinese(audioFile.name, serviceProvider)
|
||||
if err != nil {
|
||||
return tracerr.Wrap(err)
|
||||
}
|
||||
|
5
start.go
5
start.go
@ -474,6 +474,11 @@ func start(application *tview.Application, args Args) {
|
||||
gomu.playingBar.setDefault()
|
||||
init = true
|
||||
}
|
||||
if gomu.player.IsRunning() {
|
||||
gomu.playingBar.setSongTitle(gomu.player.GetCurrentSong().Name())
|
||||
} else {
|
||||
gomu.playingBar.setDefault()
|
||||
}
|
||||
})
|
||||
|
||||
go populateAudioLength(gomu.playlist.GetRoot())
|
||||
|
59
tageditor.go
59
tageditor.go
@ -27,13 +27,13 @@ func tagPopup(node *AudioFile) (err error) {
|
||||
artistInputField *tview.InputField = tview.NewInputField()
|
||||
titleInputField *tview.InputField = tview.NewInputField()
|
||||
albumInputField *tview.InputField = tview.NewInputField()
|
||||
getTagButton *tview.Button = tview.NewButton("Get Tag")
|
||||
saveTagButton *tview.Button = tview.NewButton("Save Tag")
|
||||
getTagButton *tview.Button = tview.NewButton("[G1]Get Tag")
|
||||
saveTagButton *tview.Button = tview.NewButton("[S]Save Tag")
|
||||
lyricDropDown *tview.DropDown = tview.NewDropDown()
|
||||
deleteLyricButton *tview.Button = tview.NewButton("Delete Lyric")
|
||||
getLyric1Button *tview.Button = tview.NewButton("Get Lyric 1(en)")
|
||||
getLyric2Button *tview.Button = tview.NewButton("Get Lyric 2(zh-CN)")
|
||||
getLyric3Button *tview.Button = tview.NewButton("Get Lyric 3(zh-CN)")
|
||||
deleteLyricButton *tview.Button = tview.NewButton("[D]Delete Lyric")
|
||||
getLyric1Button *tview.Button = tview.NewButton("[1]Get Lyric 1(en)")
|
||||
getLyric2Button *tview.Button = tview.NewButton("[2]Get Lyric 2(zh-CN)")
|
||||
getLyric3Button *tview.Button = tview.NewButton("[3]Get Lyric 3(zh-CN)")
|
||||
lyricTextView *tview.TextView
|
||||
leftGrid *tview.Grid = tview.NewGrid()
|
||||
rightFlex *tview.Flex = tview.NewFlex()
|
||||
@ -53,7 +53,48 @@ func tagPopup(node *AudioFile) (err error) {
|
||||
SetText(tag.Album()).
|
||||
SetFieldBackgroundColor(gomu.colors.popup).
|
||||
SetBackgroundColor(gomu.colors.background)
|
||||
getTagButton.SetBorder(true).
|
||||
getTagButton.SetSelectedFunc(func() {
|
||||
audioFile := node
|
||||
serviceProvider := "netease"
|
||||
results, resultsTag, err := lyric.GetLyricOptionsChinese(audioFile.name, serviceProvider)
|
||||
if err != nil {
|
||||
errorPopup(err)
|
||||
return
|
||||
}
|
||||
|
||||
titles := make([]string, 0, len(results))
|
||||
|
||||
for result := range results {
|
||||
titles = append(titles, result)
|
||||
}
|
||||
|
||||
searchPopup(" Lyrics ", titles, func(selected string) {
|
||||
if selected == "" {
|
||||
return
|
||||
}
|
||||
|
||||
lyricID := results[selected]
|
||||
newTag := resultsTag[lyricID]
|
||||
artistInputField.SetText(newTag.Artist)
|
||||
titleInputField.SetText(newTag.Title)
|
||||
albumInputField.SetText(newTag.Album)
|
||||
tag, err = id3v2.Open(node.path, id3v2.Options{Parse: true})
|
||||
if err != nil {
|
||||
errorPopup(err)
|
||||
}
|
||||
defer tag.Close()
|
||||
tag.SetArtist(artistInputField.GetText())
|
||||
tag.SetTitle(titleInputField.GetText())
|
||||
tag.SetAlbum(albumInputField.GetText())
|
||||
err = tag.Save()
|
||||
if err != nil {
|
||||
errorPopup(err)
|
||||
} else {
|
||||
defaultTimedPopup(" Success ", "Tag update successfully")
|
||||
}
|
||||
})
|
||||
}).
|
||||
SetBorder(true).
|
||||
SetBackgroundColor(gomu.colors.background).
|
||||
SetTitleColor(gomu.colors.accent)
|
||||
saveTagButton.SetSelectedFunc(func() {
|
||||
@ -195,7 +236,7 @@ func tagPopup(node *AudioFile) (err error) {
|
||||
getLyric2Button.SetSelectedFunc(func() {
|
||||
audioFile := node
|
||||
serviceProvider := "netease"
|
||||
results, err := lyric.GetLyricOptionsChinese(audioFile.name, serviceProvider)
|
||||
results, _, err := lyric.GetLyricOptionsChinese(audioFile.name, serviceProvider)
|
||||
if err != nil {
|
||||
errorPopup(err)
|
||||
return
|
||||
@ -263,7 +304,7 @@ func tagPopup(node *AudioFile) (err error) {
|
||||
getLyric3Button.SetSelectedFunc(func() {
|
||||
audioFile := node
|
||||
serviceProvider := "kugou"
|
||||
results, err := lyric.GetLyricOptionsChinese(audioFile.name, serviceProvider)
|
||||
results, _, err := lyric.GetLyricOptionsChinese(audioFile.name, serviceProvider)
|
||||
if err != nil {
|
||||
errorPopup(err)
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user