Skip to content

Commit d8a24e8

Browse files
committed
fix kuwo;
optimized the rules;
1 parent 6a516f8 commit d8a24e8

File tree

11 files changed

+159
-290
lines changed

11 files changed

+159
-290
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ sudo ./UnblockNeteaseMusic
6565
4. 开启多个源会自动选择最优匹配歌曲,并发的支持使得同时多个源获取并不会增加多少耗时,如果发现一直获取很慢,使用排除法来检查是否某一个源无法使用
6666
6. 0.2.3版本后默认音质将根据客户端选择的音质,启动参数加上`-b`可以设置强制音质优先
6767
7. 0.2.5版本后支持直接在搜索页面显示其他平台搜索结果,如遇错误,请关闭该功能(参数为 `-sl 0`)
68+
6869
### IOS信任证书步骤
6970

7071
1. 安装证书--设置-描述文件-安装
@@ -79,6 +80,7 @@ sudo ./UnblockNeteaseMusic
7980
5. 咪咕源貌似部分宽带无法使用
8081
6. 最新版app采用第三方登录会失败,失败的同学选择手机号登录吧
8182
7. Android7.0后默认不信任用户证书,解决办法自行谷歌
83+
8. 咪咕已无法使用,需要登录,没空写了。且用且珍惜。
8284

8385
# 感谢
8486

app.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
)
2020

