api

package
v1.1.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultWEAPIUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) NeteaseMusicDesktop/2.3.17.1034"
	DefaultEAPIUserAgent  = "NeteaseMusic 9.4.95/6806 (iPhone; iOS 16.6.1; zh_CN)"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(cfg *Config) *Client

func NewClient

func NewClient(cfg *Config, l *log.Logger) (*Client, error)

func (*Client) Close

func (c *Client) Close(ctx context.Context) error

func (*Client) Cookie

func (c *Client) Cookie(url, name string) (http.Cookie, bool)

Cookie 根据url和cookie name获取cookie.

func (*Client) Download

func (c *Client) Download(ctx context.Context, url string, headers map[string]string, reqBody io.Reader, resp io.Writer, bar *pb.ProgressBar) (*http.Response, error)

func (*Client) GetCSRF

func (c *Client) GetCSRF(url string) (string, bool)

GetCSRF 获取csrf 一般用于weapi接口中使用.

func (*Client) GetClient

func (c *Client) GetClient() *http.Client

func (*Client) GetCookies

func (c *Client) GetCookies(url *neturl.URL) []*http.Cookie

func (*Client) GetDeviceId added in v1.1.4

func (c *Client) GetDeviceId() string

GetDeviceId 从当前客户端的 Cookie 中获取设备 ID

func (*Client) MusicU added in v1.1.8

func (c *Client) MusicU() string

func (*Client) NewRequest

func (c *Client) NewRequest(mode ...CryptoMode) *resty.Request

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

func (*Client) Request

func (c *Client) Request(ctx context.Context, url string, req, resp interface{}, opts *Options) (*resty.Response, error)

Request 接口请求.

func (*Client) SetCookies

func (c *Client) SetCookies(url *neturl.URL, cookies []*http.Cookie)

SetCookies 设置cookies.

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, url string, headers map[string]string, data io.Reader, resp interface{}, bar *pb.ProgressBar) (*resty.Response, error)

func (*Client) UserAgent

func (c *Client) UserAgent(mode CryptoMode) string

type Config

type Config struct {
	Debug     bool            `json:"debug" yaml:"debug"`
	Timeout   time.Duration   `json:"timeout" yaml:"timeout"`
	Retry     int             `json:"retry" yaml:"retry"`
	Cookie    cookie.Config   `json:"cookie" yaml:"cookie"`
	UserAgent UserAgentConfig `json:"user_agent" yaml:"user_agent"`
}

func (*Config) Validate

func (c *Config) Validate() error

type CryptoMode

type CryptoMode string
const (
	CryptoModeAPI   CryptoMode = "api"
	CryptoModeEAPI  CryptoMode = "eapi"
	CryptoModeXEAPI CryptoMode = "xeapi"
	CryptoModeWEAPI CryptoMode = "weapi"
	CryptoModeLinux CryptoMode = "linux"
)

type Options

type Options struct {
	Method     string
	CryptoMode CryptoMode
	Headers    map[string]string
	Cookies    []*http.Cookie
}

func NewOptions

func NewOptions() *Options

func (*Options) SetCookies

func (o *Options) SetCookies(c ...*http.Cookie)

func (*Options) SetHeader

func (o *Options) SetHeader(key, value string) *Options

func (*Options) SetHeaders

func (o *Options) SetHeaders(h map[string]string) *Options

type UserAgentConfig

type UserAgentConfig struct {
	Default string `json:"default" yaml:"default"`
	WEAPI   string `json:"weapi" yaml:"weapi"`
	EAPI    string `json:"eapi" yaml:"eapi"`
	XEAPI   string `json:"xeapi" yaml:"xeapi"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL