Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/bluesky.py (Python)

Code before:
            for reply in replies:
                yield from self.traverse_replies(reply, root_uri)
        if parent := thread_node.get('parent'):
            yield from self.traverse_replies(parent, root_uri)

    def get_service_endpoint(self, did, video_id):
        services = self._download_json(
            f'https://resolver.identity.foundation/1.0/identifiers/{did}',
            video_id, fatal=False).get('service') or []
        for service in services:
            if service.get('type') == 'AtprotoPersonalDataServer':
                return service.get('serviceEndpoint')
        return 'https://bsky.social'

    def _real_extract(self, url):
        handle, video_id = self._match_valid_url(url).groups()

        getcomments = self.get_param('getcomments', False)
        meta = self._download_json(
            'https://public.api.bsky.app/xrpc/app.bsky.feed.getPostThread',
            video_id, headers={'Content-Type': 'application/json'}, query={
                'uri': f'at://{handle}/app.bsky.feed.post/{video_id}',
                'depth': 1000 if getcomments else 0,
                'parentHeight': 1000 if getcomments else 0,
            })['thread']
        post = meta.get('post')

        did = traverse_obj(post, ('author', 'did'))
        record_embed = traverse_obj(post, ('record', 'embed', ('media', None)), get_all=False)
        post_type = record_embed.get('$type') if record_embed else None
        quoted_post = traverse_obj(post, ('embed', 'record', ('record', None)), get_all=False)
        quoted_type = traverse_obj(quoted_post, ('value', 'embed', ('media', None), '$type'), get_all=False)
        quoted_media = traverse_obj(quoted_post, ('embeds', 0, ('media', None)), get_all=False)

        if post_type == 'app.bsky.embed.external':
            return self.url_result(traverse_obj(
                post, ('embed', ('media', None), 'external', 'uri'), get_all=False)
                or traverse_obj(record_embed, ('external', 'uri')))
        elif post_type == 'app.bsky.embed.video':
            formats, subs = self._extract_m3u8_formats_and_subtitles(
                traverse_obj(post, ('embed', ('media', None), 'playlist'), get_all=False),
                video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False,
                note='Downloading m3u8 information', errnote='Unable to download m3u8 information')
            if blob_cid := traverse_obj(record_embed, ('video', 'ref', '$link'), ('video', 'cid')):
                endpoint = self.get_service_endpoint(did, video_id)
                formats.append({
                    'format_id': 'blob',
                    'url': f'{endpoint}/xrpc/com.atproto.sync.getBlob?did={did}&cid={blob_cid}',
                    **traverse_obj(record_embed, {
                        'ext': ('video', 'mimeType', {mimetype2ext}),
                        'width': ('aspectRatio', 'width', {int_or_none}),

Review comment (refactor):
With no comment extraction for now we could do:
```suggestion
        post = self._download_json(
            'https://public.api.bsky.app/xrpc/app.bsky.feed.getPostThread',
            video_id, headers={'Content-Type': 'application/json'}, query={
                'uri': f'at://{handle}/app.bsky.feed.post/{video_id}',
                'depth': 0,
                'parentHeight': 0,
            })['thread']['post']
```
Can be fatal for post here either way, since without the post we can't do anything.

Code after:
                'channel_url': 'https://bsky.app/profile/did:plc:bjh5ffwya5f53dfy47dezuwx',
                'like_count': int,
                'channel_id': 'did:plc:bjh5ffwya5f53dfy47dezuwx',
                'repost_count': int,
                'timestamp': 1729973202,
                'tags': [],
                'uploader_id': 'purpleicetea.bsky.social',
                'title': 'One of my favorite videos',
            },
        }, {
            'info_dict': {
                'id': '3l77u64l7le2e',
                'ext': 'mp4',
                'title': 'hearing people on twitter say that bluesky isn\'...',
                'like_count': int,
                'uploader_id': 'thafnine.net',
                'uploader_url': 'https://bsky.app/profile/thafnine.net',
                'upload_date': '20241024',
                'channel_url': 'https://bsky.app/profile/did:plc:6ttyq36rhiyed7wu3ws7dmqj',
                'description': r're:(?s)hearing people on twitter say that bluesky .{93}',
                'tags': [],
                'alt_title': 'md5:9b1ee1937fb3d1a81e932f9ec14d560e',
                'uploader': 'T9',
                'channel_id': 'did:plc:6ttyq36rhiyed7wu3ws7dmqj',
                'thumbnail': r're:https://video.bsky.app/watch/.*\.jpg$',
                'timestamp': 1729731642,
                'comment_count': int,
                'repost_count': int,
            },
        }],
    }]
    _BLOB_URL_TMPL = '{}/xrpc/com.atproto.sync.getBlob'

    def _get_service_endpoint(self, did, video_id):
        if did.startswith('did:web:'):
            url = f'https://{did[8:]}/.well-known/did.json'
        else:
            url = f'https://plc.directory/{did}'
        services = self._download_json(
            url, video_id, 'Fetching service endpoint', 'Falling back to bsky.social', fatal=False)
        return traverse_obj(
            services, ('service', lambda _, x: x['type'] == 'AtprotoPersonalDataServer',
                       'serviceEndpoint', {url_or_none}, any)) or 'https://bsky.social'

    def _real_extract(self, url):
        handle, video_id = self._match_valid_url(url).group('handle', 'id')

        post = self._download_json(
            'https://public.api.bsky.app/xrpc/app.bsky.feed.getPostThread',
            video_id, query={
                'uri': f'at://{handle}/app.bsky.feed.post/{video_id}',