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

Code before:
    def traverse_replies(self, thread_node, root_uri):
        post_uri = traverse_obj(thread_node, ('post', 'uri'))
        if post_uri != root_uri:
            post = thread_node.get('post')
            parent_uri = traverse_obj(post, ('record', 'reply', 'parent', 'uri'))
            author_handle = traverse_obj(post, ('author', 'handle'))
            author_did = traverse_obj(post, ('author', 'did'), default='')
            yield {
                'id': post_uri,
                **traverse_obj(post, {
                    'text': ('record', 'text'),
                    'timestamp': ('record', 'createdAt', {parse_iso8601}),
                    'author': ('author', 'displayName'),
                    'author_thumbnail': ('author', 'avatar', {url_or_none}),
                }),
                'parent': 'root' if parent_uri == root_uri else parent_uri,
                'like_count': post.get('likeCount'),
                'author_id': author_did,
                'author_url': f'https://bsky.app/profile/{author_handle}',
                'author_is_uploader': author_did in root_uri,
            }
        if replies := thread_node.get('replies'):
            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)

Review comment (refactor):
Would you mind creating a separate PR for the comment extraction code?
I would like to include this extractor in the next release scheduled for this weekend, and this will require some more thought from our side.

Code after:
            'upload_date': '20241021',
            'timestamp': 1729523172,
            'like_count': int,
            'repost_count': int,
            'comment_count': int,
            'tags': [],
        },
    }, {
        'url': 'https://bsky.app/profile/purpleicetea.bsky.social/post/3l7gv55dc2o2w',
        'info_dict': {
            'id': '3l7gv55dc2o2w',
        },
        'playlist': [{
            'info_dict': {
                'id': '3l7gv55dc2o2w',
                'ext': 'mp4',
                'upload_date': '20241026',
                'description': 'One of my favorite videos',
                'comment_count': int,
                'uploader_url': 'https://bsky.app/profile/purpleicetea.bsky.social',
                'uploader': 'Purple.Ice.Tea',
                'thumbnail': r're:https://video.bsky.app/watch/.*\.jpg$',
                '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,
            },