Advanced Usage
Cookie Configuration
Some NetEase Cloud Music features require authentication, such as accessing user playlists or higher-quality audio streams. You can set the cookie using the chainable cookie() method:
Obtaining Your Cookie
- Log in to NetEase Cloud Music in your browser
- Open the browser's Developer Tools (F12)
- Go to the Application or Storage tab
- Find the cookies for
music.163.com - Copy the full cookie string, particularly the
MUSIC_Uvalue
Cookie in HTTP Server
When using the HTTP server, pass the cookie via the Cookie request header:
Format Mode
NCMGET operates in two modes controlled by the format() method:
Formatted Mode (Default)
When formatting is enabled (default), NCMGET extracts and structures the API response into consistent, predictable objects:
Raw Mode
When formatting is disabled, the raw API response is returned as-is:
The raw response structure differs from the formatted one and may contain additional fields from the NetEase API. Use raw mode when you need access to fields that are not included in the formatted output.
EAPI Encryption
NCMGET supports NetEase Cloud Music's EAPI encryption (netease_eapi). This is used internally for certain API endpoints that require encrypted communication.
How It Works
The _exec pipeline processes requests through these stages:
- Encode: If the API config specifies
encode: "netease_eapi", the request body is encrypted using the EAPI algorithm before being sent - HTTP: The encrypted request is sent to the NetEase API server
- Decode: If
decodeis specified (e.g.,"netease_url","netease_lrc"), the response is decrypted and parsed - Format: If formatting is enabled, the parsed data is extracted using the
formatdot-path (e.g.,"result.songs")
You do not need to manually handle encryption — NCMGET applies it automatically based on the API endpoint being called.
Error Handling
Core Error Model
NCMGET does not throw exceptions on API errors. Instead, errors are stored in instance properties:
Timeout
The default request timeout is 20 seconds. If a request exceeds this duration, ncmget.error will be set to "TIMEOUT".
Retry Mechanism
NCMGET automatically retries failed HTTP requests 3 times with a 1 second interval between retries. This handles transient network issues without manual intervention.
Checking for Errors
Always check the error property after an API call:
Instance Safety
NCMGET instances are not thread-safe. The error, status, raw, and info properties are shared state on the instance. If you make concurrent requests with the same instance, these properties may be overwritten.
Best Practice: One Instance Per Operation
For concurrent usage, create a new NCMGET instance for each independent operation:
The HTTP server already follows this pattern — it creates a new NCMGET instance per request.
