mirror of
https://github.com/AynaLivePlayer/miaosic.git
synced 2026-03-15 13:33:17 +08:00
add kugou instrumental api
This commit is contained in:
2
go.mod
2
go.mod
@@ -17,6 +17,7 @@ require (
|
||||
github.com/spf13/cast v1.5.0
|
||||
github.com/stretchr/testify v1.8.4
|
||||
github.com/tidwall/gjson v1.16.0
|
||||
golang.org/x/text v0.3.7
|
||||
)
|
||||
|
||||
require (
|
||||
@@ -29,6 +30,5 @@ require (
|
||||
github.com/tidwall/match v1.1.1 // indirect
|
||||
github.com/tidwall/pretty v1.2.0 // indirect
|
||||
golang.org/x/net v0.0.0-20211029224645-99673261e6eb // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
@@ -2,6 +2,13 @@ package kugou
|
||||
|
||||
import "github.com/AynaLivePlayer/miaosic"
|
||||
|
||||
var api *Kugou
|
||||
|
||||
func init() {
|
||||
miaosic.RegisterProvider(NewKugou(true))
|
||||
api = NewKugou(false)
|
||||
miaosic.RegisterProvider(api)
|
||||
}
|
||||
|
||||
func UseInstrumental() {
|
||||
miaosic.RegisterProvider(&KugouInstrumental{api})
|
||||
}
|
||||
|
||||
71
providers/kugou/kugou_instr.go
Normal file
71
providers/kugou/kugou_instr.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package kugou
|
||||
|
||||
import (
|
||||
"github.com/AynaLivePlayer/miaosic"
|
||||
)
|
||||
|
||||
type KugouInstrumental struct {
|
||||
k *Kugou
|
||||
}
|
||||
|
||||
func (k *KugouInstrumental) GetName() string {
|
||||
return "Kugou-Instr"
|
||||
}
|
||||
|
||||
func (k *KugouInstrumental) Search(keyword string, page, size int) ([]miaosic.MediaInfo, error) {
|
||||
result, err := k.k.Search(keyword, page, size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := 0; i < len(result); i++ {
|
||||
result[i].Meta.Provider = k.GetName()
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (k *KugouInstrumental) MatchMedia(uri string) (miaosic.MetaData, bool) {
|
||||
m, ok := k.k.MatchMedia(uri)
|
||||
if !ok {
|
||||
return m, ok
|
||||
}
|
||||
m.Provider = k.GetName()
|
||||
return m, ok
|
||||
}
|
||||
|
||||
func (k *KugouInstrumental) GetMediaInfo(meta miaosic.MetaData) (miaosic.MediaInfo, error) {
|
||||
m, err := k.k.GetMediaInfo(meta)
|
||||
if err != nil {
|
||||
return m, err
|
||||
}
|
||||
m.Meta.Provider = k.GetName()
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (k *KugouInstrumental) GetMediaUrl(meta miaosic.MetaData, quality miaosic.Quality) ([]miaosic.MediaUrl, error) {
|
||||
return k.k.GetMediaUrl(meta, "magic_acappella")
|
||||
}
|
||||
|
||||
func (k *KugouInstrumental) GetMediaLyric(meta miaosic.MetaData) ([]miaosic.Lyrics, error) {
|
||||
return k.k.GetMediaLyric(meta)
|
||||
}
|
||||
|
||||
func (k *KugouInstrumental) MatchPlaylist(uri string) (miaosic.MetaData, bool) {
|
||||
m, ok := k.k.MatchPlaylist(uri)
|
||||
if !ok {
|
||||
return m, ok
|
||||
}
|
||||
m.Provider = k.GetName()
|
||||
return m, ok
|
||||
}
|
||||
|
||||
func (k *KugouInstrumental) GetPlaylist(meta miaosic.MetaData) (*miaosic.Playlist, error) {
|
||||
p, err := k.k.GetPlaylist(meta)
|
||||
if err != nil {
|
||||
return p, err
|
||||
}
|
||||
p.Meta.Provider = k.GetName()
|
||||
for i := 0; i < len(p.Medias); i++ {
|
||||
p.Medias[i].Meta.Provider = k.GetName()
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
@@ -7,10 +7,10 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var api = NewKugou(true)
|
||||
var testApi = NewKugou(false)
|
||||
|
||||
func TestKugou_Search(t *testing.T) {
|
||||
result, err := api.Search("心似烟火", 1, 20)
|
||||
result, err := testApi.Search("心似烟火", 1, 20)
|
||||
require.NoError(t, err, "Search Error")
|
||||
require.NotEmpty(t, result, "Search Result Empty")
|
||||
require.Equal(t, 20, len(result), "Search Result Length")
|
||||
@@ -18,40 +18,40 @@ func TestKugou_Search(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestKugou_GetMediaInfo(t *testing.T) {
|
||||
meta := miaosic.MetaData{Identifier: "c79c062ff4b362ac253031c6e577e722", Provider: api.GetName()}
|
||||
result, err := api.GetMediaInfo(meta)
|
||||
meta := miaosic.MetaData{Identifier: "c79c062ff4b362ac253031c6e577e722", Provider: testApi.GetName()}
|
||||
result, err := testApi.GetMediaInfo(meta)
|
||||
require.NoError(t, err, "GetMediaInfo Error")
|
||||
require.NotEmpty(t, result, "GetMediaInfo Result Empty")
|
||||
t.Log(result)
|
||||
}
|
||||
|
||||
func TestKugou_GetMediaInfo2(t *testing.T) {
|
||||
meta := miaosic.MetaData{Identifier: "24aae0ef48311770043044ab2376a8db", Provider: api.GetName()}
|
||||
result, err := api.GetMediaInfo(meta)
|
||||
meta := miaosic.MetaData{Identifier: "24aae0ef48311770043044ab2376a8db", Provider: testApi.GetName()}
|
||||
result, err := testApi.GetMediaInfo(meta)
|
||||
require.NoError(t, err, "GetMediaInfo Error")
|
||||
require.NotEmpty(t, result, "GetMediaInfo Result Empty")
|
||||
t.Log(result)
|
||||
}
|
||||
|
||||
func TestKugou_GetMediaUrl(t *testing.T) {
|
||||
meta := miaosic.MetaData{Identifier: strings.ToLower("24aae0ef48311770043044ab2376a8db"), Provider: api.GetName()}
|
||||
result, err := api.GetMediaUrl(meta, miaosic.Quality128k)
|
||||
meta := miaosic.MetaData{Identifier: strings.ToLower("24aae0ef48311770043044ab2376a8db"), Provider: testApi.GetName()}
|
||||
result, err := testApi.GetMediaUrl(meta, miaosic.QualitySQ)
|
||||
require.NoError(t, err, "GetMediaUrl Error")
|
||||
require.NotEmpty(t, result, "GetMediaUrl Result Empty")
|
||||
t.Log(result)
|
||||
}
|
||||
|
||||
func TestKugou_GetMediaUrlAcappella(t *testing.T) {
|
||||
meta := miaosic.MetaData{Identifier: strings.ToLower("24aae0ef48311770043044ab2376a8db"), Provider: api.GetName()}
|
||||
result, err := api.GetMediaUrl(meta, "magic_acappella")
|
||||
meta := miaosic.MetaData{Identifier: strings.ToLower("16bbfe8fbcd9e62731c3c44ba79ae794"), Provider: testApi.GetName()}
|
||||
result, err := testApi.GetMediaUrl(meta, "magic_acappella")
|
||||
require.NoError(t, err, "GetMediaUrl Error")
|
||||
require.NotEmpty(t, result, "GetMediaUrl Result Empty")
|
||||
t.Log(result)
|
||||
}
|
||||
|
||||
func TestKugou_GetMediaLyric(t *testing.T) {
|
||||
meta := miaosic.MetaData{Identifier: "24aae0ef48311770043044ab2376a8db", Provider: api.GetName()}
|
||||
result, err := api.GetMediaLyric(meta)
|
||||
meta := miaosic.MetaData{Identifier: "24aae0ef48311770043044ab2376a8db", Provider: testApi.GetName()}
|
||||
result, err := testApi.GetMediaLyric(meta)
|
||||
require.NoError(t, err, "GetMediaLyric Error")
|
||||
require.NotEmpty(t, result, "GetMediaLyric Result Empty")
|
||||
t.Log(result)
|
||||
|
||||
@@ -15,7 +15,8 @@ func (n *Kugou) Login(username string, password string) error {
|
||||
}
|
||||
|
||||
func (n *Kugou) IsLogin() bool {
|
||||
return false
|
||||
_, ok := n.cookie["token"]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (n *Kugou) QrLogin() (*miaosic.QrLoginSession, error) {
|
||||
|
||||
@@ -26,21 +26,21 @@ func TestSignatureWebParams(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestKugou_QrLogin(t *testing.T) {
|
||||
login, err := api.QrLogin()
|
||||
login, err := testApi.QrLogin()
|
||||
require.NoError(t, err, "QrLogin Error")
|
||||
require.NotEmpty(t, login, "QrLogin Result Empty")
|
||||
t.Log(login)
|
||||
}
|
||||
|
||||
func TestKugou_QrLoginVerify(t *testing.T) {
|
||||
result, err := api.QrLoginVerify(&miaosic.QrLoginSession{
|
||||
Url: "https://h5.kugou.com/apps/loginQRCode/html/index.html?qrcode=5526fbc7576759da17bdeea9f02269323116",
|
||||
Key: "5526fbc7576759da17bdeea9f02269323116",
|
||||
result, err := testApi.QrLoginVerify(&miaosic.QrLoginSession{
|
||||
Url: "https://h5.kugou.com/apps/loginQRCode/html/index.html?qrcode=764ed534812fc1438e165b0d794b91121005",
|
||||
Key: "764ed534812fc1438e165b0d794b91121005",
|
||||
})
|
||||
require.NoError(t, err, "QrLoginVerify Error")
|
||||
require.NotEmpty(t, result, "QrLoginVerify Result Empty")
|
||||
t.Log(result)
|
||||
if result.Success {
|
||||
t.Log("session", api.SaveSession())
|
||||
t.Log("session", testApi.SaveSession())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ const (
|
||||
|
||||
// signKey encrypts the given parameters and returns the encrypted sign.
|
||||
func signKey(appid string, hash, mid, userid string) string {
|
||||
data := hash + "57ae12eb6890223e355ccfcb74edf70d" + appidLite + mid + userid
|
||||
data := hash + "57ae12eb6890223e355ccfcb74edf70d" + appid + mid + userid
|
||||
return getMD5Hash(data)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user