{"record":{"id":"92dd19bc4850f32d","repo":"NanmiCoder/MediaCrawler","slug":"unable-to-parse-video-id-from-url-url-92dd19","errorCode":null,"errorMessage":"Unable to parse video ID from URL: {url}","messagePattern":"Unable to parse video ID from URL: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"media_platform/douyin/help.py","lineNumber":138,"sourceCode":"\n    # Check if it's a short link (v.douyin.com)\n    if \"v.douyin.com\" in url or url.startswith(\"http\") and len(url) < 50 and \"video\" not in url:\n        return VideoUrlInfo(aweme_id=\"\", url_type=\"short\")  # Requires client parsing\n\n    # Try to extract modal_id from URL parameters\n    params = extract_url_params_to_dict(url)\n    modal_id = params.get(\"modal_id\")\n    if modal_id:\n        return VideoUrlInfo(aweme_id=modal_id, url_type=\"modal\")\n\n    # Extract ID from standard video URL: /video/number\n    video_pattern = r'/video/(\\d+)'\n    match = re.search(video_pattern, url)\n    if match:\n        aweme_id = match.group(1)\n        return VideoUrlInfo(aweme_id=aweme_id, url_type=\"normal\")\n\n    raise ValueError(f\"Unable to parse video ID from URL: {url}\")\n\n\ndef parse_creator_info_from_url(url: str) -> CreatorUrlInfo:\n    \"\"\"\n    Parse creator ID (sec_user_id) from Douyin creator homepage URL\n    Supports the following formats:\n    1. Creator homepage: https://www.douyin.com/user/MS4wLjABAAAATJPY7LAlaa5X-c8uNdWkvz0jUGgpw4eeXIwu_8BhvqE?from_tab_name=main\n    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","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/NanmiCoder/MediaCrawler/blob/d6f7c5bb906b6dac40ddf343ef9e26438a3de092/media_platform/douyin/help.py#L120-L156","documentation":"ValueError from parse_video_info_from_url (media_platform/douyin/help.py) when the URL yields no extractable aweme id: the modal_id query param is absent AND the /video/(\\d+) regex does not match. The parser accepts modal_id links (note/search pages with modal_id) and standard /video/<digits> URLs; everything else — short links (v.douyin.com), live or note image URLs without modal_id, non-numeric ids — fails here.","triggerScenarios":"Passing a raw 'https://v.douyin.com/xxxx/' share short link that 302s to the real URL; a note page URL without a modal_id param; an empty string or a bare non-numeric id; URLs where the digits sit under a different path like /slide/.","commonSituations":"Users pasting the share-text link from the Douyin mobile app; crawling mixed feeds that include image notes and live links; upstream URL format changes adding new path shapes.","solutions":["Expand v.douyin.com short links (HTTP redirect) to the final www.douyin.com URL before parsing.","Pass the bare numeric aweme id or the canonical https://www.douyin.com/video/<id> URL.","Pre-filter URLs through a regex (/video/\\d+ or modal_id=) and skip/log non-matching ones in batch jobs."],"exampleFix":"# before\nparse_video_info_from_url('https://v.douyin.com/iAbCdEf/')\n\n# after\nresolved = await expand_short_link('https://v.douyin.com/iAbCdEf/')  # -> https://www.douyin.com/video/7525082444551310602\nparse_video_info_from_url(resolved)","handlingStrategy":"validation","validationCode":"import re\nDY_RE = re.compile(r'/video/\\d+')\ndef has_douyin_video_id(u: str) -> bool:\n    return bool(DY_RE.search(u)) or 'modal_id=' in u","typeGuard":"def is_parseable_dy_video(url: str) -> bool:\n    return bool(re.search(r'/video/\\d+', url)) or 'modal_id=' in url","tryCatchPattern":"try:\n    info = parse_video_info_from_url(url)\nexcept ValueError:\n    logger.warning(f'skipping unparseable douyin url: {url}')\n    continue","preventionTips":["Expand v.douyin.com short links via redirect before parsing","Pass bare numeric aweme ids when you have them","Pre-filter URLs in batch crawls to /video/\\d+ or modal_id forms"],"tags":["douyin","url-parsing","valueerror","short-link"],"backgroundTag":null,"analyzedSha":"d6f7c5bb906b6dac40ddf343ef9e26438a3de092","analyzedAt":"2026-08-15T01:39:07.505Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}