mirror of
https://github.com/AynaLivePlayer/miaosic.git
synced 2025-12-06 13:02:48 +08:00
make lyric lang using iso 639-3 string
This commit is contained in:
@@ -24,9 +24,10 @@ miaosic [全局参数] <命令> [命令参数] [命令标志]
|
||||
|
||||
### 全局参数
|
||||
|
||||
| 参数 | 缩写 | 描述 |
|
||||
|------|------|------|
|
||||
| 参数 | 缩写 | 描述 |
|
||||
|------------------|------|--------------------|
|
||||
| `--session-file` | `-s` | 指定会话文件路径(用于保存登录状态) |
|
||||
| `--json` | `-j` | 使用json输出 |
|
||||
|
||||
### 命令列表
|
||||
|
||||
|
||||
@@ -20,29 +20,6 @@ func init() {
|
||||
CmdLyric.Flags().BoolVar(&saveLyric, "save", false, "Save lyrics to file with auto-generated name")
|
||||
}
|
||||
|
||||
func sanitizeFilename(name string) string {
|
||||
// 定义非法字符集合
|
||||
invalidChars := `/\:*?"<>|`
|
||||
|
||||
// 替换非法字符为下划线
|
||||
sanitized := strings.Map(func(r rune) rune {
|
||||
if strings.ContainsRune(invalidChars, r) {
|
||||
return '_'
|
||||
}
|
||||
return r
|
||||
}, name)
|
||||
|
||||
// 移除首尾空格
|
||||
sanitized = strings.TrimSpace(sanitized)
|
||||
|
||||
// 如果名称为空,返回默认值
|
||||
if sanitized == "" {
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
return sanitized
|
||||
}
|
||||
|
||||
var CmdLyric = &cobra.Command{
|
||||
Use: "lyric <provider> <uri>",
|
||||
Short: "Get media lyrics",
|
||||
|
||||
26
cmd/miaosic/cmds/utils.go
Normal file
26
cmd/miaosic/cmds/utils.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package cmds
|
||||
|
||||
import "strings"
|
||||
|
||||
func sanitizeFilename(name string) string {
|
||||
// 定义非法字符集合
|
||||
invalidChars := `/\:*?"<>|`
|
||||
|
||||
// 替换非法字符为下划线
|
||||
sanitized := strings.Map(func(r rune) rune {
|
||||
if strings.ContainsRune(invalidChars, r) {
|
||||
return '_'
|
||||
}
|
||||
return r
|
||||
}, name)
|
||||
|
||||
// 移除首尾空格
|
||||
sanitized = strings.TrimSpace(sanitized)
|
||||
|
||||
// 如果名称为空,返回默认值
|
||||
if sanitized == "" {
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
return sanitized
|
||||
}
|
||||
30
go.mod
30
go.mod
@@ -8,28 +8,37 @@ toolchain go1.24.4
|
||||
// github.com/aynakeya/deepcolor => ../../../deepcolor
|
||||
//)
|
||||
|
||||
//replace github.com/go-flac/go-flac/v2 => ../../../go-flac/v2
|
||||
|
||||
//replace (
|
||||
// github.com/XiaoMengXinX/Music163Api-Go => ../../../AyAudioBot/Music163Api-Go
|
||||
//)
|
||||
|
||||
require (
|
||||
github.com/XiaoMengXinX/Music163Api-Go v0.1.30
|
||||
github.com/abadojack/whatlanggo v1.0.1
|
||||
github.com/aynakeya/deepcolor v1.0.3
|
||||
github.com/bogem/id3v2/v2 v2.1.4
|
||||
github.com/dhowden/tag v0.0.0-20240417053706-3d75831295e8
|
||||
github.com/gabriel-vasile/mimetype v1.4.9
|
||||
github.com/go-flac/flacpicture/v2 v2.0.2
|
||||
github.com/go-flac/flacvorbis/v2 v2.0.2
|
||||
github.com/go-flac/go-flac/v2 v2.0.3
|
||||
github.com/go-resty/resty/v2 v2.16.5
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/jinzhu/copier v0.4.0
|
||||
github.com/k0kubun/pp/v3 v3.4.1
|
||||
github.com/k0kubun/pp/v3 v3.5.0
|
||||
github.com/makiuchi-d/gozxing v0.1.1
|
||||
github.com/sahilm/fuzzy v0.1.1
|
||||
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d
|
||||
github.com/schollz/progressbar/v3 v3.18.0
|
||||
github.com/spf13/cast v1.9.2
|
||||
github.com/spf13/cobra v1.9.1
|
||||
github.com/stretchr/testify v1.10.0
|
||||
github.com/tidwall/gjson v1.18.0
|
||||
github.com/yeqown/go-qrcode/v2 v2.2.5
|
||||
github.com/yeqown/go-qrcode/writer/file v1.0.0
|
||||
golang.org/x/text v0.26.0
|
||||
golang.org/x/text v0.27.0
|
||||
)
|
||||
|
||||
require (
|
||||
@@ -38,15 +47,18 @@ require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/kylelemons/godebug v1.1.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.16 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/spf13/pflag v1.0.6 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/spf13/pflag v1.0.7 // indirect
|
||||
github.com/tidwall/match v1.1.1 // indirect
|
||||
github.com/tidwall/pretty v1.2.1 // indirect
|
||||
github.com/yeqown/reedsolomon v1.0.0 // indirect
|
||||
golang.org/x/net v0.41.0 // indirect
|
||||
golang.org/x/sys v0.33.0 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||
golang.org/x/net v0.42.0 // indirect
|
||||
golang.org/x/sys v0.34.0 // indirect
|
||||
golang.org/x/term v0.33.0 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
1
lyric.go
1
lyric.go
@@ -21,6 +21,7 @@ func (lr LyricLine) String() string {
|
||||
}
|
||||
|
||||
type Lyrics struct {
|
||||
// Lang will is ISO 639-3 string
|
||||
Lang string `json:"lang"`
|
||||
Content []LyricLine `json:"content"`
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/AynaLivePlayer/miaosic"
|
||||
"github.com/AynaLivePlayer/miaosic/providers"
|
||||
"github.com/AynaLivePlayer/miaosic/utils"
|
||||
"github.com/aynakeya/deepcolor"
|
||||
"github.com/aynakeya/deepcolor/dphttp"
|
||||
"github.com/tidwall/gjson"
|
||||
@@ -302,5 +303,5 @@ func (k *Kugou) GetMediaLyric(meta miaosic.MetaData) ([]miaosic.Lyrics, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []miaosic.Lyrics{miaosic.ParseLyrics("default", string(lyricdata))}, nil
|
||||
return []miaosic.Lyrics{utils.ParseLyricWithLangDetection(string(lyricdata))}, nil
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/AynaLivePlayer/miaosic"
|
||||
"github.com/AynaLivePlayer/miaosic/providers"
|
||||
"github.com/AynaLivePlayer/miaosic/utils"
|
||||
"github.com/aynakeya/deepcolor"
|
||||
"github.com/aynakeya/deepcolor/dphttp"
|
||||
"github.com/spf13/cast"
|
||||
@@ -122,7 +123,7 @@ func NewKuwo() *Kuwo {
|
||||
if len(lrcs) == 0 {
|
||||
return miaosic.ErrorExternalApi
|
||||
}
|
||||
*lyrics = []miaosic.Lyrics{miaosic.ParseLyrics("default", strings.Join(lrcs, "\n"))}
|
||||
*lyrics = []miaosic.Lyrics{utils.ParseLyricWithLangDetection(strings.Join(lrcs, "\n"))}
|
||||
return nil
|
||||
})
|
||||
kw.SearchApi = deepcolor.CreateApiResultFunc(
|
||||
|
||||
@@ -3,6 +3,7 @@ package netease
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/AynaLivePlayer/miaosic"
|
||||
"github.com/AynaLivePlayer/miaosic/utils"
|
||||
neteaseApi "github.com/XiaoMengXinX/Music163Api-Go/api"
|
||||
neteaseTypes "github.com/XiaoMengXinX/Music163Api-Go/types"
|
||||
neteaseUtil "github.com/XiaoMengXinX/Music163Api-Go/utils"
|
||||
@@ -187,10 +188,10 @@ func (n *Netease) GetMediaLyric(meta miaosic.MetaData) ([]miaosic.Lyrics, error)
|
||||
}
|
||||
lrcs := make([]miaosic.Lyrics, 0)
|
||||
if result.Lrc.Lyric != "" {
|
||||
lrcs = append(lrcs, miaosic.ParseLyrics("default", result.Lrc.Lyric))
|
||||
lrcs = append(lrcs, utils.ParseLyricWithLangDetection(result.Lrc.Lyric))
|
||||
}
|
||||
if result.Tlyric.Lyric != "" {
|
||||
lrcs = append(lrcs, miaosic.ParseLyrics("translation", result.Tlyric.Lyric))
|
||||
lrcs = append(lrcs, utils.ParseLyricWithLangDetection(result.Tlyric.Lyric))
|
||||
}
|
||||
if result.Klyric.Lyric != "" {
|
||||
lrcs = append(lrcs, miaosic.ParseLyrics("karaoke", result.Klyric.Lyric))
|
||||
|
||||
@@ -3,6 +3,7 @@ package qq
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/AynaLivePlayer/miaosic"
|
||||
"github.com/AynaLivePlayer/miaosic/utils"
|
||||
"github.com/tidwall/gjson"
|
||||
"regexp"
|
||||
"slices"
|
||||
@@ -237,7 +238,7 @@ func (p *QQMusicProvider) GetMediaLyric(meta miaosic.MetaData) ([]miaosic.Lyrics
|
||||
if lyricEnc := resp.Get("data.lyric").String(); lyricEnc != "" {
|
||||
lyric, err := qrcDecrypt(lyricEnc)
|
||||
if err == nil {
|
||||
result = append(result, miaosic.ParseLyrics("default", lyric))
|
||||
result = append(result, utils.ParseLyricWithLangDetection(lyric))
|
||||
} else {
|
||||
fmt.Println(err)
|
||||
}
|
||||
@@ -245,13 +246,13 @@ func (p *QQMusicProvider) GetMediaLyric(meta miaosic.MetaData) ([]miaosic.Lyrics
|
||||
if lyricEnc := resp.Get("data.trans").String(); lyricEnc != "" {
|
||||
lyric, err := qrcDecrypt(lyricEnc)
|
||||
if err == nil {
|
||||
result = append(result, miaosic.ParseLyrics("translation", lyric))
|
||||
result = append(result, utils.ParseLyricWithLangDetection(lyric))
|
||||
}
|
||||
}
|
||||
if lyricEnc := resp.Get("data.roma").String(); lyricEnc != "" {
|
||||
lyric, err := qrcDecrypt(lyricEnc)
|
||||
if err == nil {
|
||||
result = append(result, miaosic.ParseLyrics("roma", lyric))
|
||||
result = append(result, utils.ParseLyricWithLangDetection(lyric))
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
|
||||
1
tag/tag.go
Normal file
1
tag/tag.go
Normal file
@@ -0,0 +1 @@
|
||||
package tag
|
||||
22
utils/lang.go
Normal file
22
utils/lang.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/AynaLivePlayer/miaosic"
|
||||
"github.com/abadojack/whatlanggo"
|
||||
)
|
||||
|
||||
func DetectSetLyricLang(lyric *miaosic.Lyrics) string {
|
||||
lyrics := ""
|
||||
for _, lrcLine := range lyric.Content {
|
||||
lyrics += " " + lrcLine.Lyric
|
||||
}
|
||||
lang := whatlanggo.DetectLang(lyrics)
|
||||
lyric.Lang = lang.Iso6393()
|
||||
return lyrics
|
||||
}
|
||||
|
||||
func ParseLyricWithLangDetection(lyrics string) miaosic.Lyrics {
|
||||
lyric := miaosic.ParseLyrics("default", lyrics)
|
||||
DetectSetLyricLang(&lyric)
|
||||
return lyric
|
||||
}
|
||||
Reference in New Issue
Block a user