2121
func main() {
22-
2322
//log.Println("--------------------Version--------------------")
2423
//fmt.Println(version.AppVersion())
2524
defer func() {
@@ -60,7 +59,7 @@ func main() {
6059
restoreHosts()
6160
exit <- true
6261
}()
63-
signal.Notify(signalChan, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGSEGV)
62+
signal.Notify(signalChan, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGSEGV, syscall.SIGKILL)
6463
proxy.InitProxy()
6564
provider.Init()
6665
<-exit

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CurrentVersion=0.2.9
1+
CurrentVersion=0.2.10
22
Project=github.com/cnsilvan/UnblockNeteaseMusic
33
Path="$Project/version"
44
ExecName="UnblockNeteaseMusic"

network/network.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package network
33
import (
44
"bytes"
55
"crypto/tls"
6+
"github.com/cnsilvan/UnblockNeteaseMusic/common"
67
"io"
78
"io/ioutil"
89
"log"
@@ -11,12 +12,12 @@ import (
1112
"strings"
1213
"time"
1314

14-
"github.com/cnsilvan/UnblockNeteaseMusic/common"
1515
"github.com/cnsilvan/UnblockNeteaseMusic/utils"
1616
)
1717

1818
var (
19-
httpClient *http.Client
19+
httpClient *http.Client
20+
directClient *http.Client
2021
)
2122

2223
func init() {
@@ -34,9 +35,14 @@ func init() {
3435
ResponseHeaderTimeout: 5 * time.Second,
3536
MaxConnsPerHost: 100,
3637
}
38+
directClient = &http.Client{
39+
Transport: tr.Clone(),
40+
}
41+
tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
3742
httpClient = &http.Client{
3843
Transport: tr,
3944
}
45+
4046
}
4147

4248
type ClientRequest struct {
@@ -84,18 +90,6 @@ func Request(clientRequest *ClientRequest) (*http.Response, error) {
8490
request.URL.Scheme = "http"
8591
}
8692
}
87-
tr := httpClient.Transport.(*http.Transport)
88-
tr.TLSClientConfig = nil
89-
// if request.URL.Scheme == "https" || request.TLS != nil {
90-
// fix redirect to https://music.163.com
91-
if _, ok := common.HostDomain[request.Host]; ok {
92-
tr.TLSClientConfig = &tls.Config{}
93-
// verify music.163.com certificate
94-
tr.TLSClientConfig.ServerName = request.Host //it doesn't contain any IP SANs
95-
// redirect to music.163.com will need verify self
96-
tr.TLSClientConfig.InsecureSkipVerify = true
97-
}
98-
// }
9993

10094
if proxy { //keep headers&cookies for Direct
10195
if header != nil {
@@ -137,7 +131,12 @@ func Request(clientRequest *ClientRequest) (*http.Response, error) {
137131
request.Header.Set("accept-encoding", acceptEncoding)
138132
request.Header.Set("accept-language", acceptLanguage)
139133
request.Header.Set("user-agent", userAgent)
140-
resp, err = httpClient.Do(request)
134+
client := directClient
135+
if _, ok := common.HostDomain[request.Host]; ok {
136+
client = httpClient
137+
}
138+
// }
139+
resp, err = client.Do(request)
141140
if err != nil {
142141
//log.Println(request.Method, request.URL.String(), host)
143142
log.Printf("http.Client.Do fail:%v\n", err)

processor/processor.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ func RequestBefore(request *http.Request) *Netease {
100100
decryptECBBytes, _ := crypto.AesDecryptECB(requestBodyH[:length], []byte(linuxApiKey))
101101
var result common.MapType
102102
result = utils.ParseJson(decryptECBBytes)
103-
//log.Println(utils.ToJson(result))
104103
urlM, ok := result["url"].(string)
105104
if ok {
106105
netease.Path = urlM
@@ -109,9 +108,6 @@ func RequestBefore(request *http.Request) *Netease {
109108
if ok {
110109
netease.Params = params
111110
}
112-
113-
//log.Println("forward")
114-
//log.Printf("path:%s \nparams:%s\n", netease.Path, netease.Params)
115111
} else if len(requestBody) > 7 {
116112
requestBodyH := make([]byte, len(requestBody))
117113
length, _ := hex.Decode(requestBodyH, requestBody[7:len(requestBody)-len(pad)])
@@ -120,9 +116,7 @@ func RequestBefore(request *http.Request) *Netease {
120116
data := strings.Split(decryptString, "-36cd479b6b5-")
121117
netease.Path = data[0]
122118
netease.Params = utils.ParseJson(bytes.NewBufferString(data[1]).Bytes())
123-
// log.Println(utils.ToJson(netease))
124-
//log.Printf("path:%s \nparams:%s\n", netease.Path, netease.Params)
125-
}
119+
}
126120
netease.Path = strings.ReplaceAll(netease.Path, "https://music.163.com", "")
127121
netease.Path = strings.ReplaceAll(netease.Path, "http://music.163.com", "")
128122
netease.Path = utils.ReplaceAll(netease.Path, `\/\d*$`, "")
@@ -154,7 +148,6 @@ func RequestAfter(request *http.Request, response *http.Response, netease *Netea
154148
pass := false
155149
if _, ok := Path[netease.Path]; ok {
156150
pass = true
157-
//log.Println(utils.ToJson(netease))
158151
}
159152
if pass && response.StatusCode == 200 {
160153

@@ -172,7 +165,6 @@ func RequestAfter(request *http.Request, response *http.Response, netease *Netea
172165
if enableGzip {
173166
decryptECBBytes, _ = utils.UnGzip(decryptECBBytes)
174167
}
175-
//log.Println(string(decryptECBBytes), netease)
176168
aeskey := eApiKey
177169
if netease.Forward {
178170
aeskey = linuxApiKey
@@ -182,16 +174,12 @@ func RequestAfter(request *http.Request, response *http.Response, netease *Netea
182174
result := utils.ParseJson(decryptECBBytes)
183175
netease.JsonBody = result
184176

185-
//if strings.Contains(netease.Path,"batch"){
186-
// log.Println(utils.ToJson(netease))
187-
//}
188177
modified := false
189178
codeN, ok := netease.JsonBody["code"].(json.Number)
190179
code := "200"
191180
if ok {
192181
code = codeN.String()
193182
}
194-
//log.Println(utils.ToJson(netease))
195183
if !netease.Web && (code == "401" || code == "512") && strings.Contains(netease.Path, "manipulate") {
196184
modified = tryCollect(netease, request)
197185
} else if !netease.Web && (code == "401" || code == "512") && strings.EqualFold(netease.Path, "/api/song/like") {

provider/base/base.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package base
2+
3+
import (
4+
"errors"
5+
"github.com/cnsilvan/UnblockNeteaseMusic/common"
6+
"github.com/cnsilvan/UnblockNeteaseMusic/network"
7+
"github.com/cnsilvan/UnblockNeteaseMusic/utils"
8+
"net/http"
9+
"sort"
10+
"strconv"
11+
"strings"
12+
)
13+
14+
func PreSearchSong(song common.SearchSong) common.SearchSong {
15+
song.Keyword = strings.ToUpper(song.Keyword)
16+
song.Name = strings.ToUpper(song.Name)
17+
song.ArtistsName = strings.ToUpper(song.ArtistsName)
18+
return song
19+
}
20+
func Fetch(url string, cookies []*http.Cookie, header http.Header, proxy bool) (result map[string]interface{}, err error) {
21+
clientRequest := network.ClientRequest{
22+
Method: http.MethodGet,
23+
RemoteUrl: url,
24+
Cookies: cookies,
25+
Header: header,
26+
Proxy: proxy,
27+
}
28+
resp, err := network.Request(&clientRequest)
29+
if err != nil {
30+
return nil, err
31+
}
32+
if resp.StatusCode != http.StatusOK {
33+
err = errors.New("StatusCode :" + strconv.Itoa(resp.StatusCode))
34+
return nil, err
35+
}
36+
defer resp.Body.Close()
37+
body, err := network.StealResponseBody(resp)
38+
if err != nil {
39+
return nil, err
40+
}
41+
result = utils.ParseJsonV2(body)
42+
return result, nil
43+
}
44+
func CalScore(song common.SearchSong, songName string, singerName string, index int, maxIndex int) (float32, bool) {
45+
if song.OrderBy == common.MatchedScoreDesc {
46+
if strings.Contains(songName, "伴奏") && !strings.Contains(song.Keyword, "伴奏") {
47+
return 0, false
48+
}
49+
var songNameSores float32 = 0.0
50+
if len(songName) > 0 {
51+
songNameSores = utils.CalMatchScoresV2(song.Name, songName, "songName")
52+
}
53+
var artistsNameSores float32 = 0.0
54+
if len(singerName) > 0 {
55+
singerName = strings.ReplaceAll(singerName, "&", "、")
56+
singerName = strings.ReplaceAll(singerName, "·", "、")
57+
artistsNameSores = utils.CalMatchScoresV2(song.ArtistsName, singerName, "singerName")
58+
}
59+
songMatchScore := songNameSores*0.55 + artistsNameSores*0.35 + 0.1*float32(maxIndex-index)/float32(maxIndex)
60+
return songMatchScore, true
61+
} else if song.OrderBy == common.PlatformDefault {
62+
63+
}
64+
return 0, true
65+
}
66+
func AfterSearchSong(song common.SearchSong, songs []*common.Song) []*common.Song {
67+
if song.OrderBy == common.MatchedScoreDesc && len(songs) > 1 {
68+
sort.Sort(common.SongSlice(songs))
69+
}
70+
if song.Limit > 0 && len(songs) > song.Limit {
71+
songs = songs[:song.Limit]
72+
}
73+
return songs
74+
}

0 commit comments

Comments
 (0)