mirror of
https://github.com/issadarkthing/gomu.git
synced 2025-04-26 13:49:21 +08:00
select sylt if available
This commit is contained in:
parent
a4498fe8c0
commit
884782432e
4
go.mod
4
go.mod
@ -2,9 +2,9 @@ module github.com/issadarkthing/gomu
|
||||
|
||||
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 (
|
||||
github.com/PuerkitoBio/goquery v1.6.1 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -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.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.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/go.mod h1:qEalzze4VN9O8tnhBXScfCrmoJo10o8TN5ciKjm6Mww=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
|
@ -87,7 +87,7 @@ func NewFromLRC(s string) (res Lyric, err error) {
|
||||
matchStart := r1.FindStringSubmatch(lines[i])
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ func NewFromLRC(s string) (res Lyric, err error) {
|
||||
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) {
|
||||
in = strings.TrimPrefix(in, "[")
|
||||
in = strings.TrimSuffix(in, "]")
|
||||
|
@ -31,6 +31,7 @@ type PlayingBar struct {
|
||||
|
||||
type gomuSubtitle struct {
|
||||
langExt string
|
||||
isSync bool
|
||||
subtitle *lyric.Lyric
|
||||
}
|
||||
|
||||
@ -146,22 +147,26 @@ func (p *PlayingBar) newProgress(currentSong *AudioFile, full int) {
|
||||
langLyricFromConfig = "en"
|
||||
}
|
||||
if p.hasTag && p.subtitles != nil {
|
||||
// First we check if the lyric language prefered is presented
|
||||
for i := range p.subtitles {
|
||||
if strings.Contains(langLyricFromConfig, p.subtitles[i].langExt) {
|
||||
p.subtitle = p.subtitles[i].subtitle
|
||||
p.langLyricCurrentPlaying = p.subtitles[i].langExt
|
||||
break
|
||||
// First we check if the lyric language preferred is presented
|
||||
for _, v := range p.subtitles {
|
||||
if strings.Contains(langLyricFromConfig, v.langExt) {
|
||||
p.subtitle = v.subtitle
|
||||
p.langLyricCurrentPlaying = v.langExt
|
||||
if v.isSync {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Secondly we check if english lyric is available
|
||||
if p.subtitle == nil {
|
||||
for i := range p.subtitles {
|
||||
if p.subtitles[i].langExt == "en" {
|
||||
p.subtitle = p.subtitles[i].subtitle
|
||||
for _, v := range p.subtitles {
|
||||
if v.langExt == "en" {
|
||||
p.subtitle = v.subtitle
|
||||
p.langLyricCurrentPlaying = "en"
|
||||
break
|
||||
if v.isSync {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -278,6 +283,7 @@ func (p *PlayingBar) loadLyrics(currentSongPath string) error {
|
||||
}
|
||||
subtitle := &gomuSubtitle{
|
||||
langExt: uslf.ContentDescriptor,
|
||||
isSync: false,
|
||||
subtitle: &res,
|
||||
}
|
||||
p.subtitles = append(p.subtitles, subtitle)
|
||||
@ -305,6 +311,7 @@ func (p *PlayingBar) loadLyrics(currentSongPath string) error {
|
||||
}
|
||||
subtitle := &gomuSubtitle{
|
||||
langExt: sylf.ContentDescriptor,
|
||||
isSync: true,
|
||||
subtitle: &lyric,
|
||||
}
|
||||
p.subtitles = append(p.subtitles, subtitle)
|
||||
|
5
utils.go
5
utils.go
@ -320,9 +320,6 @@ func embedSyncLyric(songPath string, lyricContent string, usltContentDescriptor
|
||||
|
||||
var syncedTextSlice []id3v2.SyncedText
|
||||
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
|
||||
if lyric.Offset >= 0 {
|
||||
timeStamp += uint32(lyric.Offset)
|
||||
@ -345,7 +342,7 @@ func embedSyncLyric(songPath string, lyricContent string, usltContentDescriptor
|
||||
Language: "eng",
|
||||
TimestampFormat: 2,
|
||||
ContentType: 1,
|
||||
ContentDescriptor: usltContentDescriptor + " Sync",
|
||||
ContentDescriptor: usltContentDescriptor,
|
||||
SynchronizedTexts: syncedTextSlice,
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user