{"record":{"id":"422a8008b283946a","repo":"iawia002/lux","slug":"could-not-find-video-in-page","errorCode":null,"errorMessage":"could not find video in page","messagePattern":"could not find video in page","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"extractors/bilibili/bilibili.go","lineNumber":205,"sourceCode":"\t\thtml, `window.__INITIAL_STATE__=(.+?);\\(function`,\n\t)\n\tif multiPageDataString == nil {\n\t\treturn &data, errors.New(\"this page has no playlist\")\n\t}\n\terr := json.Unmarshal([]byte(multiPageDataString[1]), &data)\n\tif err != nil {\n\t\treturn nil, errors.WithStack(err)\n\t}\n\treturn &data, nil\n}\n\nfunc extractFestival(url, html string, extractOption extractors.Options) ([]*extractors.Data, error) {\n\tmatches := utils.MatchAll(html, \"<\\\\s*script[^>]*>\\\\s*window\\\\.__INITIAL_STATE__=([\\\\s\\\\S]*?);\\\\s?\\\\(function[\\\\s\\\\S]*?<\\\\/\\\\s*script\\\\s*>\")\n\tif len(matches) < 1 {\n\t\treturn nil, errors.WithStack(extractors.ErrURLParseFailed)\n\t}\n\tif len(matches[0]) < 2 {\n\t\treturn nil, errors.New(\"could not find video in page\")\n\t}\n\n\tvar festivalData festival\n\terr := json.Unmarshal([]byte(matches[0][1]), &festivalData)\n\tif err != nil {\n\t\treturn nil, errors.WithStack(err)\n\t}\n\n\toptions := bilibiliOptions{\n\t\turl:  url,\n\t\thtml: html,\n\t\taid:  festivalData.VideoInfo.Aid,\n\t\tbvid: festivalData.VideoInfo.BVid,\n\t\tcid:  festivalData.VideoInfo.Cid,\n\t\tpage: 0,\n\t}\n\n\treturn []*extractors.Data{bilibiliDownload(options, extractOption)}, nil","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/iawia002/lux/blob/dd00f6d258d80b6684a0b9402d7124e5c18ef42f/extractors/bilibili/bilibili.go#L187-L223","documentation":"bilibili.extractFestival handles festival/activity pages. It matches the whole script tag containing window.__INITIAL_STATE__ and this error fires when the outer script regex matched but the capture group is absent (len(matches[0]) < 2), i.e. the festival page has no extractable video state. It is distinct from the sibling ErrURLParseFailed check one line above, which fires when no script matched at all.","triggerScenarios":"A /festival/ URL whose activity ended and now redirects elsewhere; a festival template without the __INITIAL_STATE__ script payload; a risk-control page served instead of the festival DOM.","commonSituations":"Expired seasonal event links (the most common case); Bilibili template changes; scraping from flagged IPs.","solutions":["Confirm the festival URL still shows its video in an incognito browser.","If the event ended, locate the underlying av/BV id in the page and extract that video URL directly.","Retry with a cookie (-c) to bypass risk control.","If the page format changed, update the extractFestival script regex."],"exampleFix":"// before\n$ lux \"https://www.bilibili.com/festival/2022bnj?bvid=BV1er411b7mJ\"\n// after — extract the underlying video id directly\n$ lux \"https://www.bilibili.com/video/BV1er411b7mJ\"","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func isFestivalVideoMissing(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"could not find video in page\")\n}","tryCatchPattern":"Catch and, when this specific message appears, retry once with the underlying av/BV video URL extracted from the festival page; otherwise surface the error with the original festival link for manual triage.","preventionTips":["Treat festival links as perishable — events end and pages redirect","Pre-resolve festival URLs to their concrete video ids when archiving content","Pass a cookie for risk control when scraping bilibili at scale"],"tags":["bilibili","festival","html-parsing","scraping"],"backgroundTag":null,"analyzedSha":"dd00f6d258d80b6684a0b9402d7124e5c18ef42f","analyzedAt":"2026-08-15T16:57:31.080Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}