feat(base): 优化艺人关键字逻辑

This commit is contained in:
WROIATE 2021-11-04 20:27:32 +08:00
parent 65179e6f42
commit 2c3b5eca32
5 changed files with 16 additions and 7 deletions

View File

@ -39,6 +39,7 @@ type SearchSong struct {
Quality MusicQuality
OrderBy SearchOrderBy
Limit int
ArtistList []string
}
type PlatformIdTag string

View File

@ -28,7 +28,7 @@ var lock sync.Mutex
func (m *KuGou) SearchSong(song common.SearchSong) (songs []*common.Song) {
song = base.PreSearchSong(song)
cookies := getCookies()
keyWordList := utils.Combination(strings.Split(song.ArtistsName, " "))
keyWordList := utils.Combination(song.ArtistList)
wg := sync.WaitGroup{}
for _, v := range keyWordList {
wg.Add(1)

View File

@ -32,7 +32,7 @@ var lock sync.Mutex
func (m *KuWo) SearchSong(song common.SearchSong) (songs []*common.Song) {
song = base.PreSearchSong(song)
keyWordList := utils.Combination(strings.Split(song.ArtistsName, " "))
keyWordList := utils.Combination(song.ArtistList)
wg := sync.WaitGroup{}
for _, v := range keyWordList {
wg.Add(1)

View File

@ -159,6 +159,7 @@ func Find(music common.SearchMusic) common.Song {
// searchSong["name"] = utils.ReplaceAll(searchSong["name"].(string), `(\s*cover[:\s][^\)]+)`, "")
//}
searchSong["artistsName"] = strings.Join(artists, " ")
searchSong["artistList"] = artists
searchSong["keyword"] = searchSong["name"].(string) + " " + searchSong["artistsName"].(string)
log.Println("search song:" + searchSong["keyword"].(string))
songT = *parseSongFn(searchSong, music)
@ -183,6 +184,7 @@ func parseSongFn(key common.MapType, music common.SearchMusic) *common.Song {
if songId, ok := key["songId"]; ok {
id = songId.(string)
}
searchArtistList := key["artistList"].([]string)
key["musicQuality"] = music.Quality
var ch = make(chan *common.Song)
now := time.Now()
@ -190,6 +192,7 @@ func parseSongFn(key common.MapType, music common.SearchMusic) *common.Song {
Keyword: searchKeyword, Name: searchSongName,
ArtistsName: searchArtistsName, Quality: music.Quality,
OrderBy: common.MatchedScoreDesc, Limit: 1,
ArtistList: searchArtistList,
}
songs := getSongFromAllSource(searchSong, ch)
log.Println("consumed:", time.Since(now))

View File

@ -331,17 +331,22 @@ func ParseCookies(file string) []*http.Cookie {
return cl
}
func Combination(keyWords []string) (result []string) {
if len(keyWords) == 1 {
func Combination(WordList []string) (result []string) {
if WordList == nil || len(WordList) == 0 {
return []string{
"",
keyWords[0],
}
}
tmp := Combination(keyWords[1:])
if len(WordList) == 1 {
return []string{
"",
WordList[0],
}
}
tmp := Combination(WordList[1:])
result = append(result, tmp...)
for _, v := range tmp {
result = append(result, keyWords[0]+" "+v)
result = append(result, WordList[0]+" "+v)
}
return result
}