Repository: yt-dlp/yt-dlp

Issue:
olympics.com not working any more
### Checklist

- [X] I'm reporting a broken site
- [X] I've verified that I'm running yt-dlp version **2021.10.22**. ([update instructions](https://github.com/yt-dlp/yt-dlp#update))
- [X] I've checked that all provided URLs are alive and playable in a browser
- [X] I've checked that all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/ytdl-org/youtube-dl#video-url-contains-an-ampersand-and-im-getting-some-strange-output-1-2839-or-v-is-not-recognized-as-an-internal-or-external-command)
- [X] I've searched the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues including closed ones. DO NOT post duplicates
- [X] I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
- [ ] I've read about [sharing account credentials](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#are-you-willing-to-share-account-details-if-needed) and I'm willing to share it if required

### Region

The Netherlands

### Description

Recently support [was added](https://github.com/yt-dlp/yt-dlp/pull/905) for olympics.com, but when I just tried, it gave an error:
`Unsupported URL`.
Am I missing something here?

Related: https://github.com/ytdl-org/youtube-dl/issues/30165

### Verbose log

```shell
yt-dlp -v https://olympics.com/fr/video/men-s-109kg-group-a-weightlifting-tokyo-2020-replays
[debug] Command-line config: ['-v', 'https://olympics.com/fr/video/men-s-109kg-group-a-weightlifting-tokyo-2020-replays']
[debug] User config file: /home/nico/.config/yt-dlp/config
[debug] User config: ['-o', '/dev/shm/test-dlp/%(title)s.%(ext)s', '-f', 'bestvideo[height<=1080][ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best', '--no-mtime', '--add-metadata', '--embed-thumbnail', '--force-ipv4', '--sponsorblock-remove', 'all', '--cookies-from-browser', 'firefox', '--user-agent', 'Mozilla/5.0 (X11; Linux x86_64; rv:93.0) Gecko/20100101 Firefox/93.0']
[Cookies] Extracting cookies from firefox
[debug] Extracting cookies from: "/home/nico/.mozilla/firefox/ivy4ozwp.default-release-1/cookies.sqlite"
[Cookies] Extracted 116 cookies from firefox
[debug] Encodings: locale UTF-8, fs utf-8, out UTF-8, err UTF-8, pref UTF-8
[debug] yt-dlp version 2021.10.24 (zip)
[debug] Python version 3.6.9 (CPython 64bit) - Linux-5.4.0-89-generic-x86_64-with-LinuxMint-19.3-tricia
[debug] exe versions: ffmpeg N-104315-g148ada5577-Nico-20211011-With-VP9-Timestamp-Fix, ffprobe N-104315-g148ada5577-Nico-20211011-With-VP9-Timestamp-Fix
[debug] Optional libraries: Cryptodome, keyring, mutagen, sqlite, websockets
[debug] Proxy map: {}
[debug] [generic] Extracting URL: https://olympics.com/fr/video/men-s-109kg-group-a-weightlifting-tokyo-2020-replays
[generic] men-s-109kg-group-a-weightlifting-tokyo-2020-replays: Requesting header
WARNING: [generic] Falling back on generic information extractor.
[generic] men-s-109kg-group-a-weightlifting-tokyo-2020-replays: Downloading webpage
[generic] men-s-109kg-group-a-weightlifting-tokyo-2020-replays: Extracting information
ERROR: [generic] Unsupported URL: https://olympics.com/fr/video/men-s-109kg-group-a-weightlifting-tokyo-2020-replays
Traceback (most recent call last):
  File "/usr/local/bin/dlp/yt_dlp/extractor/common.py", line 593, in extract
    ie_result = self._real_extract(url)
  File "/usr/local/bin/dlp/yt_dlp/extractor/generic.py", line 3706, in _real_extract
    raise UnsupportedError(url)
yt_dlp.utils.UnsupportedError: Unsupported URL: https://olympics.com/fr/video/men-s-109kg-group-a-weightlifting-tokyo-2020-replays
Traceback (most recent call last):
  File "/usr/local/bin/dlp/yt_dlp/extractor/common.py", line 593, in extract
    ie_result = self._real_extract(url)
  File "/usr/local/bin/dlp/yt_dlp/extractor/generic.py", line 3706, in _real_extract
    raise UnsupportedError(url)
yt_dlp.utils.UnsupportedError: Unsupported URL: https://olympics.com/fr/video/men-s-109kg-group-a-weightlifting-tokyo-2020-replays

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/dlp/yt_dlp/YoutubeDL.py", line 1311, in wrapper
    return func(self, *args, **kwargs)
  File "/usr/local/bin/dlp/yt_dlp/YoutubeDL.py", line 1336, in __extract_info
    ie_result = ie.extract(url)
  File "/usr/local/bin/dlp/yt_dlp/extractor/common.py", line 610, in extract
    e.msg, video_id=video_id, ie=self.IE_NAME, tb=e.traceback, expected=e.expected, cause=e.cause)
yt_dlp.utils.ExtractorError: [generic] Unsupported URL: https://olympics.com/fr/video/men-s-109kg-group-a-weightlifting-tokyo-2020-replays
```



Discussion:
Site changed the url.
most proly require a complete rework since the id is no longer in the url (ofc assuming it's using the same backend)

Resolving patch:
diff --git a/yt_dlp/extractor/olympics.py b/yt_dlp/extractor/olympics.py
--- a/yt_dlp/extractor/olympics.py
+++ b/yt_dlp/extractor/olympics.py
@@ -2,22 +2,27 @@
 from __future__ import unicode_literals
 
 from .common import InfoExtractor
-from ..utils import unified_strdate
+from ..utils import (
+    int_or_none,
+    try_get
+)
 
 
 class OlympicsReplayIE(InfoExtractor):
-    _VALID_URL = r'(?:https?://)(?:www\.)?olympics\.com/tokyo-2020/(?:[a-z]{2}/)?replay/(?P<id>[^/#&?]+)'
+    _VALID_URL = r'https?://(?:www\.)?olympics\.com(?:/tokyo-2020)?/[a-z]{2}/(?:replay|video)/(?P<id>[^/#&?]+)'
     _TESTS = [{
-        'url': 'https://olympics.com/tokyo-2020/en/replay/300622eb-abc0-43ea-b03b-c5f2d429ec7b/jumping-team-qualifier',
+        'url': 'https://olympics.com/fr/video/men-s-109kg-group-a-weightlifting-tokyo-2020-replays',
         'info_dict': {
-            'id': '300622eb-abc0-43ea-b03b-c5f2d429ec7b',
+            'id': 'f6a0753c-8e6f-4b7d-a435-027054a4f8e9',
             'ext': 'mp4',
-            'title': 'Jumping Team Qualifier',
-            'release_date': '20210806',
-            'upload_date': '20210713',
+            'title': '+109kg (H) Groupe A - Haltérophilie | Replay de Tokyo 2020',
+            'upload_date': '20210801',
+            'timestamp': 1627783200,
+            'description': 'md5:c66af4a5bc7429dbcc43d15845ff03b3',
         },
         'params': {
-            'format': 'bv',
+            'format': 'bestvideo',
+            'skip_download': True,
         },
     }, {
         'url': 'https://olympics.com/tokyo-2020/en/replay/bd242924-4b22-49a5-a846-f1d4c809250d/mens-bronze-medal-match-hun-esp',
@@ -26,31 +31,41 @@ class OlympicsReplayIE(InfoExtractor):
 
     def _real_extract(self, url):
         id = self._match_id(url)
-        # The parameters are hardcoded in the webpage, it's not necessary to download the webpage just for these parameters.
-        # If in downloading webpage serves other functions aswell, then extract these parameters from it.
-        token_url = 'https://appovptok.ovpobs.tv/api/identity/app/token?api_key=OTk5NDcxOjpvY3N3LWFwaXVzZXI%3D&api_secret=ODY4ODM2MjE3ODMwYmVjNTAxMWZlMDJiMTYxZmY0MjFiMjMwMjllMjJmNDA1YWRiYzA5ODcxYTZjZTljZDkxOTo6NTM2NWIzNjRlMTM1ZmI2YWNjNmYzMGMzOGM3NzZhZTY%3D'
-        token = self._download_webpage(token_url, id)
-        headers = {'x-obs-app-token': token}
-        data_json = self._download_json(f'https://appocswtok.ovpobs.tv/api/schedule-sessions/{id}?include=stream',
-                                        id, headers=headers)
-        meta_data = data_json['data']['attributes']
-        for t_dict in data_json['included']:
-            if t_dict.get('type') == 'Stream':
-                stream_data = t_dict['attributes']
+
+        webpage = self._download_webpage(url, id)
+        title = self._html_search_meta(('title', 'og:title', 'twitter:title'), webpage)
+        uuid = self._html_search_meta('episode_uid', webpage)
+        m3u8_url = self._html_search_meta('video_url', webpage)
+        json_ld = self._search_json_ld(webpage, uuid)
+        thumbnails_list = json_ld.get('image')
+        if not thumbnails_list:
+            thumbnails_list = self._html_search_regex(
+                r'["\']image["\']:\s*["\']([^"\']+)["\']', webpage, 'images', default='')
+            thumbnails_list = thumbnails_list.replace('[', '').replace(']', '').split(',')
+            thumbnails_list = [thumbnail.strip() for thumbnail in thumbnails_list]
+        thumbnails = []
+        for thumbnail in thumbnails_list:
+            width_a, height_a, width = self._search_regex(
+                r'/images/image/private/t_(?P<width_a>\d+)-(?P<height_a>\d+)_(?P<width>\d+)/primary/[\W\w\d]+',
+                thumbnail, 'thumb', group=(1, 2, 3), default=(None, None, None))
+            width_a, height_a, width = int_or_none(width_a), int_or_none(height_a), int_or_none(width)
+            thumbnails.append({
+                'url': thumbnail,
+                'width': width,
+                'height': int_or_none(try_get(width, lambda x: x * height_a / width_a))
+            })
         m3u8_url = self._download_json(
-            'https://meteringtok.ovpobs.tv/api/playback-sessions', id, headers=headers, query={
-                'alias': stream_data['alias'],
-                'stream': stream_data['stream'],
-                'type': 'vod'
-            })['data']['attributes']['url']
-        formats, subtitles = self._extract_m3u8_formats_and_subtitles(m3u8_url, id)
+            f'https://olympics.com/tokenGenerator?url={m3u8_url}', uuid, note='Downloading m3u8 url')
+        formats, subtitles = self._extract_m3u8_formats_and_subtitles(m3u8_url, uuid, m3u8_id='hls')
         self._sort_formats(formats)
 
         return {
-            'id': id,
-            'title': meta_data['title'],
-            'release_date': unified_strdate(meta_data.get('start') or meta_data.get('broadcastPublished')),
-            'upload_date': unified_strdate(meta_data.get('publishedAt')),
+            'id': uuid,
+            'title': title,
+            'timestamp': json_ld.get('timestamp'),
+            'description': json_ld.get('description'),
+            'thumbnails': thumbnails,
+            'duration': json_ld.get('duration'),
             'formats': formats,
             'subtitles': subtitles,
         }


Test patch: