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

Code before:
class TheHighWireIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?thehighwire\.com/ark-videos/(?P<id>[^/?#]+)'
    _EMBED_URL = 'https://app.arkengine.com/embed/{id}'
    _TESTS = [{
        'url': 'https://thehighwire.com/ark-videos/the-deposition-of-stanley-plotkin/',
        'info_dict': {
            'id': 'clllgcra301z4ik01x8cwhfu2',
            'title': 'THE DEPOSITION OF STANLEY PLOTKIN',
            'ext': 'mp4',
        },
        'params': {'skip_download': True},
    }]

    def _real_extract(self, url):
        display_id = self._match_id(url)
        webpage = self._download_webpage(url, display_id)

        iframe_url = self._search_regex(
            r'<iframe[^>]+src=["\'](https?://app\.arkengine\.com/embed/[^"\']+)',
            webpage, 'iframe URL')
        video_id = self._search_regex(
            r'embed/([a-zA-Z0-9]+)', iframe_url, 'video ID')

        player_page = self._download_webpage(
            self._EMBED_URL.format(id=video_id), video_id,
            note='Downloading player page')

        m3u8_url = self._search_regex(
            r'<source[^>]+src=["\']([^"\']+\.m3u8)',
            player_page, 'm3u8 URL')

        title = self._og_search_title(webpage, default=None) or self._html_search_meta(
            'og:title', webpage, 'title', default=video_id)

        return {
            'id': video_id,
            'display_id': display_id,
            'title': title,
            'formats': self._extract_m3u8_formats(m3u8_url, video_id, 'mp4'),
        }


Review comment (refactor):
more simply
```suggestion
        embed_url = traverse_obj(webpage, (
            {find_element(cls='ark-video-embed', html=True)},
            {extract_attributes}, 'src', {url_or_none}, {require('embed URL')}))
        embed_page = self._download_webpage(embed_url, display_id)
```

Code after:
    clean_html,
    extract_attributes,
    url_or_none,
)
from ..utils.traversal import (
    find_element,
    require,
    traverse_obj,
)


class TheHighWireIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?thehighwire\.com/ark-videos/(?P<id>[^/?#]+)'
    _TESTS = [{
        'url': 'https://thehighwire.com/ark-videos/the-deposition-of-stanley-plotkin/',
        'info_dict': {
            'id': 'the-deposition-of-stanley-plotkin',
            'ext': 'mp4',
            'title': 'THE DEPOSITION OF STANLEY PLOTKIN',
            'description': 'md5:6d0be4f1181daaa10430fd8b945a5e54',
            'thumbnail': r're:https?://static\.arkengine\.com/video/.+\.jpg',
        },
    }]

    def _real_extract(self, url):
        display_id = self._match_id(url)
        webpage = self._download_webpage(url, display_id)

        embed_url = traverse_obj(webpage, (
            {find_element(cls='ark-video-embed', html=True)},
            {extract_attributes}, 'src', {url_or_none}, {require('embed URL')}))
        embed_page = self._download_webpage(embed_url, display_id)

        return {
            'id': display_id,
            **traverse_obj(webpage, {
                'title': ({find_element(cls='section-header')}, {clean_html}),
                'description': ({find_element(cls='episode-description__copy')}, {clean_html}),
            }),
            **self._parse_html5_media_entries(embed_url, embed_page, display_id, m3u8_id='hls')[0],
        }