{"record":{"id":"8f50cdac67fb9daa","repo":"NanmiCoder/MediaCrawler","slug":"unable-to-parse-creator-id-from-url-url","errorCode":null,"errorMessage":"Unable to parse creator ID from URL: {url}","messagePattern":"Unable to parse creator ID from URL: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"media_platform/bilibili/help.py","lineNumber":131,"sourceCode":"            - https://space.bilibili.com/20813884\n            - 434377496 (directly pass UID)\n    Returns:\n        CreatorUrlInfo: Object containing creator ID\n    \"\"\"\n    # If the input is already a numeric ID, return directly\n    if url.isdigit():\n        return CreatorUrlInfo(creator_id=url)\n\n    # Use regex to extract UID\n    # Match /space.bilibili.com/number format\n    uid_pattern = r'space\\.bilibili\\.com/(\\d+)'\n    match = re.search(uid_pattern, url)\n\n    if match:\n        creator_id = match.group(1)\n        return CreatorUrlInfo(creator_id=creator_id)\n\n    raise ValueError(f\"Unable to parse creator ID from URL: {url}\")\n\n\nif __name__ == '__main__':\n    # Test video URL parsing\n    video_url1 = \"https://www.bilibili.com/video/BV1dwuKzmE26/?spm_id_from=333.1387.homepage.video_card.click\"\n    video_url2 = \"BV1d54y1g7db\"\n    print(\"Video URL parsing test:\")\n    print(f\"URL1: {video_url1} -> {parse_video_info_from_url(video_url1)}\")\n    print(f\"URL2: {video_url2} -> {parse_video_info_from_url(video_url2)}\")\n\n    # Test creator URL parsing\n    creator_url1 = \"https://space.bilibili.com/434377496?spm_id_from=333.1007.0.0\"\n    creator_url2 = \"20813884\"\n    print(\"\\nCreator URL parsing test:\")\n    print(f\"URL1: {creator_url1} -> {parse_creator_info_from_url(creator_url1)}\")\n    print(f\"URL2: {creator_url2} -> {parse_creator_info_from_url(creator_url2)}\")\n","sourceCodeStart":113,"sourceCodeEnd":148,"githubUrl":"https://github.com/NanmiCoder/MediaCrawler/blob/d6f7c5bb906b6dac40ddf343ef9e26438a3de092/media_platform/bilibili/help.py#L113-L148","documentation":"ValueError from parse_creator_info_from_url (media_platform/bilibili/help.py) when the input is neither an all-digit string (pure UID) nor a URL matching space.bilibili.com/(\\d+). Bilibili space IDs are numeric, so any non-digit slug, username-style URL, or malformed share link falls through to this raise.","triggerScenarios":"Passing a space URL with a non-numeric path (rare vanity/legacy forms); an empty or whitespace-only string failing url.isdigit(); a URL like 'https://space.bilibili.com/' with no ID; query-only strings where the digits sit in a param instead of the path.","commonSituations":"Copy-pasting creator links that got truncated at the digits; feeding a username or display name instead of the numeric UID; leading/trailing spaces or a '\\n' smuggled in from CSV input.","solutions":["Pass the numeric UID directly ('434377496') or the full space URL 'https://space.bilibili.com/434377496'.","Pre-validate with a digit check or the space.bilibili.com regex before calling.","Trim/normalize user input (strip whitespace) before parsing."],"exampleFix":"# before\nparse_creator_info_from_url(' 434377496\\n')\n\n# after\nparse_creator_info_from_url('434377496')","handlingStrategy":"validation","validationCode":"import re\nSPACE_RE = re.compile(r'space\\.bilibili\\.com/(\\d+)')\ndef extract_bili_uid(u: str) -> str | None:\n    u = u.strip()\n    if u.isdigit():\n        return u\n    m = SPACE_RE.search(u)\n    return m.group(1) if m else None","typeGuard":"def is_parseable_bili_creator(u: str) -> bool:\n    u = u.strip()\n    return u.isdigit() or bool(re.search(r'space\\.bilibili\\.com/\\d+', u))","tryCatchPattern":"try:\n    info = parse_creator_info_from_url(url.strip())\nexcept ValueError:\n    logger.warning(f'not a numeric bilibili space id/url: {url}')","preventionTips":["Bilibili creator ids are numeric — validate digits before calling","Strip whitespace from user-pasted input","Don't feed usernames or vanity names; only UIDs and space.bilibili.com/<uid> URLs"],"tags":["bilibili","url-parsing","valueerror","creator"],"backgroundTag":null,"analyzedSha":"d6f7c5bb906b6dac40ddf343ef9e26438a3de092","analyzedAt":"2026-08-15T01:39:07.505Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}