{"record":{"id":"075345d43bb0cb6a","repo":"NanmiCoder/MediaCrawler","slug":"unable-to-parse-creator-id-from-url-url-075345","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/douyin/help.py","lineNumber":164,"sourceCode":"    2. Pure ID: MS4wLjABAAAATJPY7LAlaa5X-c8uNdWkvz0jUGgpw4eeXIwu_8BhvqE\n\n    Args:\n        url: Douyin creator homepage link or sec_user_id\n    Returns:\n        CreatorUrlInfo: Object containing creator ID\n    \"\"\"\n    # If it's a pure ID format (usually starts with MS4wLjABAAAA), return directly\n    if url.startswith(\"MS4wLjABAAAA\") or (not url.startswith(\"http\") and \"douyin.com\" not in url):\n        return CreatorUrlInfo(sec_user_id=url)\n\n    # Extract sec_user_id from creator homepage URL: /user/xxx\n    user_pattern = r'/user/([^/?]+)'\n    match = re.search(user_pattern, url)\n    if match:\n        sec_user_id = match.group(1)\n        return CreatorUrlInfo(sec_user_id=sec_user_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    print(\"=== Video URL Parsing Test ===\")\n    test_urls = [\n        \"https://www.douyin.com/video/7525082444551310602\",\n        \"https://www.douyin.com/user/MS4wLjABAAAATJPY7LAlaa5X-c8uNdWkvz0jUGgpw4eeXIwu_8BhvqE?from_tab_name=main&modal_id=7525082444551310602\",\n        \"https://www.douyin.com/root/search/python?aid=b733a3b0-4662-4639-9a72-c2318fba9f3f&modal_id=7471165520058862848&type=general\",\n        \"7525082444551310602\",\n    ]\n    for url in test_urls:\n        try:\n            result = parse_video_info_from_url(url)\n            print(f\"✓ URL: {url[:80]}...\")\n            print(f\"  Result: {result}\\n\")\n        except Exception as e:\n            print(f\"✗ URL: {url}\")","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/NanmiCoder/MediaCrawler/blob/d6f7c5bb906b6dac40ddf343ef9e26438a3de092/media_platform/douyin/help.py#L146-L182","documentation":"ValueError from parse_creator_info_from_url (media_platform/douyin/help.py) when the input is neither a bare sec_user_id (prefix 'MS4wLjABAAAA', or any non-http string not containing douyin.com) nor a URL containing /user/<segment>. Douyin creator ids are the long MS4w... sec_user_id strings embedded in /user/ paths, so usernames, homepages with other path shapes, or malformed links fall through.","triggerScenarios":"Passing a douyin.com URL whose creator path is not /user/... (e.g. a profile redirect through /profile/); an http(s) URL containing douyin.com but without a /user/ segment (search pages); a sec_user_id with a typo that still starts with MS4wLjABAAAA passes, but a truncated one wrapped in a full URL fails the regex.","commonSituations":"Copy-pasting the share page rather than the creator homepage; URL truncation losing the /user/ path; upstream layout changes on douyin.com.","solutions":["Pass the bare sec_user_id (the MS4wLjABAAAA... string) or the canonical https://www.douyin.com/user/<sec_user_id> URL.","Pre-validate http(s) inputs with the /user/([^/?]+) regex before calling.","Expand share/short links to their final form first."],"exampleFix":"# before\nparse_creator_info_from_url('https://www.douyin.com/search?author=x')\n\n# after\nparse_creator_info_from_url('https://www.douyin.com/user/MS4wLjABAAAATJPY7LAlaa5X-c8uNdWkvz0jUGgpw4eeXIwu_8BhvqE')","handlingStrategy":"validation","validationCode":"import re\nDY_USER_RE = re.compile(r'/user/([^/?]+)')\ndef extract_dy_sec_uid(u: str) -> str | None:\n    u = u.strip()\n    if u.startswith('MS4wLjABAAAA'):\n        return u\n    m = DY_USER_RE.search(u)\n    return m.group(1) if m else None","typeGuard":"def is_parseable_dy_creator(u: str) -> bool:\n    u = u.strip()\n    return u.startswith('MS4wLjABAAAA') or bool(re.search(r'/user/[^/?]+', u))","tryCatchPattern":"try:\n    info = parse_creator_info_from_url(url.strip())\nexcept ValueError:\n    logger.warning(f'not a douyin creator url/sec_uid: {url}')","preventionTips":["Pass the bare MS4wLjABAAAA... sec_user_id or a /user/<id> URL","Expand share links before parsing","Validate with the /user/ regex first in pipelines"],"tags":["douyin","url-parsing","valueerror","creator"],"backgroundTag":null,"analyzedSha":"d6f7c5bb906b6dac40ddf343ef9e26438a3de092","analyzedAt":"2026-08-15T01:39:07.505Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}