select sylt if available

This commit is contained in:
tramhao 2021-03-15 03:03:12 +08:00
parent a4498fe8c0
commit 884782432e
5 changed files with 24 additions and 18 deletions

4
go.mod
View File

@ -2,9 +2,9 @@ module github.com/issadarkthing/gomu
go 1.14 go 1.14
replace github.com/bogem/id3v2 v1.2.0 => /home/tramhao/.local/src/id3v2 // replace github.com/bogem/id3v2 v1.2.0 => /home/tramhao/.local/src/id3v2
// replace github.com/bogem/id3v2 v1.2.0 => github.com/tramhao/id3v2 v1.2.1-0.20210312170538-66359bf3a82d replace github.com/bogem/id3v2 v1.2.0 => github.com/tramhao/id3v2 v1.2.1-0.20210314184634-d13ef0e6c7e8
require ( require (
github.com/PuerkitoBio/goquery v1.6.1 // indirect github.com/PuerkitoBio/goquery v1.6.1 // indirect

2
go.sum
View File

@ -94,6 +94,8 @@ github.com/tramhao/id3v2 v1.2.1-0.20210312065634-d90e31d07ff0 h1:E7hGI929X/GMlik
github.com/tramhao/id3v2 v1.2.1-0.20210312065634-d90e31d07ff0/go.mod h1:4jmC9bwoDhtGTsDkEBwSUlUgJq/D+8w4626jvM1Oo1k= github.com/tramhao/id3v2 v1.2.1-0.20210312065634-d90e31d07ff0/go.mod h1:4jmC9bwoDhtGTsDkEBwSUlUgJq/D+8w4626jvM1Oo1k=
github.com/tramhao/id3v2 v1.2.1-0.20210312170538-66359bf3a82d h1:AOeJZc5ajdVbRNiq41266b+P341CAXwZO8OdRvPmN9c= github.com/tramhao/id3v2 v1.2.1-0.20210312170538-66359bf3a82d h1:AOeJZc5ajdVbRNiq41266b+P341CAXwZO8OdRvPmN9c=
github.com/tramhao/id3v2 v1.2.1-0.20210312170538-66359bf3a82d/go.mod h1:4jmC9bwoDhtGTsDkEBwSUlUgJq/D+8w4626jvM1Oo1k= github.com/tramhao/id3v2 v1.2.1-0.20210312170538-66359bf3a82d/go.mod h1:4jmC9bwoDhtGTsDkEBwSUlUgJq/D+8w4626jvM1Oo1k=
github.com/tramhao/id3v2 v1.2.1-0.20210314184634-d13ef0e6c7e8 h1:MfHRPlPLDZKr0cPNAt7M+ZiHhFAS9NNK7Pkg45CGutA=
github.com/tramhao/id3v2 v1.2.1-0.20210314184634-d13ef0e6c7e8/go.mod h1:4jmC9bwoDhtGTsDkEBwSUlUgJq/D+8w4626jvM1Oo1k=
github.com/ztrue/tracerr v0.3.0 h1:lDi6EgEYhPYPnKcjsYzmWw4EkFEoA/gfe+I9Y5f+h6Y= github.com/ztrue/tracerr v0.3.0 h1:lDi6EgEYhPYPnKcjsYzmWw4EkFEoA/gfe+I9Y5f+h6Y=
github.com/ztrue/tracerr v0.3.0/go.mod h1:qEalzze4VN9O8tnhBXScfCrmoJo10o8TN5ciKjm6Mww= github.com/ztrue/tracerr v0.3.0/go.mod h1:qEalzze4VN9O8tnhBXScfCrmoJo10o8TN5ciKjm6Mww=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

View File

@ -87,7 +87,7 @@ func NewFromLRC(s string) (res Lyric, err error) {
matchStart := r1.FindStringSubmatch(lines[i]) matchStart := r1.FindStringSubmatch(lines[i])
if len(matchStart) < 1 { if len(matchStart) < 1 {
// Here we continue to parse the subtitle and ignore the lines have no startTime // Here we continue to parse the subtitle and ignore the lines have no timestamp
continue continue
} }
@ -108,7 +108,7 @@ func NewFromLRC(s string) (res Lyric, err error) {
return return
} }
// parseLrcTime parses a lrc subtitle time (duration since start of film) // parseLrcTime parses a lrc subtitle time (ms since start of song)
func parseLrcTime(in string) (uint32, error) { func parseLrcTime(in string) (uint32, error) {
in = strings.TrimPrefix(in, "[") in = strings.TrimPrefix(in, "[")
in = strings.TrimSuffix(in, "]") in = strings.TrimSuffix(in, "]")

View File

@ -31,6 +31,7 @@ type PlayingBar struct {
type gomuSubtitle struct { type gomuSubtitle struct {
langExt string langExt string
isSync bool
subtitle *lyric.Lyric subtitle *lyric.Lyric
} }
@ -146,25 +147,29 @@ func (p *PlayingBar) newProgress(currentSong *AudioFile, full int) {
langLyricFromConfig = "en" langLyricFromConfig = "en"
} }
if p.hasTag && p.subtitles != nil { if p.hasTag && p.subtitles != nil {
// First we check if the lyric language prefered is presented // First we check if the lyric language preferred is presented
for i := range p.subtitles { for _, v := range p.subtitles {
if strings.Contains(langLyricFromConfig, p.subtitles[i].langExt) { if strings.Contains(langLyricFromConfig, v.langExt) {
p.subtitle = p.subtitles[i].subtitle p.subtitle = v.subtitle
p.langLyricCurrentPlaying = p.subtitles[i].langExt p.langLyricCurrentPlaying = v.langExt
if v.isSync {
break break
} }
} }
}
// Secondly we check if english lyric is available // Secondly we check if english lyric is available
if p.subtitle == nil { if p.subtitle == nil {
for i := range p.subtitles { for _, v := range p.subtitles {
if p.subtitles[i].langExt == "en" { if v.langExt == "en" {
p.subtitle = p.subtitles[i].subtitle p.subtitle = v.subtitle
p.langLyricCurrentPlaying = "en" p.langLyricCurrentPlaying = "en"
if v.isSync {
break break
} }
} }
} }
}
// Finally we display the first lyric // Finally we display the first lyric
if p.subtitle == nil { if p.subtitle == nil {
@ -278,6 +283,7 @@ func (p *PlayingBar) loadLyrics(currentSongPath string) error {
} }
subtitle := &gomuSubtitle{ subtitle := &gomuSubtitle{
langExt: uslf.ContentDescriptor, langExt: uslf.ContentDescriptor,
isSync: false,
subtitle: &res, subtitle: &res,
} }
p.subtitles = append(p.subtitles, subtitle) p.subtitles = append(p.subtitles, subtitle)
@ -305,6 +311,7 @@ func (p *PlayingBar) loadLyrics(currentSongPath string) error {
} }
subtitle := &gomuSubtitle{ subtitle := &gomuSubtitle{
langExt: sylf.ContentDescriptor, langExt: sylf.ContentDescriptor,
isSync: true,
subtitle: &lyric, subtitle: &lyric,
} }
p.subtitles = append(p.subtitles, subtitle) p.subtitles = append(p.subtitles, subtitle)

View File

@ -320,9 +320,6 @@ func embedSyncLyric(songPath string, lyricContent string, usltContentDescriptor
var syncedTextSlice []id3v2.SyncedText var syncedTextSlice []id3v2.SyncedText
for _, v := range lyric.Captions { for _, v := range lyric.Captions {
// timeStampDuration := v.Timestamp.Sub(time.Date(0, 1, 1, 0, 0, 0, 0, time.UTC))
// timeStampDuration += lyric.Offset
// timeStamp := timeStampDuration.Milliseconds()
timeStamp := v.Timestamp timeStamp := v.Timestamp
if lyric.Offset >= 0 { if lyric.Offset >= 0 {
timeStamp += uint32(lyric.Offset) timeStamp += uint32(lyric.Offset)
@ -345,7 +342,7 @@ func embedSyncLyric(songPath string, lyricContent string, usltContentDescriptor
Language: "eng", Language: "eng",
TimestampFormat: 2, TimestampFormat: 2,
ContentType: 1, ContentType: 1,
ContentDescriptor: usltContentDescriptor + " Sync", ContentDescriptor: usltContentDescriptor,
SynchronizedTexts: syncedTextSlice, SynchronizedTexts: syncedTextSlice,
}) })
} }