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

Code before:
            # If there's only one item, use it as the main info dict
            only_video = entries[list(entries.keys())[0]]
            if entry_id:
                info = merge_dicts(only_video, info)
            else:
                info = merge_dicts(info, only_video)
        else:
            # Otherwise, we have a playlist.
            info['_type'] = 'playlist'
            info['entries'] = list(entries.values())

        if metadata.get('reviews'):
            info['comments'] = []
            for review in metadata['reviews']:
                info['comments'].append({
                    'id': review.get('review_id'),
                    'author': review.get('reviewer'),
                    'text': str_or_none(review.get('reviewtitle'), '') + '\n\n' + review.get('reviewbody'),
                    'timestamp': unified_timestamp(review.get('createdate')),
                    'parent': 'root'})

        return info


class YoutubeWebArchiveIE(InfoExtractor):
    IE_NAME = 'youtube:web.archive.org'
    IE_DESC = 'web.archive.org saved youtube videos'
    _VALID_URL = r"""(?x)^
                (?:https?://|//)?web\.archive\.org\/
                    (?:web/)?
                    (?:[0-9A-Za-z_*]+/)? # /web and the version index is optional
                (?:https?:\/\/)?
                (?:
                    (?:\w+\.)?youtube\.com\/watch\?v= # Youtube URL
                    |(wayback-fakeurl\.archive\.org\/yt\/) # Or optionally, also support the internal fake url
                )
                (?P<id>[0-9A-Za-z_-]{11})(?(1).+)?(?:\#|&|$)
                """

    _INTERNAL_URL_TEMPLATE = "https://web.archive.org/web/2oe_/http://wayback-fakeurl.archive.org/yt/%s"

    _TESTS = [
        {
            'url': 'https://web.archive.org/web/20150415002341/https://www.youtube.com/watch?v=aYAGB11YrSs',
            'info_dict': {
                'id': 'aYAGB11YrSs',
                'ext': 'webm',
                'title': 'Unknown Video'
            }
        },
        {

Review comment (suggestion):
should probably be `archive.org:something` (is web.archive.org and www.archive.org different things?)

Code after:
        for entry in entries.values():
            entry['formats'] = list(sorted(entry['formats'], key=lambda x: x.get('filesize', -1)))

        if len(entries) == 1:
            # If there's only one item, use it as the main info dict
            only_video = entries[list(entries.keys())[0]]
            if entry_id:
                info = merge_dicts(only_video, info)
            else:
                info = merge_dicts(info, only_video)
        else:
            # Otherwise, we have a playlist.
            info['_type'] = 'playlist'
            info['entries'] = list(entries.values())

        if metadata.get('reviews'):
            info['comments'] = []
            for review in metadata['reviews']:
                info['comments'].append({
                    'id': review.get('review_id'),
                    'author': review.get('reviewer'),
                    'text': str_or_none(review.get('reviewtitle'), '') + '\n\n' + review.get('reviewbody'),
                    'timestamp': unified_timestamp(review.get('createdate')),
                    'parent': 'root'})

        return info


class YoutubeWebArchiveIE(InfoExtractor):
    IE_NAME = 'web.archive:youtube'
    IE_DESC = 'web.archive.org saved youtube videos'
    _VALID_URL = r"""(?x)^
                (?:https?://)?web\.archive\.org/
                    (?:web/)?
                    (?:[0-9A-Za-z_*]+/)?  # /web and the version index is optional

                (?:https?(?::|%3[Aa])//)?
                (?:
                    (?:\w+\.)?youtube\.com/watch(?:\?|%3[fF])(?:[^\#]+(?:&|%26))?v(?:=|%3[dD])  # Youtube URL
                    |(wayback-fakeurl\.archive\.org/yt/)  # Or the internal fake url
                )
                (?P<id>[0-9A-Za-z_-]{11})(?:%26|\#|&|$)
                """

    _TESTS = [
        {
            'url': 'https://web.archive.org/web/20150415002341/https://www.youtube.com/watch?v=aYAGB11YrSs',
            'info_dict': {
                'id': 'aYAGB11YrSs',
                'ext': 'webm',
                'title': 'Team Fortress 2 - Sandviches!'