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

Code before:
        if client not in self._CLIENT_CONFIGS:
            raise ExtractorError(
                f'Unsupported API client "{client}" requested. '
                f'Supported clients are: {", ".join(self._CLIENT_CONFIGS)}', expected=True)

        client_config = self._CLIENT_CONFIGS[client]
        if client_config['REQUIRES_AUTH'] and not self._get_cookies('https://vimeo.com').get('vimeo'):
            self.raise_login_required(f'The {client} client requires authentication')

        return self._download_json(
            join_nonempty(
                'https://api.vimeo.com/videos',
                join_nonempty(video_id, unlisted_hash, delim=':'),
                path, delim='/'),
            video_id, f'Downloading {client} API JSON', f'Unable to download {client} API JSON',
            headers=filter_dict({
                'Authorization': self._fetch_oauth_token(client),
                'User-Agent': client_config['USER_AGENT'],
                **self._CLIENT_HEADERS,
            }), query={
                'fields': ','.join(client_config['VIDEOS_FIELDS']),
                **(query or {}),
            }, **kwargs)

    def _extract_original_format(self, url, video_id, unlisted_hash=None):
        # Original/source formats are only available when logged in
        if not self._get_cookies('https://vimeo.com/').get('vimeo'):
            return

        query = {'action': 'load_download_config'}
        if unlisted_hash:
            query['unlisted_hash'] = unlisted_hash

        try:
            download_data = self._download_json(
                url, video_id, 'Loading download config JSON', query=query, headers={
                    'Accept': 'application/json',
                    'X-Requested-With': 'XMLHttpRequest',
                })
        except ExtractorError as error:
            self.write_debug(f'Unable to load download config JSON: {error.cause}')
            download_data = None

        source_file = traverse_obj(download_data, ('source_file', {dict})) or {}
        download_url = traverse_obj(source_file, ('download_url', {url_or_none}))
        if download_url and not source_file.get('is_cold') and not source_file.get('is_defrosting'):
            source_name = source_file.get('public_name', 'Original')
            if self._is_valid_url(download_url, video_id, f'{source_name} video'):
                ext = (try_get(
                    source_file, lambda x: x['extension'],
                    str) or determine_ext(

Review comment (refactor):
Is it reasonable to add a `force_extract` parameter here so that libraries can use that instead of supplying the configuration argument, just like with `force_client` on `_call_videos_api`?

Code after:
        client = force_client or self._configuration_arg('client', [self._DEFAULT_CLIENT], ie_key=VimeoIE)[0]
        if client not in self._CLIENT_CONFIGS:
            raise ExtractorError(
                f'Unsupported API client "{client}" requested. '
                f'Supported clients are: {", ".join(self._CLIENT_CONFIGS)}', expected=True)

        client_config = self._CLIENT_CONFIGS[client]
        if client_config['REQUIRES_AUTH'] and not self._get_cookies('https://vimeo.com').get('vimeo'):
            self.raise_login_required(f'The {client} client requires authentication')

        return self._download_json(
            join_nonempty(
                'https://api.vimeo.com/videos',
                join_nonempty(video_id, unlisted_hash, delim=':'),
                path, delim='/'),
            video_id, f'Downloading {client} API JSON', f'Unable to download {client} API JSON',
            headers=filter_dict({
                'Authorization': self._fetch_oauth_token(client),
                'User-Agent': client_config['USER_AGENT'],
                **self._CLIENT_HEADERS,
            }), query={
                'fields': ','.join(client_config['VIDEOS_FIELDS']),
                **(query or {}),
            }, **kwargs)

    def _extract_original_format(self, url, video_id, unlisted_hash=None):
        # Original/source formats are only available when logged in
        if not self._get_cookies('https://vimeo.com/').get('vimeo'):
            return None

        policy = self._configuration_arg('original_format_policy', ['auto'], ie_key=VimeoIE)[0]
        if policy == 'never':
            return None

        try:
            download_data = self._download_json(
                url, video_id, 'Loading download config JSON', query=filter_dict({
                    'action': 'load_download_config',
                    'unlisted_hash': unlisted_hash,
                }), headers={
                    'Accept': 'application/json',
                    'X-Requested-With': 'XMLHttpRequest',
                })
        except ExtractorError as error:
            self.write_debug(f'Unable to load download config JSON: {error.cause}')
            download_data = None

        source_file = traverse_obj(download_data, ('source_file', {dict})) or {}
        download_url = traverse_obj(source_file, ('download_url', {url_or_none}))
        if download_url and not source_file.get('is_cold') and not source_file.get('is_defrosting'):
            source_name = source_file.get('public_name', 'Original')