iawia002/lux · error
couldn't extract the media short code from the link
Error message
couldn't extract the media short code from the link
What it means
extractShortCodeFromLink pulls the media shortcode from the paths /p/<code>, /tv/<code>, /reel/<code> and /reels/videos/<code>. The error means the link matches none of these shapes, so no Instagram endpoint can be queried. It fails before any network request.
Source
Thrown at extractors/instagram/instagram.go:132
for _, item := range embedResponse.Media.SliderItems.Edges {
result = append(result, item.Node.extractMediaURL())
}
return result, nil
}
if embeddedMediaImage != "" {
return []string{embeddedMediaImage}, nil
}
// If every two methods have failed, then return an error
return nil, errors.New("failed to fetch the post, the page might be \"private\", or the link is completely wrong")
}
func extractShortCodeFromLink(link string) (string, error) {
values := regexp.MustCompile(`(p|tv|reel|reels\/videos)\/([A-Za-z0-9-_]+)`).FindStringSubmatch(link)
if len(values) != 3 {
return "", errors.New("couldn't extract the media short code from the link")
}
return values[2], nil
}
type extractor struct{}
// New returns a instagram extractor.
func New() extractors.Extractor {
return &extractor{}
}
// Extract is the main function to extract the data.
func (e *extractor) Extract(url string, option extractors.Options) ([]*extractors.Data, error) {
u, err := netURL.Parse(url)
if err != nil {
return nil, errors.WithStack(err)
}View on GitHub (pinned to dd00f6d258)
Solutions
- Use the post permalink form https://www.instagram.com/p/<code>/.
- For reels use /reel/<code>/; for IGTV /tv/<code>/.
- URL-decode and inspect the path portion before passing the link.
Example fix
// before $ lux "https://www.instagram.com/someuser/" // after $ lux "https://www.instagram.com/p/Cx1y2z3AbCd/"
Defensive patterns
Strategy: validation
Validate before calling
var shortCodeRe = regexp.MustCompile(`(p|tv|reel|reels/videos)/([A-Za-z0-9-_]+)`)
if shortCodeRe.FindStringSubmatch(link) == nil {
return fmt.Errorf("not an instagram post link (need /p|/tv|/reel/<code>): %s", link)
} Type guard
func isInstagramPostLink(link string) bool {
return regexp.MustCompile(`(p|tv|reel|reels/videos)/([A-Za-z0-9-_]+)`).MatchString(link)
} Prevention
- Validate the path shape before enqueueing Instagram URLs
- Normalize share links to /p/<code>/ permalink form
- Reject profile and stories links early with a clear message
When it happens
Trigger: Profile URLs (instagram.com/<user>/); /stories/... links; explore pages; truncated or URL-encoded share links that lost their path.
Common situations: Sharing a profile instead of a post; app share-links using path schemes outside the alternation; odd casing or trailing content that breaks the character class.
Related errors
- unable to get video ID
- Invalid video URL: Missing video ID parameter
- 暂不支持斗鱼直播
- failed to fetch the post, the page might be "private", or th
- invalid url for netease music
AI-assisted analysis of iawia002/lux@dd00f6d258 (2026-08-15).
Data as JSON: /api/errors/14db2c85deb88d54.
Report an issue: GitHub.