{"record":{"id":"6006fa2f4176416f","repo":"ytdl-org/youtube-dl","slug":"unable-to-extract-moment-id","errorCode":null,"errorMessage":"Unable to extract moment id","messagePattern":"Unable to extract moment id","errorType":"exception","errorClass":"ExtractorError","httpStatus":null,"severity":"error","filePath":"youtube_dl/extractor/younow.py","lineNumber":85,"sourceCode":"            'uploader_url': 'https://www.younow.com/%s' % username,\n            'creator': uploader,\n            'view_count': int_or_none(data.get('viewers')),\n            'like_count': int_or_none(data.get('likes')),\n            'formats': [{\n                'url': '%s/broadcast/videoPath/hls=1/broadcastId=%s/channelId=%s'\n                       % (CDN_API_BASE, data['broadcastId'], data['userId']),\n                'ext': 'mp4',\n                'protocol': 'm3u8',\n            }],\n        }\n\n\ndef _extract_moment(item, fatal=True):\n    moment_id = item.get('momentId')\n    if not moment_id:\n        if not fatal:\n            return\n        raise ExtractorError('Unable to extract moment id')\n\n    moment_id = compat_str(moment_id)\n\n    title = item.get('text')\n    if not title:\n        title = 'YouNow %s' % (\n            item.get('momentType') or item.get('titleType') or 'moment')\n\n    uploader = try_get(item, lambda x: x['owner']['name'], compat_str)\n    uploader_id = try_get(item, lambda x: x['owner']['userId'])\n    uploader_url = 'https://www.younow.com/%s' % uploader if uploader else None\n\n    entry = {\n        'extractor_key': 'YouNowMoment',\n        'id': moment_id,\n        'title': title,\n        'view_count': int_or_none(item.get('views')),\n        'like_count': int_or_none(item.get('likes')),","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/ytdl-org/youtube-dl/blob/956b8c585591b401a543e409accb163eeaaa1193/youtube_dl/extractor/younow.py#L67-L103","documentation":"Raised inside _extract_moment (younow.py) when a moment item from the YouNow moments API has a falsy 'momentId' field and the fatal flag is True. Moments are short clips; without a momentId there is nothing to construct a URL from, so extraction cannot proceed. Callers that pass fatal=False get None back instead of the exception.","triggerScenarios":"Iterating channel moments where an entry in the API response lacks 'momentId' (deleted moments, placeholder entries, API schema drift) while calling _extract_moment with the default fatal=True.","commonSituations":"Channel scrape hit a moment deleted between listing and extraction; YouNow changed the field name (e.g. to 'momentId' vs an id nested object); processing raw API JSON that mixes non-moment entries into the items array.","solutions":["Inspect the failing item dict (log item.keys()) and confirm whether 'momentId' exists under a different key or nesting.","If some items legitimately lack the id, call _extract_moment(item, fatal=False) so they are skipped instead of aborting the batch.","Pre-filter the items list before extraction: keep only entries with a truthy 'momentId'.","If the field was renamed by the API, update item.get('momentId') to the new key in younow.py."],"exampleFix":"// before\nentries = [_extract_moment(item) for item in items]\n\n// after\nentries = [_extract_moment(item, fatal=False) for item in items]\nentries = [e for e in entries if e]","handlingStrategy":"validation","validationCode":"def moment_items_valid(items) -> bool:\n    return all(item.get('momentId') for item in items)","typeGuard":"def is_valid_moment(item: dict) -> bool:\n    return isinstance(item, dict) and bool(item.get('momentId'))","tryCatchPattern":"try:\n    entry = _extract_moment(item)\nexcept ExtractorError as e:\n    if 'Unable to extract moment id' in str(e):\n        continue  # skip malformed/deleted moment in a batch\n    raise","preventionTips":["Filter items on a truthy 'momentId' before batch extraction.","Use the fatal=False parameter offered by _extract_moment instead of hand-rolling catches."],"tags":["younow","moments","missing-field","data-validation"],"backgroundTag":null,"analyzedSha":"956b8c585591b401a543e409accb163eeaaa1193","analyzedAt":"2026-08-14T18:59:47.863Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}