From a30b871b5cacae342b4e6b9cba8a7ced5e4ca5cd Mon Sep 17 00:00:00 2001 From: tramhao Date: Sat, 27 Feb 2021 23:11:17 +0800 Subject: [PATCH] lyric chinese in progress --- command.go | 17 +++++ go.mod | 3 +- go.sum | 17 +---- lyric/lrc.go | 161 +++++++++++++++++++++++++++++++++++++++++ lyric/lyric_chinese.go | 82 +++++++++++++++++++++ playingbar.go | 2 + playlist.go | 3 +- popup.go | 46 ++++++++++++ 8 files changed, 316 insertions(+), 15 deletions(-) create mode 100644 lyric/lrc.go create mode 100644 lyric/lyric_chinese.go diff --git a/command.go b/command.go index c42fcb0..0f0659a 100644 --- a/command.go +++ b/command.go @@ -398,6 +398,23 @@ func (c Command) defineCommands() { err := lyricPopup(audioFile) if err != nil { errorPopup(err) + gomu.app.Draw() + } + }) + }() + } + }) + + c.define("fetch_lyric_cn", func() { + audioFile := gomu.playlist.getCurrentFile() + + if audioFile.isAudioFile { + go func() { + gomu.app.QueueUpdateDraw(func() { + err := lyricPopupCN(audioFile) + if err != nil { + errorPopup(err) + gomu.app.Draw() } }) }() diff --git a/go.mod b/go.mod index 7ff1c9f..482a20f 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/PuerkitoBio/goquery v1.6.1 // indirect github.com/antchfx/htmlquery v1.2.3 // indirect github.com/antchfx/xmlquery v1.3.4 // indirect + github.com/asmcos/requests v0.0.0-20210118082303-cb8f46dd3767 github.com/bogem/id3v2 v1.2.0 github.com/faiface/beep v1.0.2 github.com/gdamore/tcell/v2 v2.1.0 @@ -15,7 +16,7 @@ require ( github.com/hajimehoshi/oto v0.7.1 // indirect github.com/kylelemons/godebug v1.1.0 // indirect github.com/logrusorgru/aurora v2.0.3+incompatible // indirect - github.com/martinlindhe/subtitles v0.0.0-20210219114018-c133f18cfb3d + github.com/martinlindhe/subtitles v0.0.0-20210226093915-8010a8a9b389 github.com/mattn/anko v0.1.8 github.com/pkg/errors v0.9.1 // indirect github.com/rivo/tview v0.0.0-20210125085121-dbc1f32bb1d0 diff --git a/go.sum b/go.sum index 58b1c74..5da739f 100644 --- a/go.sum +++ b/go.sum @@ -13,9 +13,10 @@ github.com/antchfx/xmlquery v1.3.4/go.mod h1:64w0Xesg2sTaawIdNqMB+7qaW/bSqkQm+ss github.com/antchfx/xpath v1.1.6/go.mod h1:Yee4kTMuNiPYJ7nSNorELQMr1J33uOpXDMByNYhvtNk= github.com/antchfx/xpath v1.1.10 h1:cJ0pOvEdN/WvYXxvRrzQH9x5QWKpzHacYO8qzCcDYAg= github.com/antchfx/xpath v1.1.10/go.mod h1:Yee4kTMuNiPYJ7nSNorELQMr1J33uOpXDMByNYhvtNk= +github.com/asmcos/requests v0.0.0-20210118082303-cb8f46dd3767 h1:/2W6hzSR62YUThJdMsKkx4n1kpe05cH8T21Jk0j3msA= +github.com/asmcos/requests v0.0.0-20210118082303-cb8f46dd3767/go.mod h1:2W5PB6UTVRBypeouEebhwOJrDZOfJvPwMP1mtD8ZXM4= github.com/bogem/id3v2 v1.2.0 h1:hKDF+F1gOgQ5r1QmBCEZUk4MveJbKxCeIDSBU7CQ4oI= github.com/bogem/id3v2 v1.2.0/go.mod h1:t78PK5AQ56Q47kizpYiV6gtjj3jfxlz87oFpty8DYs8= -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -26,7 +27,6 @@ github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo github.com/gdamore/tcell v1.1.1/go.mod h1:K1udHkiR3cOtlpKG5tZPD5XxrF7v2y7lDq7Whcj+xkQ= github.com/gdamore/tcell v1.4.0 h1:vUnHwJRvcPQa3tzi+0QI4U9JINXYJlOz9yiaiPQ2wMU= github.com/gdamore/tcell v1.4.0/go.mod h1:vxEiSDZdW3L+Uhjii9c3375IlDmR05bzxY404ZVSMo0= -github.com/gdamore/tcell/v2 v2.0.1-0.20201017141208-acf90d56d591 h1:0WWUDZ1oxq7NxVyGo8M3KI5jbkiwNAdZFFzAdC68up4= github.com/gdamore/tcell/v2 v2.0.1-0.20201017141208-acf90d56d591/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA= github.com/gdamore/tcell/v2 v2.1.0 h1:UnSmozHgBkQi2PGsFr+rpdXuAPRRucMegpQp3Z3kDro= github.com/gdamore/tcell/v2 v2.1.0/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA= @@ -42,16 +42,12 @@ github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/gopherjs/gopherjs v0.0.0-20180628210949-0892b62f0d9f/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherjs v0.0.0-20180825215210-0210a2f0f73c/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherwasm v0.1.1/go.mod h1:kx4n9a+MzHH0BJJhvlsQ65hqLFXDO/m256AsaDPQ+/4= -github.com/gopherjs/gopherwasm v1.0.0 h1:32nge/RlujS1Im4HNCJPp0NbBOAeBXFuT1KonUuLl+Y= github.com/gopherjs/gopherwasm v1.0.0/go.mod h1:SkZ8z7CWBz5VXbhJel8TxCmAcsQqzgWGR/8nMhyhZSI= -github.com/hajimehoshi/go-mp3 v0.1.1 h1:Y33fAdTma70fkrxnc9u50Uq0lV6eZ+bkAlssdMmCwUc= github.com/hajimehoshi/go-mp3 v0.1.1/go.mod h1:4i+c5pDNKDrxl1iu9iG90/+fhP37lio6gNhjCx9WBJw= github.com/hajimehoshi/go-mp3 v0.3.1 h1:pn/SKU1+/rfK8KaZXdGEC2G/KCB2aLRjbTCrwKcokao= github.com/hajimehoshi/go-mp3 v0.3.1/go.mod h1:qMJj/CSDxx6CGHiZeCgbiq2DSUkbK0UbtXShQcnfyMM= github.com/hajimehoshi/oto v0.1.1/go.mod h1:hUiLWeBQnbDu4pZsAhOnGqMI1ZGibS6e2qhQdfpwz04= -github.com/hajimehoshi/oto v0.3.1 h1:cpf/uIv4Q0oc5uf9loQn7PIehv+mZerh+0KKma6gzMk= github.com/hajimehoshi/oto v0.3.1/go.mod h1:e9eTLBB9iZto045HLbzfHJIc+jP3xaKrjZTghvb6fdM= -github.com/hajimehoshi/oto v0.6.1 h1:7cJz/zRQV4aJvMSSRqzN2TImoVVMpE0BCY4nrNJaDOM= github.com/hajimehoshi/oto v0.6.1/go.mod h1:0QXGEkbuJRohbJaxr7ZQSxnju7hEhseiPx2hrh6raOI= github.com/hajimehoshi/oto v0.7.1 h1:I7maFPz5MBCwiutOrz++DLdbr4rTzBsbBuV2VpgU9kk= github.com/hajimehoshi/oto v0.7.1/go.mod h1:wovJ8WWMfFKvP587mhHgot/MBr4DnNy9m6EepeVGnos= @@ -61,7 +57,6 @@ github.com/kennygrant/sanitize v1.2.4 h1:gN25/otpP5vAsO2djbMhF/LQX6R7+O1TB4yv8Nz github.com/kennygrant/sanitize v1.2.4/go.mod h1:LGsjYYtgxbetdg5owWB2mpgUL6e2nfw2eObZ0u0qvak= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= -github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e h1:9MlwzLdW7QSDrhDjFlsEYmxpFyIoXmYRon3dt0io31k= github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8= github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= @@ -70,8 +65,8 @@ github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tW github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/magefile/mage v1.10.0 h1:3HiXzCUY12kh9bIuyXShaVe529fJfyqoVM42o/uom2g= github.com/magefile/mage v1.10.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= -github.com/martinlindhe/subtitles v0.0.0-20210219114018-c133f18cfb3d h1:7pTPyGn1BlepA/DoNsDKuhDovj5cGdIiQpRjHwPHNlk= -github.com/martinlindhe/subtitles v0.0.0-20210219114018-c133f18cfb3d/go.mod h1:EjV1EvmBWHZGVRjE+IolE0t6LnkbhyRiwD7SlXDQsuw= +github.com/martinlindhe/subtitles v0.0.0-20210226093915-8010a8a9b389 h1:J+b8EmZxqdHNq00SW/19neJHazgzlRrDrBLkGpOQqSo= +github.com/martinlindhe/subtitles v0.0.0-20210226093915-8010a8a9b389/go.mod h1:EjV1EvmBWHZGVRjE+IolE0t6LnkbhyRiwD7SlXDQsuw= github.com/mattn/anko v0.1.8 h1:wDGM0Rwgbzhk1h8xE6qAR4n+PO/9clzf3tLGtrwsqJg= github.com/mattn/anko v0.1.8/go.mod h1:C5D2zw4NIv/sB2SrQ3qs5wqPw0wKiA2GZqexy4ctNH0= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= @@ -79,7 +74,6 @@ github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg= github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/mewkiz/flac v1.0.5/go.mod h1:EHZNU32dMF6alpurYyKHDLYpW1lYpBZ5WrXi/VuNIGs= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -87,7 +81,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rivo/tview v0.0.0-20210125085121-dbc1f32bb1d0 h1:WCfp+Jq9Mx156zIf9X6Frd6F19rf7wIRlm54UPxUfcU= github.com/rivo/tview v0.0.0-20210125085121-dbc1f32bb1d0/go.mod h1:1QW7hX7RQzOqyGgx8O64bRPQBrFtPflioPPX5gFPV3A= -github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= @@ -120,7 +113,6 @@ golang.org/x/exp v0.0.0-20201229011636-eab1b5eb1a03 h1:XlAInxBYX5nBofPaY51uv/x9x golang.org/x/exp v0.0.0-20201229011636-eab1b5eb1a03/go.mod h1:I6l2HNBLBZEcrOoCpyKLdY2lHoRZ8lI4x60KMCQDft4= golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= -golang.org/x/image v0.0.0-20190802002840-cff245a6509b h1:+qEpEAPhDZ1o0x3tHzZTQDArnOixOzGD9HUJfcg0mb4= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.0.0-20201208152932-35266b937fa6 h1:nfeHNc1nAqecKCy2FCy4HY+soOOe5sDLJ/gZLbx6GYI= golang.org/x/image v0.0.0-20201208152932-35266b937fa6/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= @@ -166,7 +158,6 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200117012304-6edc0a871e69/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa h1:5E4dL8+NgFOgjwbTKz+OOEGGhP+ectTmF842l6KjupQ= golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/lyric/lrc.go b/lyric/lrc.go new file mode 100644 index 0000000..fa2dc79 --- /dev/null +++ b/lyric/lrc.go @@ -0,0 +1,161 @@ +//Package lyric package download lyrics from different website and embed them into mp3 file. +//lrc file is used to parse lrc file into subtitle. Similar to subtitles package +package lyric + +import ( + "fmt" + "regexp" + "runtime" + "strconv" + "strings" + "time" + + "github.com/martinlindhe/subtitles" +) + +// Eol is the end of line characters to use when writing .srt data +var eol = "\n" + +func init() { + if runtime.GOOS == "windows" { + eol = "\r\n" + } +} + +func looksLikeLRC(s string) bool { + return s[0] == '[' +} + +// NewFromLRC parses a .lrc text into Subtitle, assumes s is a clean utf8 string +func NewFromLRC(s string) (res *subtitles.Subtitle, err error) { + r1 := regexp.MustCompile(`^\[[0-9].*\]`) + lines := strings.Split(s, "\n") + outSeq := 1 + + for i := 0; i < len(lines); i++ { + seq := strings.Trim(lines[i], "\r ") + // fmt.Println(seq) + if seq == "" { + continue + } + + var matchEnd []string + matchStart := r1.FindStringSubmatch(lines[i]) + if i+1 < len(lines) { + matchEnd = r1.FindStringSubmatch(lines[i+1]) + } else { + matchEnd = matchStart + } + + if len(matchStart) < 1 || len(matchEnd) < 1 { + // err = fmt.Errorf("lrc: parse error at line %d (idx out of range) for input '%s'", i, lines[i]) + // break + continue + } + + var o subtitles.Caption + o.Seq = outSeq + + o.Start, err = parseLrcTime(matchStart[0]) + if err != nil { + err = fmt.Errorf("lrc: start error at line %d: %v", i, err) + break + } + + o.End, err = parseLrcTime(matchEnd[0]) + if err != nil { + err = fmt.Errorf("lrc: end error at line %d: %v", i, err) + break + } + + res.Captions = append(res.Captions, o) + outSeq++ + // i++ + // if i >= len(lines) { + // break + // } + + // textLine := 1 + // for { + // line := strings.Trim(lines[i], "\r ") + // if line == "" && textLine > 1 { + // break + // } + // if line != "" { + // o.Text = append(o.Text, line) + // } + + // i++ + // if i >= len(lines) { + // break + // } + + // textLine++ + // } + + // if len(o.Text) > 0 { + // fmt.Println(o.Text) + // fmt.Println(outSeq) + // res.Captions = append(res.Captions, o) + // outSeq++ + // } + + } + return +} + +// AsSRT renders the sub in .srt format +// func (subtitle *Subtitle) AsLRC() (res string) { +// for _, sub := range subtitle.Captions { +// // res += sub.AsLRC() +// } +// return +// } + +// // TimeSRT renders a timestamp for use in .srt +// func TimeLRC(t time.Time) string { +// res := t.Format("15:04:05.000") +// return strings.Replace(res, ".", ",", 1) +// } + +// parseSrtTime parses a srt subtitle time (duration since start of film) +func parseLrcTime(in string) (time.Time, error) { + in = strings.TrimPrefix(in, "[") + in = strings.TrimSuffix(in, "]") + // . and , to : + in = strings.Replace(in, ",", ":", -1) + in = strings.Replace(in, ".", ":", -1) + + if strings.Count(in, ":") == 2 { + in += ":000" + } + + r1 := regexp.MustCompile("([0-9]+):([0-9]+):([0-9]+):([0-9]+)") + matches := r1.FindStringSubmatch(in) + if len(matches) < 5 { + return time.Now(), fmt.Errorf("[lrc] Regexp didnt match: %s", in) + } + h, err := strconv.Atoi(matches[1]) + if err != nil { + return time.Now(), err + } + m, err := strconv.Atoi(matches[2]) + if err != nil { + return time.Now(), err + } + s, err := strconv.Atoi(matches[3]) + if err != nil { + return time.Now(), err + } + ms, err := strconv.Atoi(matches[4]) + if err != nil { + return time.Now(), err + } + + return makeTime(h, m, s, ms), nil +} + +// makeTime is a helper to create a time duration +func makeTime(h int, m int, s int, ms int) time.Time { + return time.Date(0, 1, 1, h, m, s, ms*1000*1000, time.UTC) +} diff --git a/lyric/lyric_chinese.go b/lyric/lyric_chinese.go new file mode 100644 index 0000000..4f3ab03 --- /dev/null +++ b/lyric/lyric_chinese.go @@ -0,0 +1,82 @@ +package lyric + +import ( + // "encoding/json" + "fmt" + // "net/url" + "strconv" + + "github.com/asmcos/requests" + "github.com/martinlindhe/subtitles" + // "github.com/gocolly/colly" + // r "github.com/solos/requests" +) + +// GetLyricOptionsChinese queries available song lyrics. It returns map of title and +// id of the lyric. +func GetLyricOptionsChinese(search string) (map[string]string, error) { + + result := make(map[string]string) + p := requests.Params{ + "site": "netease", + "search": search, + } + req := requests.Requests() + req.Header.Set("Content-Type", "application/json") + resp, err := req.Get("http://api.sunyj.xyz", p) + if err != nil { + return nil, err + } + + var dataMap []map[string]interface{} + err = resp.Json(&dataMap) + if err != nil { + return nil, err + } + for k, v := range dataMap { + lyricIDfloat64 := dataMap[k]["lyric_id"] + songName := v["name"] + songArtist := v["artist"] + lyricID := strconv.FormatFloat(lyricIDfloat64.(float64), 'f', -1, 64) + songTitle := fmt.Sprintf("%s - %s ", songArtist, songName) + if lyricID == "" { + continue + } + result[songTitle] = lyricID + } + + return result, nil +} + +// GetLyricChinese should receive url that was returned from GetLyricOptions. GetLyric +// returns lyric of the queried song. +func GetLyricChinese(lyricID string) (string, error) { + + var lyric string + p := requests.Params{ + "site": "netease", + "lyric": lyricID, + } + req := requests.Requests() + resp, err := req.Get("http://api.sunyj.xyz", p) + if err != nil { + return "", err + } + var dataMap map[string]interface{} + err = resp.Json(&dataMap) + if err != nil { + return "", err + } + lyric = dataMap["lyric"].(string) + if looksLikeLRC(lyric) { + // err = fmt.Errorf("is a lrc file and need to convert to srt") + // return "", err + var tmpSubtitle *subtitles.Subtitle + tmpSubtitle, err = NewFromLRC(lyric) + if err != nil { + return "", err + } + lyric = tmpSubtitle.AsSRT() + } + return lyric, nil +} diff --git a/playingbar.go b/playingbar.go index ec4704e..75c7e6c 100644 --- a/playingbar.go +++ b/playingbar.go @@ -86,6 +86,7 @@ func (p *PlayingBar) run() error { _, _, width, _ := p.GetInnerRect() progressBar := progresStr(p.progress, p.full, width/2, "█", "━") // our progress bar + p.subtitle = nil if p.hasTag && p.subtitles != nil { for i := range p.subtitles { // First we check if the lyric language prefered is presented @@ -180,6 +181,7 @@ func (p *PlayingBar) newProgress(currentSong *AudioFile, full int) { if !ok { die(errors.New("USLT error!")) } + // res, err := subtitles.Parse([]byte(uslf.Lyrics)) res, err := subtitles.NewFromSRT(uslf.Lyrics) if err != nil { logError(err) diff --git a/playlist.go b/playlist.go index 53c530b..c88467d 100644 --- a/playlist.go +++ b/playlist.go @@ -65,7 +65,7 @@ func (p *Playlist) help() []string { "/ find in playlist", "s search audio from youtube", "t edit mp3 tags", - "1 find lyric if available", + "1/2 find lyric if available", } } @@ -174,6 +174,7 @@ func newPlaylist(args Args) *Playlist { '/': "playlist_search", 't': "edit_tags", '1': "fetch_lyric", + '2': "fetch_lyric_cn", } for key, cmd := range cmds { diff --git a/popup.go b/popup.go index 3cefea5..ab6d5eb 100644 --- a/popup.go +++ b/popup.go @@ -892,14 +892,60 @@ func lyricPopup(audioFile *AudioFile) error { lyric, err := lyric.GetLyric(url) if err != nil { errorPopup(err) + gomu.app.Draw() } langExt := "en" err = embedLyric(audioFile.path, lyric, langExt) if err != nil { errorPopup(err) + gomu.app.Draw() } else { infoPopup("Lyric added successfully") + gomu.app.Draw() + } + + }() + }) + + return nil +} + +func lyricPopupCN(audioFile *AudioFile) error { + + results, err := lyric.GetLyricOptionsChinese(audioFile.name) + if err != nil { + return tracerr.Wrap(err) + } + + titles := make([]string, 0, len(results)) + + for result := range results { + titles = append(titles, result) + } + + searchPopup(" Lyrics ", titles, func(selected string) { + if selected == "" { + return + } + + go func() { + lyricID := results[selected] + lyric, err := lyric.GetLyricChinese(lyricID) + if err != nil { + errorPopup(err) + gomu.app.Draw() + return + } + + langExt := "zh-CN" + err = embedLyric(audioFile.path, lyric, langExt) + if err != nil { + errorPopup(err) + gomu.app.Draw() + } else { + infoPopup("Lyric added successfully") + gomu.app.Draw() } }()