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

Code before:
                'title': 'NEW: Makaya McCraven in La Rochelle',
                'thumbnail': r're:^https?://medicitv-[abc]\.imgix\.net/movie/[^?]+\.jpg(?:\?[^?]+)?',
                'description': 'md5:b5a8aaeb6993d8ccb18bde8abb8aa8d2',
                'upload_date': '20231228',
            },
        },
    ]

    def _real_extract(self, url):
        video_id = self._match_id(url)

        self._download_webpage(url, video_id)
        cookies = self._get_cookies(url)

        if 'edu' in url:
            request_url = f'https://api.medici.tv/edu-satie/edito/movie-file/{video_id}/'
            source_url = 'https://edu.medici.tv'
        else:
            request_url = f'https://api.medici.tv/satie/edito/movie-file/{video_id}/'
            source_url = 'https://www.medici.tv'

        mAuth_cookie = cookies.get('auth._token.mAuth')
        if not mAuth_cookie:
            token = ''
        else:
            token = unquote(str_or_none(mAuth_cookie.value, ''))

        data = self._download_json(
            request_url, video_id,
            headers={
                'Authorization': token,
                'Device-Type': 'web',
                'Origin': source_url,
                'Referer': source_url + '/',
                'Accept': 'application/json, text/plain, */*',
                'Accept-Language': 'en',
            }
        )

        id = str_or_none(data.get('id'))
        title = data.get('title')
        description = data.get('subtitle')
        is_free = bool_or_none(data.get('is_free'))
        is_full = traverse_obj(data, ('video', 'is_full_video'), expected_type=bool)
        m3u8_url = traverse_obj(data, ('video', 'video_url'), expected_type=str)

        if not is_full:
            if is_free:
                self.report_warning('You need an account. Only previews will be downloaded. If you have used the --cookies-from-browser option, try using the --cookies option.')
            else:
                self.report_warning('The full video is for subscribers only. Only previews will be downloaded. If you have used the --cookies-from-browser option, try using the --cookies option.')

Review comment (security):
import `try_call` from utils
```suggestion
        token = try_call(lambda: urllib.parse.unquote(self._get_cookies(url)['auth._token.mAuth'].value))
```

Code after:
    }, {
        'url': 'https://www.medici.tv/en/jazz/makaya-mccraven-la-rochelle',
        'md5': '4cc279a8b06609782747c8f50beea2b3',
        'info_dict': {
            'id': '7922',
            'ext': 'mp4',
            'title': 'NEW: Makaya McCraven in La Rochelle',
            'thumbnail': r're:https://.+/.+\.jpg',
            'description': 'md5:b5a8aaeb6993d8ccb18bde8abb8aa8d2',
            'upload_date': '20231228',
            'timestamp': 1703754863,
            'display_id': 'makaya-mccraven-la-rochelle',
        },
        'expected_warnings': [r'preview'],
    }]

    def _real_extract(self, url):
        display_id, subdomain = self._match_valid_url(url).group('id', 'sub')
        self._request_webpage(url, display_id, 'Requesting CSRF token cookie')

        subdomain = 'edu-' if subdomain == 'edu' else ''
        origin = f'https://{urllib.parse.urlparse(url).hostname}'

        data = self._download_json(
            f'https://api.medici.tv/{subdomain}satie/edito/movie-file/{display_id}/', display_id,
            headers=filter_dict({
                'Authorization': try_call(
                    lambda: urllib.parse.unquote(self._get_cookies(url)['auth._token.mAuth'].value)),
                'Device-Type': 'web',
                'Origin': origin,
                'Referer': f'{origin}/',
                'Accept': 'application/json, text/plain, */*',
            }))

        if not traverse_obj(data, ('video', 'is_full_video')) and traverse_obj(
                data, ('video', 'is_limited_by_user_access')):
            self.report_warning(
                'The full video is for subscribers only. Only previews will be downloaded. If you '
                'have used the --cookies-from-browser option, try using the --cookies option instead')

        formats, subtitles = self._extract_m3u8_formats_and_subtitles(
            data['video']['video_url'], display_id, 'mp4')

        return {
            'id': str(data['id']),
            'display_id': display_id,
            'formats': formats,
            'subtitles': subtitles,
            **traverse_obj(data, {
                'title': ('title', {str}),
                'description': ('subtitle', {str}),