mirror of
https://github.com/issadarkthing/gomu.git
synced 2025-04-26 13:49:21 +08:00
Merge pull request #26 from tramhao/master
Fix a bug of embedLyric and add a function to adjust lyric delay
This commit is contained in:
commit
a24d334638
@ -103,6 +103,8 @@ Each panel has it's own additional keybinding. To view the available keybinding
|
||||
| z | toggle loop |
|
||||
| s | shuffle |
|
||||
| / | find in queue |
|
||||
| t | lyric delay increase 1 second |
|
||||
| r | lyric delay decrease 1 second |
|
||||
|
||||
### Scripting
|
||||
|
||||
|
14
command.go
14
command.go
@ -404,6 +404,20 @@ func (c Command) defineCommands() {
|
||||
}
|
||||
})
|
||||
|
||||
c.define("lyric_delay_increase", func() {
|
||||
err := gomu.playingBar.delayLyric(1000)
|
||||
if err != nil {
|
||||
logError(err)
|
||||
}
|
||||
})
|
||||
|
||||
c.define("lyric_delay_decrease", func() {
|
||||
err := gomu.playingBar.delayLyric(-1000)
|
||||
if err != nil {
|
||||
logError(err)
|
||||
}
|
||||
})
|
||||
|
||||
for name, cmd := range c.commands {
|
||||
err := gomu.anko.Define(name, cmd)
|
||||
if err != nil {
|
||||
|
@ -17,16 +17,17 @@ import (
|
||||
|
||||
type PlayingBar struct {
|
||||
*tview.Frame
|
||||
full int
|
||||
update chan struct{}
|
||||
progress int
|
||||
skip bool
|
||||
text *tview.TextView
|
||||
hasTag bool
|
||||
tag *id3v2.Tag
|
||||
subtitle *subtitles.Subtitle
|
||||
subtitles []*gomuSubtitle
|
||||
langLyric string
|
||||
full int
|
||||
update chan struct{}
|
||||
progress int
|
||||
skip bool
|
||||
text *tview.TextView
|
||||
hasTag bool
|
||||
tag *id3v2.Tag
|
||||
subtitle *subtitles.Subtitle
|
||||
subtitles []*gomuSubtitle
|
||||
langConfigFromConfig string
|
||||
langLyricCurrentPlaying string
|
||||
}
|
||||
|
||||
type gomuSubtitle struct {
|
||||
@ -46,8 +47,8 @@ func newPlayingBar() *PlayingBar {
|
||||
frame.SetBorder(true).SetTitle(" Now Playing ")
|
||||
|
||||
p := &PlayingBar{
|
||||
Frame: frame,
|
||||
text: textView,
|
||||
Frame: frame,
|
||||
text: textView,
|
||||
update: make(chan struct{}),
|
||||
}
|
||||
|
||||
@ -88,8 +89,9 @@ func (p *PlayingBar) run() error {
|
||||
if p.hasTag && p.subtitles != nil {
|
||||
for i := range p.subtitles {
|
||||
// First we check if the lyric language prefered is presented
|
||||
if strings.Contains(p.langLyric, p.subtitles[i].langExt) {
|
||||
if strings.Contains(p.langConfigFromConfig, p.subtitles[i].langExt) {
|
||||
p.subtitle = p.subtitles[i].subtitle
|
||||
p.langLyricCurrentPlaying = p.subtitles[i].langExt
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -97,9 +99,9 @@ func (p *PlayingBar) run() error {
|
||||
// Secondly we check if english lyric is available
|
||||
if p.subtitle == nil {
|
||||
for i := range p.subtitles {
|
||||
if strings.Contains(p.langLyric, "en") {
|
||||
if p.subtitles[i].langExt == "en" {
|
||||
p.subtitle = p.subtitles[i].subtitle
|
||||
p.langLyric = "en"
|
||||
p.langLyricCurrentPlaying = "en"
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -108,7 +110,7 @@ func (p *PlayingBar) run() error {
|
||||
// Finally we display the first lyric
|
||||
if p.subtitle == nil {
|
||||
p.subtitle = p.subtitles[0].subtitle
|
||||
p.langLyric = p.subtitles[0].langExt
|
||||
p.langLyricCurrentPlaying = p.subtitles[0].langExt
|
||||
}
|
||||
|
||||
var lyricText string
|
||||
@ -186,9 +188,9 @@ func (p *PlayingBar) newProgress(currentSong *AudioFile, full int) {
|
||||
subtitle: &res,
|
||||
}
|
||||
p.subtitles = append(p.subtitles, subtitle)
|
||||
p.langLyric = gomu.anko.GetString("General.lang_lyric")
|
||||
if p.langLyric == "" {
|
||||
p.langLyric = "en"
|
||||
p.langConfigFromConfig = gomu.anko.GetString("General.lang_lyric")
|
||||
if p.langConfigFromConfig == "" {
|
||||
p.langConfigFromConfig = "en"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -218,7 +220,7 @@ func (p *PlayingBar) switchLyrics() {
|
||||
|
||||
var langIndex int
|
||||
for i := range p.subtitles {
|
||||
if p.subtitles[i].langExt == p.langLyric {
|
||||
if p.subtitles[i].langExt == p.langConfigFromConfig {
|
||||
langIndex = i + 1
|
||||
break
|
||||
}
|
||||
@ -228,7 +230,17 @@ func (p *PlayingBar) switchLyrics() {
|
||||
langIndex = 0
|
||||
}
|
||||
|
||||
p.langLyric = p.subtitles[langIndex].langExt
|
||||
defaultTimedPopup(" Success ", p.langLyric+" lyric switched successfully.")
|
||||
p.langConfigFromConfig = p.subtitles[langIndex].langExt
|
||||
defaultTimedPopup(" Success ", p.langConfigFromConfig+" lyric switched successfully.")
|
||||
|
||||
}
|
||||
|
||||
func (p *PlayingBar) delayLyric(lyricDelay int) (err error) {
|
||||
|
||||
p.subtitle.ResyncSubs(lyricDelay)
|
||||
err = embedLyric(gomu.player.currentSong.path, p.subtitle.AsSRT(), p.langLyricCurrentPlaying)
|
||||
if err != nil {
|
||||
return tracerr.Wrap(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
4
queue.go
4
queue.go
@ -330,6 +330,8 @@ func (q *Queue) help() []string {
|
||||
"z toggle loop",
|
||||
"s shuffle",
|
||||
"/ find in queue",
|
||||
"t lyric delay increase 1 second",
|
||||
"r lyric delay decrease 1 second",
|
||||
}
|
||||
|
||||
}
|
||||
@ -390,6 +392,8 @@ func newQueue() *Queue {
|
||||
'z': "toggle_loop",
|
||||
's': "shuffle_queue",
|
||||
'/': "queue_search",
|
||||
't': "lyric_delay_increase",
|
||||
'r': "lyric_delay_decrease",
|
||||
}
|
||||
|
||||
for key, cmd := range cmds {
|
||||
|
14
utils.go
14
utils.go
@ -249,7 +249,19 @@ func embedLyric(songPath string, lyricContent string, usltContentDescriptor stri
|
||||
return tracerr.Wrap(err)
|
||||
}
|
||||
defer tag.Close()
|
||||
|
||||
usltFrames := tag.GetFrames(tag.CommonID("Unsynchronised lyrics/text transcription"))
|
||||
tag.DeleteFrames(tag.CommonID("Unsynchronised lyrics/text transcription"))
|
||||
// We delete the lyric frame with same language by delete all and add others back
|
||||
for _, f := range usltFrames {
|
||||
uslf, ok := f.(id3v2.UnsynchronisedLyricsFrame)
|
||||
if !ok {
|
||||
die(errors.New("USLT error!"))
|
||||
}
|
||||
if uslf.ContentDescriptor == usltContentDescriptor {
|
||||
continue
|
||||
}
|
||||
tag.AddUnsynchronisedLyricsFrame(uslf)
|
||||
}
|
||||
tag.AddUnsynchronisedLyricsFrame(id3v2.UnsynchronisedLyricsFrame{
|
||||
Encoding: id3v2.EncodingUTF8,
|
||||
Language: "eng",
|
||||
|
Loading…
x
Reference in New Issue
Block a user