11package processor
22
33import (
4+ "fmt"
45 "github.com/pkg/errors"
56 "lrcAPI/util"
6- "strconv "
7+ "sort "
78)
89
910func (data * Processor ) Process () error {
10- var titles , artists , oriLrc , trLrc []string
11- if err := netease (data , & titles , & artists , & oriLrc , & trLrc ); err != nil {
11+ if err := netease (data ); err != nil {
1212 return errors .Wrap (err , "neteaseAPI" )
1313 }
14- if err := qq (data , & titles , & artists , & oriLrc , & trLrc ); err != nil {
14+ if err := qq (data ); err != nil {
1515 return errors .Wrap (err , "qqAPI" )
1616 }
17- for index , _ := range titles {
18- infoLyric := InfoLyric {
19- ID : strconv . Itoa ( index ),
20- Title : titles [ index ],
21- Artist : artists [ index ] ,
22- Lyric : util . LrcTranslationBlender ( oriLrc [ index ], trLrc [ index ]) ,
23- }
24- data . InfoLyric = append ( data .InfoLyric , infoLyric )
25- }
17+ sort . Slice ( data . InfoLyric , func ( i , j int ) bool {
18+ return data . InfoLyric [ i ]. Index < data . InfoLyric [ j ]. Index
19+ })
20+ data . InfoLyric = append ( data . InfoLyric , InfoLyric {
21+ Index : - 1 ,
22+ Title : data . Title ,
23+ Artist : data . Artist ,
24+ Lyric : fmt . Sprintf ( "[00:00.00]%s \n [00:00.00]%s" , data .Title , data . Artist ),
25+ })
2626 return nil
2727}
2828
29- func netease (data * Processor , Titles , Artists , OriLrc , TrLrc * [] string ) error {
29+ func netease (data * Processor ) error {
3030 musicIDs , titles , artists , err := util .NeteaseGetMusic (data .Title , data .Artist )
3131 if err != nil {
3232 return errors .WithStack (err )
@@ -39,15 +39,17 @@ func netease(data *Processor, Titles, Artists, OriLrc, TrLrc *[]string) error {
3939 if err != nil {
4040 return errors .WithStack (err )
4141 }
42- * Titles = append (* Titles , (* titles )[index ])
43- * Artists = append (* Artists , (* artists )[index ])
44- * OriLrc = append (* OriLrc , oriLrc )
45- * TrLrc = append (* TrLrc , trLrc )
42+ data .InfoLyric = append (data .InfoLyric , InfoLyric {
43+ Index : API_TOT * index + NETEASE_API_COUNT ,
44+ Title : (* titles )[index ] + " (网易云音乐)" ,
45+ Artist : (* artists )[index ],
46+ Lyric : util .LrcTranslationBlender (oriLrc , trLrc ),
47+ })
4648 }
4749 return nil
4850}
4951
50- func qq (data * Processor , Titles , Artists , OriLrc , TrLrc * [] string ) error {
52+ func qq (data * Processor ) error {
5153 musicIDs , musicMIDs , titles , artists , err := util .QQGetMusic (data .Title )
5254 if err != nil {
5355 return errors .WithStack (err )
@@ -60,10 +62,12 @@ func qq(data *Processor, Titles, Artists, OriLrc, TrLrc *[]string) error {
6062 if err != nil {
6163 return errors .WithStack (err )
6264 }
63- * Titles = append (* Titles , (* titles )[index ])
64- * Artists = append (* Artists , (* artists )[index ])
65- * OriLrc = append (* OriLrc , oriLrc )
66- * TrLrc = append (* TrLrc , trLrc )
65+ data .InfoLyric = append (data .InfoLyric , InfoLyric {
66+ Index : API_TOT * index + QQ_API_COUNT ,
67+ Title : (* titles )[index ] + " (QQ音乐)" ,
68+ Artist : (* artists )[index ],
69+ Lyric : util .LrcTranslationBlender (oriLrc , trLrc ),
70+ })
6771 }
6872 return nil
6973}
0 commit comments