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

Code before:
        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})(?:\#|&|$)
                """

    _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!'
            }
        },
        {
            # Internal link
            'url': 'https://web.archive.org/web/2oe/http://wayback-fakeurl.archive.org/yt/97t7Xj_iBv0',
            'info_dict': {
                'id': '97t7Xj_iBv0',
                'ext': 'mp4',
                'title': 'How Flexible Machines Could Save The World'
            }
        },
        {
            # Video from 2012, webm format itag 45.
            'url': 'https://web.archive.org/web/20120712231619/http://www.youtube.com/watch?v=AkhihxRKcrs&gl=US&hl=en',
            'info_dict': {
                'id': 'AkhihxRKcrs',

Review comment (suggestion):
```suggestion

                (?: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|\#|&|$)
```

Here are a few test cases:
```
https://web.archive.org/web/20120712231619/http://www.youtube.com/watch?gl=US&v=AkhihxRKcrs&hl=en
https://web.archive.org/web/20120712231619/http%3A//www.youtube.com/watch%3Fv%3DAkhihxRKcrs%26gl%3DUS%26hl%3Den
https://web.archive.org/web/20120712231619/http%3A//www.youtube.com/watch%3Fgl%3DUS%26v%3DAkhihxRKcrs%26hl%3Den
```

Code after:
            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!'
            }
        },
        {
            # Internal link
            'url': 'https://web.archive.org/web/2oe/http://wayback-fakeurl.archive.org/yt/97t7Xj_iBv0',
            'info_dict': {
                'id': '97t7Xj_iBv0',
                'ext': 'mp4',
                'title': 'How Flexible Machines Could Save The World'
            }
        },
        {
            # Video from 2012, webm format itag 45.
            'url': 'https://web.archive.org/web/20120712231619/http://www.youtube.com/watch?v=AkhihxRKcrs&gl=US&hl=en',
            'info_dict': {
                'id': 'AkhihxRKcrs',