iawia002/lux · error
unable to get audio ID
Error message
unable to get audio ID
What it means
The Ximalaya extractor requires the URL itself to contain a /sound/<digits> segment (a single audio track). It runs utils.MatchOneOf(url, `/sound/(\d+)`); when there is no match, len(itemIds) == 0 and 'unable to get audio ID' is returned. The numeric sound id is mandatory because the playback API URL is built from it.
Source
Thrown at extractors/ximalaya/ximalaya.go:41
}
// Extract is the main function to extract the data.
func (e *extractor) Extract(url string, option extractors.Options) ([]*extractors.Data, error) {
html, err := request.Get(url, url, nil)
if err != nil {
return nil, errors.WithStack(err)
}
// get the title
doc, err := parser.GetDoc(html)
if err != nil {
return nil, errors.WithStack(err)
}
title := parser.Title(doc)
itemIds := utils.MatchOneOf(url, `/sound/(\d+)`)
if len(itemIds) == 0 {
return nil, errors.New("unable to get audio ID")
}
if itemIds == nil || len(itemIds) < 2 {
return nil, errors.WithStack(extractors.ErrURLParseFailed)
}
itemId := itemIds[len(itemIds)-1]
jsonData, err := request.Get("https://www.ximalaya.com/revision/play/v1/audio?id="+itemId+"&ptype=1", url, nil)
if err != nil {
return nil, errors.WithStack(err)
}
var ximalaya ximalayaData
if err = json.Unmarshal([]byte(jsonData), &ximalaya); err != nil {
return nil, errors.WithStack(err)
}
realURL := ximalaya.Data.Src
urlData := make([]*extractors.Part, 0)
totalSize, err := request.Size(realURL, url)View on GitHub (pinned to dd00f6d258)
Solutions
- Open the album in a browser and copy the URL of an individual track (contains /sound/123456)
- If you have album URLs, first expand them to their track URLs (album API or page parsing) before calling Extract
- Normalize share links to the canonical www.ximalaya.com/sound/<id> form
- Validate the /sound/\d+ pattern on the caller side before invoking Extract
Example fix
// before
_, err := ximalaya.Extract("https://www.ximalaya.com/album/12345678", opts) // -> unable to get audio ID
// after
_, err := ximalaya.Extract("https://www.ximalaya.com/sound/456033392", opts) // single track URL Defensive patterns
Strategy: validation
Validate before calling
var ximalayaSoundRe = regexp.MustCompile(`^https?://www\.ximalaya\.com/sound/\d+`)
func isXimalayaTrackURL(raw string) bool {
return ximalayaSoundRe.MatchString(raw)
} Try / catch
if !isXimalayaTrackURL(url) {
return fmt.Errorf("expected a ximalaya /sound/<id> track URL, got %s", url)
}
_, err := ximalaya.Extract(url, opts) Prevention
- Expand album URLs to their track URLs before extraction
- Canonicalize share links to www.ximalaya.com/sound/<id>
- URL-shape validation is cheap and converts runtime errors into early skips
When it happens
Trigger: Passing an album/playlist URL (https://www.ximalaya.com/album/12345678) instead of a single track, or share/search URLs that do not carry the /sound/ path segment. Note the code checks len == 0 before the nil check, so both nil and empty results land here.
Common situations: Users copy the album page link from the browser address bar; scripts enumerate album URLs expecting per-track extraction; mobile share URLs use a different path scheme.
Related errors
- Invalid video URL: Missing video ID parameter
- unable to get video ID
- 暂不支持斗鱼直播
- couldn't extract the media short code from the link
- invalid url for netease music
AI-assisted analysis of iawia002/lux@dd00f6d258 (2026-08-15).
Data as JSON: /api/errors/779a7543a7403d71.
Report an issue: GitHub.