Repository: yt-dlp/yt-dlp
File: yt_dlp/downloader/youtube_live_chat.py (Python)

Code before:
                or try_get(item, lambda x: x['liveChatPaidStickerRenderer'], dict)
                # ticker
                or try_get(item, lambda x: x['liveChatTickerPaidMessageItemRenderer'], dict)
                or try_get(item, lambda x: x['liveChatTickerSponsorItemRenderer'], dict)
                # banner
                or try_get(item, lambda x: x['liveChatBannerRenderer'], dict)
            )
            if renderer is None:
                return None
            parent_item = (
                try_get(
                    renderer,
                    lambda x: x['showItemEndpoint']['showLiveChatItemEndpoint']['renderer'], dict)
                or try_get(renderer, lambda x: x['contents'], dict)
            )
            if parent_item:
                renderer = (
                    try_get(parent_item, lambda x: x['liveChatTextMessageRenderer'], dict)
                    or try_get(parent_item, lambda x: x['liveChatPaidMessageRenderer'], dict)
                    or try_get(parent_item, lambda x: x['liveChatMembershipItemRenderer'], dict)
                    or try_get(parent_item, lambda x: x['liveChatPaidStickerRenderer'], dict)
                )
            if renderer:
                timestamp_usec = try_get(renderer, lambda x: x['timestampUsec'], str)
                if timestamp_usec:
                    return int(int(timestamp_usec) / 1000)
            return None

        live_offset = [0]  # Python 2 doesnot support nonlocal

        def parse_actions_live(live_chat_continuation):
            continuation_id = None
            processed_fragment = bytearray()
            for action in live_chat_continuation.get('actions', []):
                timestamp = parse_live_timestamp(action)
                if timestamp is not None:
                    live_offset[0] = timestamp - start_time
                # compatibility with replay format
                pseudo_action = {
                    'replayChatItemAction': {'actions': [action]},
                    'videoOffsetTimeMsec': str(live_offset[0]),
                    'isLive': True,
                }
                processed_fragment.extend(
                    json.dumps(pseudo_action, ensure_ascii=False).encode('utf-8') + b'\n')
            continuation_data = (
                try_get(
                    live_chat_continuation,
                    lambda x: x['continuations'][0]['invalidationContinuationData'], dict)
                or try_get(
                    live_chat_continuation,

Review comment (suggestion):
```suggestion
                timestamp_usec = int_or_none(try_get(renderer, lambda x: x['timestampUsec'], str), 1000)
```

Code after:
                    json.dumps(pseudo_action, ensure_ascii=False).encode('utf-8') + b'\n')
            continuation_data_getters = [
                lambda x: x['continuations'][0]['invalidationContinuationData'],
                lambda x: x['continuations'][0]['timedContinuationData'],
            ]
            continuation_data = try_get(live_chat_continuation, continuation_data_getters, dict)
            if continuation_data:
                continuation_id = continuation_data.get('continuation')
                timeout_ms = int_or_none(continuation_data.get('timeoutMs'))
                if timeout_ms is not None:
                    time.sleep(timeout_ms / 1000)
            self._append_fragment(ctx, processed_fragment)
            return continuation_id, live_offset

        if info_dict['protocol'] == 'youtube_live_chat_replay':
            parse_actions = parse_actions_replay
        elif info_dict['protocol'] == 'youtube_live_chat':
            parse_actions = parse_actions_live

        def download_and_parse_fragment(url, frag_index, request_data, headers):
            count = 0
            while count <= fragment_retries:
                try:
                    success, raw_fragment = dl_fragment(url, request_data, headers)
                    if not success:
                        return False, None, None
                    data = json.loads(raw_fragment)
                    live_chat_continuation = try_get(
                        data,
                        lambda x: x['continuationContents']['liveChatContinuation'], dict) or {}
                    continuation_id, offset = parse_actions(live_chat_continuation)
                    return True, continuation_id, offset
                except compat_urllib_error.HTTPError as err:
                    count += 1
                    if count <= fragment_retries:
                        self.report_retry_fragment(err, frag_index, count, fragment_retries)
            if count > fragment_retries:
                self.report_error('giving up after %s fragment retries' % fragment_retries)
                return False, None, None

        self._prepare_and_start_frag_download(ctx)

        success, raw_fragment = dl_fragment(info_dict['url'])
        if not success:
            return False
        try:
            data = ie._extract_yt_initial_data(video_id, raw_fragment.decode('utf-8', 'replace'))
        except RegexNotFoundError:
            return False
        continuation_id = try_get(
            data,