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

Code before:
    }, {
        'url': 'https://www.yfanefa.com/evaluating_nature_matters',
        'info_dict': {
            'id': 'evaluating_nature_matters',
            'ext': 'mp4',
            'title': 'Evaluating Nature Matters',
        },
        'params': {'skip_download': True},
    }]

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

        webpage = self._download_webpage(url, video_id)
        title = self._og_search_title(webpage) or self._html_extract_title(webpage)

        player_match = re.search(r'iwPlayer\.options\[[^\]]+\]\s*=\s*({.*?});', webpage, re.DOTALL)
        if not player_match:
            raise ExtractorError('Could not find player configuration')

        config_str = player_match.group(1).replace('\\/', '/')
        url_match = re.search(r'"url":"(https://media\.yfanefa\.com/storage/v1/(?:hls|file)/[^"]+)"', config_str)
        sig_match = re.search(r'"signature":"(\?[^"]*)"', config_str)

        if not url_match:
            raise ExtractorError('Could not extract video URL')

        m3u8_url = url_match.group(1)

        if sig_match and sig_match.group(1):
            signature = sig_match.group(1)
            if signature and not signature.startswith('?'):
                signature = '?' + signature
            m3u8_url += signature

        m3u8_url = m3u8_url.replace('\\', '')

        if m3u8_url.endswith('.m3u8'):
            formats = self._extract_m3u8_formats(m3u8_url, video_id, 'mp4', m3u8_id='hls')
        else:
            formats = [{
                'url': m3u8_url,
                'ext': 'mp4',
            }]

        return {
            'id': video_id,
            'title': title,
            'formats': formats,
            'http_headers': {'Referer': url},
        }

Review comment (refactor):
Let's use the _search_json helper instead and extract the entire set of player options
```suggestion
        player_data = self._search_json(
            r'iwPlayer\.options\["[\w.]+"\]\s*=', webpage, 'player options', video_id)
```

Code after:
            'title': 'Memory Bank:  Bradford Launch',
            'thumbnail': r're:https://media\.yfanefa\.com/storage/v1/file/',
        },
    }, {
        'url': 'https://www.yfanefa.com/evaluating_nature_matters',
        'info_dict': {
            'id': 'evaluating_nature_matters',
            'ext': 'mp4',
            'title': 'Evaluating Nature Matters',
            'thumbnail': r're:https://media\.yfanefa\.com/storage/v1/file/',
        },
    }]

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

        webpage = self._download_webpage(url, video_id)
        player_data = self._search_json(
            r'iwPlayer\.options\["[\w.]+"\]\s*=', webpage, 'player options', video_id)

        formats = []
        video_url = join_nonempty(player_data['url'], player_data.get('signature'), delim='')
        if determine_ext(video_url) == 'm3u8':
            formats = self._extract_m3u8_formats(
                video_url, video_id, 'mp4', m3u8_id='hls')
        else:
            formats = [{'url': video_url, 'ext': 'mp4'}]

        return {
            'id': video_id.strip('/').replace('/', '-'),
            'title':
                self._og_search_title(webpage, default=None)
                or remove_end(self._html_extract_title(webpage), ' | Yorkshire Film Archive'),
            'formats': formats,
            **traverse_obj(player_data, {
                'thumbnail': ('preview', {url_or_none}),
                'duration': ('duration', {int_or_none}),
            }),
        }