mirror of
https://github.com/AynaLivePlayer/AynaLivePlayer.git
synced 2025-12-06 18:32:50 +08:00
add netease login plugin
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
"AynaLivePlayer/plugin/diange"
|
||||
"AynaLivePlayer/plugin/qiege"
|
||||
"AynaLivePlayer/plugin/textinfo"
|
||||
"AynaLivePlayer/plugin/webinfo"
|
||||
"AynaLivePlayer/plugin/wylogin"
|
||||
"fmt"
|
||||
"github.com/mitchellh/panicwrap"
|
||||
"os"
|
||||
@@ -25,7 +25,8 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
var plugins = []controller.Plugin{diange.NewDiange(), qiege.NewQiege(), textinfo.NewTextInfo(), webinfo.NewWebInfo()}
|
||||
var plugins = []controller.Plugin{diange.NewDiange(), qiege.NewQiege(), textinfo.NewTextInfo(),
|
||||
wylogin.NewWYLogin()}
|
||||
|
||||
func main() {
|
||||
fmt.Printf("BiliAudioBot Revive %s\n", config.VERSION)
|
||||
|
||||
124
app/webs/main.go
124
app/webs/main.go
@@ -1,124 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gorilla/websocket"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var upgrader = websocket.Upgrader{
|
||||
ReadBufferSize: 1024,
|
||||
WriteBufferSize: 1024,
|
||||
CheckOrigin: func(r *http.Request) bool {
|
||||
return true
|
||||
},
|
||||
}
|
||||
|
||||
type WebInfo struct {
|
||||
A string
|
||||
B string
|
||||
}
|
||||
|
||||
type WebInfoServer struct {
|
||||
ServeMux http.ServeMux
|
||||
Clients map[*Client]int
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
conn *websocket.Conn
|
||||
Data chan []byte
|
||||
Close chan byte
|
||||
}
|
||||
|
||||
func NewWebInfoServer() *WebInfoServer {
|
||||
server := &WebInfoServer{
|
||||
Clients: map[*Client]int{},
|
||||
}
|
||||
server.ServeMux.Handle("/", http.FileServer(http.Dir("./assets/webinfo")))
|
||||
server.ServeMux.HandleFunc("/ws/info", server.handleInfo)
|
||||
return server
|
||||
}
|
||||
|
||||
func (s *WebInfoServer) handleInfo(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("connection start")
|
||||
conn, err := upgrader.Upgrade(w, r, nil)
|
||||
if err != nil {
|
||||
fmt.Println("upgrade error", err)
|
||||
return
|
||||
}
|
||||
client := &Client{
|
||||
conn: conn,
|
||||
Data: make(chan []byte, 16),
|
||||
Close: make(chan byte, 1),
|
||||
}
|
||||
s.addClient(client)
|
||||
defer s.removeClient(client)
|
||||
go func() {
|
||||
for {
|
||||
_, _, err := client.conn.ReadMessage()
|
||||
if err != nil {
|
||||
client.Close <- 1
|
||||
}
|
||||
}
|
||||
}()
|
||||
for {
|
||||
fmt.Println("waiting for message")
|
||||
select {
|
||||
case data := <-client.Data:
|
||||
writer, err := client.conn.NextWriter(websocket.TextMessage)
|
||||
if err != nil {
|
||||
fmt.Println("get writer error", err)
|
||||
return
|
||||
}
|
||||
|
||||
if _, err = writer.Write(data); err != nil {
|
||||
fmt.Println("send error:", err)
|
||||
return
|
||||
}
|
||||
if err = writer.Close(); err != nil {
|
||||
fmt.Println("can't close writer")
|
||||
return
|
||||
}
|
||||
case _ = <-client.Close:
|
||||
fmt.Println("client close", client.conn.Close())
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *WebInfoServer) sendInfo(info *WebInfo) {
|
||||
for client := range s.Clients {
|
||||
d, _ := json.Marshal(info)
|
||||
client.Data <- d
|
||||
}
|
||||
}
|
||||
|
||||
func (s *WebInfoServer) addClient(c *Client) {
|
||||
s.lock.Lock()
|
||||
s.Clients[c] = 1
|
||||
s.lock.Unlock()
|
||||
}
|
||||
|
||||
func (s *WebInfoServer) removeClient(c *Client) {
|
||||
s.lock.Lock()
|
||||
close(c.Data)
|
||||
delete(s.Clients, c)
|
||||
s.lock.Unlock()
|
||||
}
|
||||
|
||||
var info WebInfo = WebInfo{A: "asdf", B: "ffff"}
|
||||
|
||||
func main() {
|
||||
server := NewWebInfoServer()
|
||||
go func() {
|
||||
for {
|
||||
time.Sleep(time.Second * 5)
|
||||
server.sendInfo(&info)
|
||||
}
|
||||
}()
|
||||
http.ListenAndServe("localhost:8080", &server.ServeMux)
|
||||
}
|
||||
58
app/wylogin/main.go
Normal file
58
app/wylogin/main.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
neteaseApi "github.com/XiaoMengXinX/Music163Api-Go/api"
|
||||
"github.com/skip2/go-qrcode"
|
||||
"net/http"
|
||||
|
||||
//neteaseTypes "github.com/XiaoMengXinX/Music163Api-Go/types"
|
||||
neteaseUtil "github.com/XiaoMengXinX/Music163Api-Go/utils"
|
||||
)
|
||||
|
||||
var reqData = neteaseUtil.RequestData{
|
||||
Cookies: []*http.Cookie{},
|
||||
Headers: neteaseUtil.Headers{
|
||||
{
|
||||
"X-Real-IP",
|
||||
"118.88.88.88",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func IsLogin() {
|
||||
|
||||
}
|
||||
|
||||
func main() {
|
||||
status, err := neteaseApi.GetLoginStatus(reqData)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
fmt.Println(status.Profile.UserId)
|
||||
fmt.Println(status.Account.Id)
|
||||
unikey, err := neteaseApi.GetQrUnikey(reqData)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
fmt.Println(unikey.Unikey)
|
||||
qrcode.WriteFile(fmt.Sprintf("https://music.163.com/login?codekey=%s", unikey.Unikey), qrcode.Medium, 256, "qrcode.png")
|
||||
//wait user input
|
||||
var input string
|
||||
_, _ = fmt.Scanln(&input)
|
||||
login, h, err := neteaseApi.CheckQrLogin(reqData, unikey.Unikey)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, c := range (&http.Response{Header: h}).Cookies() {
|
||||
fmt.Println(c)
|
||||
}
|
||||
fmt.Println(login.Nickname, login.Message, login.Code)
|
||||
reqData.Cookies = (&http.Response{Header: h}).Cookies()
|
||||
status, err = neteaseApi.GetLoginStatus(reqData)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
fmt.Println(status.Profile.UserId)
|
||||
fmt.Println(status.Account.Id)
|
||||
}
|
||||
@@ -248,6 +248,38 @@
|
||||
"en": "User",
|
||||
"zh-CN": "普通用户"
|
||||
},
|
||||
"plugin.neteaselogin.logout": {
|
||||
"en": "Logout",
|
||||
"zh-CN": "登出"
|
||||
},
|
||||
"plugin.neteaselogin.current_user": {
|
||||
"en": "Current User:",
|
||||
"zh-CN": "当前用户:"
|
||||
},
|
||||
"plugin.neteaselogin.current_user.notlogin": {
|
||||
"en": "Not Login",
|
||||
"zh-CN": "未登录"
|
||||
},
|
||||
"plugin.neteaselogin.description": {
|
||||
"en": "Netease User Login",
|
||||
"zh-CN": "网易云登录"
|
||||
},
|
||||
"plugin.neteaselogin.qr.finish": {
|
||||
"en": "Finish Scan",
|
||||
"zh-CN": "完成扫描后按我"
|
||||
},
|
||||
"plugin.neteaselogin.qr.new": {
|
||||
"en": "Get a new qr code",
|
||||
"zh-CN": "获取新二维码"
|
||||
},
|
||||
"plugin.neteaselogin.refresh": {
|
||||
"en": "Refresh",
|
||||
"zh-CN": "刷新状态"
|
||||
},
|
||||
"plugin.neteaselogin.title": {
|
||||
"en": "Netease Login",
|
||||
"zh-CN": "网易云登录"
|
||||
},
|
||||
"plugin.qiege.admin": {
|
||||
"en": "Admin",
|
||||
"zh-CN": "管理员"
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"path"
|
||||
)
|
||||
|
||||
const VERSION = "alpha 0.8.3"
|
||||
const VERSION = "alpha 0.8.4"
|
||||
|
||||
const CONFIG_PATH = "./config.ini"
|
||||
const Assests_PATH = "./assets"
|
||||
|
||||
1
go.mod
1
go.mod
@@ -14,6 +14,7 @@ require (
|
||||
github.com/jinzhu/copier v0.3.5
|
||||
github.com/mitchellh/panicwrap v1.0.0
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
|
||||
github.com/spf13/cast v1.3.1
|
||||
github.com/tidwall/gjson v1.14.1
|
||||
gopkg.in/ini.v1 v1.66.4
|
||||
|
||||
2
go.sum
2
go.sum
@@ -95,6 +95,8 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
|
||||
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
|
||||
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
|
||||
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
|
||||
|
||||
52
gui/helper_async_button.go
Normal file
52
gui/helper_async_button.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
// AsyncButton is a Button that handle OnTapped handler asynchronously.
|
||||
type AsyncButton struct {
|
||||
widget.Button
|
||||
anim *fyne.Animation
|
||||
}
|
||||
|
||||
func NewAsyncButton(label string, tapped func()) *AsyncButton {
|
||||
button := &AsyncButton{
|
||||
Button: widget.Button{
|
||||
Text: label,
|
||||
OnTapped: tapped,
|
||||
},
|
||||
}
|
||||
button.ExtendBaseWidget(button)
|
||||
return button
|
||||
}
|
||||
|
||||
func NewAsyncButtonWithIcon(label string, icon fyne.Resource, tapped func()) *AsyncButton {
|
||||
button := &AsyncButton{
|
||||
Button: widget.Button{
|
||||
Text: label,
|
||||
Icon: icon,
|
||||
OnTapped: tapped,
|
||||
},
|
||||
}
|
||||
button.ExtendBaseWidget(button)
|
||||
return button
|
||||
}
|
||||
|
||||
func (b *AsyncButton) Tapped(e *fyne.PointEvent) {
|
||||
if b.Disabled() {
|
||||
return
|
||||
}
|
||||
|
||||
// missing animation
|
||||
b.Refresh()
|
||||
|
||||
if b.OnTapped != nil {
|
||||
b.Disable()
|
||||
go func() {
|
||||
b.OnTapped()
|
||||
b.Enable()
|
||||
}()
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package gui
|
||||
|
||||
import (
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
@@ -11,5 +12,10 @@ type RoomLoggerContainer struct {
|
||||
var RoomLogger = &RoomLoggerContainer{}
|
||||
|
||||
func createRoomLogger() fyne.CanvasObject {
|
||||
return widget.NewLabel("广告位招租")
|
||||
//b := NewAsyncButton("ceshi", func() {
|
||||
// time.Sleep(time.Second * 5)
|
||||
//})
|
||||
return container.NewVBox(
|
||||
widget.NewLabel("广告位招租"),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ type WebInfoServer struct {
|
||||
Info OutInfo
|
||||
Server *http.Server
|
||||
Clients map[*Client]int
|
||||
Running bool
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
@@ -40,7 +41,7 @@ func NewWebInfoServer(port int) *WebInfoServer {
|
||||
mux.HandleFunc("/ws/info", server.handleInfo)
|
||||
mux.HandleFunc("/api/info", server.getInfo)
|
||||
server.Server = &http.Server{
|
||||
Addr: fmt.Sprintf(":%d", port),
|
||||
Addr: fmt.Sprintf("localhost:%d", port),
|
||||
Handler: mux,
|
||||
}
|
||||
return server
|
||||
@@ -127,8 +128,10 @@ func (s *WebInfoServer) removeClient(c *Client) {
|
||||
}
|
||||
|
||||
func (s *WebInfoServer) Start() {
|
||||
s.Running = true
|
||||
go func() {
|
||||
err := s.Server.ListenAndServe()
|
||||
s.Running = false
|
||||
if err == http.ErrServerClosed {
|
||||
lg.Info("server closed")
|
||||
return
|
||||
@@ -141,5 +144,8 @@ func (s *WebInfoServer) Start() {
|
||||
}
|
||||
|
||||
func (s *WebInfoServer) Stop() error {
|
||||
s.lock.Lock()
|
||||
s.Clients = map[*Client]int{}
|
||||
s.lock.Unlock()
|
||||
return s.Server.Shutdown(context.Background())
|
||||
}
|
||||
|
||||
@@ -136,5 +136,5 @@ func (t *WebInfo) registerHandlers() {
|
||||
}
|
||||
|
||||
func (w *WebInfo) CreatePanel() fyne.CanvasObject {
|
||||
return widget.NewLabel("adf")
|
||||
return widget.NewLabel("No Setting")
|
||||
}
|
||||
|
||||
164
plugin/wylogin/wylogin.go
Normal file
164
plugin/wylogin/wylogin.go
Normal file
@@ -0,0 +1,164 @@
|
||||
package wylogin
|
||||
|
||||
import (
|
||||
"AynaLivePlayer/config"
|
||||
"AynaLivePlayer/gui"
|
||||
"AynaLivePlayer/i18n"
|
||||
"AynaLivePlayer/logger"
|
||||
"AynaLivePlayer/provider"
|
||||
"bytes"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
qrcode "github.com/skip2/go-qrcode"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const MODULE_PLGUIN_NETEASELOGIN = "plugin.neteaselogin"
|
||||
|
||||
var lg = logger.Logger.WithField("Module", MODULE_PLGUIN_NETEASELOGIN)
|
||||
|
||||
type WYLogin struct {
|
||||
MusicU string
|
||||
CSRF string
|
||||
panel fyne.CanvasObject
|
||||
}
|
||||
|
||||
func NewWYLogin() *WYLogin {
|
||||
return &WYLogin{
|
||||
MusicU: "MUSIC_U=;",
|
||||
CSRF: "__csrf=;",
|
||||
}
|
||||
}
|
||||
|
||||
func (w *WYLogin) Name() string {
|
||||
return "NeteaseLogin"
|
||||
}
|
||||
|
||||
func (w *WYLogin) Enable() error {
|
||||
config.LoadConfig(w)
|
||||
w.loadCookie()
|
||||
gui.AddConfigLayout(w)
|
||||
go func() {
|
||||
lg.Info("updating netease status")
|
||||
provider.NeteaseAPI.UpdateStatus()
|
||||
lg.Info("finish updating netease status")
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *WYLogin) Disable() error {
|
||||
w.saveCookie()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *WYLogin) loadCookie() {
|
||||
provider.NeteaseAPI.ReqData.Cookies = (&http.Response{
|
||||
Header: map[string][]string{
|
||||
"Set-Cookie": []string{w.MusicU, w.CSRF},
|
||||
},
|
||||
}).Cookies()
|
||||
}
|
||||
|
||||
func (w *WYLogin) saveCookie() {
|
||||
for _, c := range provider.NeteaseAPI.ReqData.Cookies {
|
||||
if c.Name == "MUSIC_U" {
|
||||
w.MusicU = c.String()
|
||||
}
|
||||
if c.Name == "__csrf" {
|
||||
w.CSRF = c.String()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (w *WYLogin) Title() string {
|
||||
return i18n.T("plugin.neteaselogin.title")
|
||||
}
|
||||
|
||||
func (w *WYLogin) Description() string {
|
||||
return i18n.T("plugin.neteaselogin.description")
|
||||
}
|
||||
|
||||
func (w *WYLogin) CreatePanel() fyne.CanvasObject {
|
||||
if w.panel != nil {
|
||||
return w.panel
|
||||
}
|
||||
currentUser := widget.NewLabel(i18n.T("plugin.neteaselogin.current_user.notlogin"))
|
||||
currentStatus := container.NewHBox(
|
||||
widget.NewLabel(i18n.T("plugin.neteaselogin.current_user")),
|
||||
currentUser)
|
||||
|
||||
refreshBtn := gui.NewAsyncButton(
|
||||
i18n.T("plugin.neteaselogin.refresh"),
|
||||
func() {
|
||||
provider.NeteaseAPI.UpdateStatus()
|
||||
if provider.NeteaseAPI.IsLogin() {
|
||||
currentUser.SetText(provider.NeteaseAPI.Nickname())
|
||||
} else {
|
||||
currentUser.SetText(i18n.T("plugin.neteaselogin.current_user.notlogin"))
|
||||
}
|
||||
|
||||
},
|
||||
)
|
||||
logoutBtn := gui.NewAsyncButton(
|
||||
i18n.T("plugin.neteaselogin.logout"),
|
||||
func() {
|
||||
provider.NeteaseAPI.Logout()
|
||||
currentUser.SetText(i18n.T("plugin.neteaselogin.current_user.notlogin"))
|
||||
},
|
||||
)
|
||||
controlBtns := container.NewHBox(refreshBtn, logoutBtn)
|
||||
qrcodeImg := canvas.NewImageFromFile(config.GetAssetPath("empty.png"))
|
||||
qrcodeImg.SetMinSize(fyne.NewSize(200, 200))
|
||||
qrcodeImg.FillMode = canvas.ImageFillContain
|
||||
var key string
|
||||
qrStatus := widget.NewLabel("AAAAAAAA")
|
||||
qrStatus.SetText("")
|
||||
newQrBtn := gui.NewAsyncButton(
|
||||
i18n.T("plugin.neteaselogin.qr.new"),
|
||||
func() {
|
||||
qrStatus.SetText("")
|
||||
lg.Info("getting a new qr code for login")
|
||||
key = provider.NeteaseAPI.GetQrLoginKey()
|
||||
if key == "" {
|
||||
lg.Warn("fail to get qr code key")
|
||||
return
|
||||
}
|
||||
lg.Debugf("trying encode url %s to qrcode", provider.NeteaseAPI.GetQrLoginUrl(key))
|
||||
data, err := qrcode.Encode(provider.NeteaseAPI.GetQrLoginUrl(key), qrcode.Medium, 256)
|
||||
if err != nil {
|
||||
lg.Warnf("generate qr code failed: %s", err)
|
||||
return
|
||||
}
|
||||
lg.Debug("create img from raw data")
|
||||
pic := canvas.NewImageFromReader(bytes.NewReader(data), "qrcode")
|
||||
qrcodeImg.Resource = pic.Resource
|
||||
qrcodeImg.Refresh()
|
||||
},
|
||||
)
|
||||
finishQrBtn := gui.NewAsyncButton(
|
||||
i18n.T("plugin.neteaselogin.qr.finish"),
|
||||
func() {
|
||||
if key == "" {
|
||||
return
|
||||
}
|
||||
lg.Info("checking qr status")
|
||||
ok, msg := provider.NeteaseAPI.CheckQrLogin(key)
|
||||
qrStatus.SetText(msg)
|
||||
if ok {
|
||||
key = ""
|
||||
qrcodeImg.Resource = nil
|
||||
qrcodeImg.Refresh()
|
||||
}
|
||||
},
|
||||
)
|
||||
loginPanel := container.NewCenter(
|
||||
container.NewVBox(
|
||||
qrcodeImg,
|
||||
container.NewHBox(newQrBtn, finishQrBtn, qrStatus),
|
||||
),
|
||||
)
|
||||
w.panel = container.NewVBox(controlBtns, currentStatus, loginPanel)
|
||||
return w.panel
|
||||
}
|
||||
@@ -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