mirror of
https://github.com/AynaLivePlayer/AynaLivePlayer.git
synced 2025-12-13 13:38:16 +08:00
add netease login plugin
This commit is contained in:
@@ -4,7 +4,7 @@ import (
|
||||
"AynaLivePlayer/player"
|
||||
"AynaLivePlayer/util"
|
||||
neteaseApi "github.com/XiaoMengXinX/Music163Api-Go/api"
|
||||
"github.com/XiaoMengXinX/Music163Api-Go/types"
|
||||
neteaseTypes "github.com/XiaoMengXinX/Music163Api-Go/types"
|
||||
neteaseUtil "github.com/XiaoMengXinX/Music163Api-Go/utils"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@@ -17,6 +17,7 @@ type Netease struct {
|
||||
ReqData neteaseUtil.RequestData
|
||||
IdRegex0 *regexp.Regexp
|
||||
IdRegex1 *regexp.Regexp
|
||||
loginStatus neteaseTypes.LoginStatusData
|
||||
}
|
||||
|
||||
func _newNetease() *Netease {
|
||||
@@ -44,7 +45,9 @@ func init() {
|
||||
Providers[NeteaseAPI.GetName()] = NeteaseAPI
|
||||
}
|
||||
|
||||
func _neteaseGetArtistNames(data types.SongDetailData) string {
|
||||
// Netease private helper method
|
||||
|
||||
func _neteaseGetArtistNames(data neteaseTypes.SongDetailData) string {
|
||||
artists := make([]string, 0)
|
||||
for _, a := range data.Ar {
|
||||
artists = append(artists, a.Name)
|
||||
@@ -52,6 +55,8 @@ func _neteaseGetArtistNames(data types.SongDetailData) string {
|
||||
return strings.Join(artists, ",")
|
||||
}
|
||||
|
||||
// MediaProvider implementation
|
||||
|
||||
func (n *Netease) GetName() string {
|
||||
return "netease"
|
||||
}
|
||||
|
||||
62
provider/netease_extra.go
Normal file
62
provider/netease_extra.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
neteaseApi "github.com/XiaoMengXinX/Music163Api-Go/api"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Netease other method
|
||||
|
||||
func (n *Netease) UpdateStatus() {
|
||||
status, _ := neteaseApi.GetLoginStatus(n.ReqData)
|
||||
n.loginStatus = status
|
||||
}
|
||||
|
||||
// IsLogin check if current cookie is a login user
|
||||
func (n *Netease) IsLogin() bool {
|
||||
return n.loginStatus.Profile.UserId != 0
|
||||
}
|
||||
|
||||
func (n *Netease) Nickname() string {
|
||||
return n.loginStatus.Profile.Nickname
|
||||
}
|
||||
|
||||
func (n *Netease) GetQrLoginKey() string {
|
||||
unikey, err := neteaseApi.GetQrUnikey(n.ReqData)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return unikey.Unikey
|
||||
}
|
||||
|
||||
func (n *Netease) GetQrLoginUrl(key string) string {
|
||||
return fmt.Sprintf("https://music.163.com/login?codekey=%s", key)
|
||||
}
|
||||
|
||||
func (n *Netease) CheckQrLogin(key string) (bool, string) {
|
||||
login, h, err := neteaseApi.CheckQrLogin(n.ReqData, key)
|
||||
if err != nil {
|
||||
return false, ""
|
||||
}
|
||||
// if login.Code == 800 || login.Code == 803. login success
|
||||
if login.Code != 800 && login.Code != 803 {
|
||||
return false, login.Message
|
||||
}
|
||||
cookies := make([]*http.Cookie, 0)
|
||||
for _, c := range (&http.Response{Header: h}).Cookies() {
|
||||
if c.Name == "MUSIC_U" || c.Name == "__csrf" {
|
||||
cookies = append(cookies, c)
|
||||
}
|
||||
}
|
||||
n.ReqData.Cookies = cookies
|
||||
return true, login.Message
|
||||
}
|
||||
|
||||
func (n *Netease) Logout() {
|
||||
n.ReqData.Cookies = []*http.Cookie{
|
||||
{Name: "MUSIC_U", Value: ""},
|
||||
{Name: "__csrf", Value: ""},
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user