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

Code before:
        },
    }, {
        # iframe embed
        'url': 'http://www.ceskatelevize.cz/porady/10614999031-neviditelni/21251212048/',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        playlist_id = self._match_id(url)
        parsed_url = compat_urllib_parse_urlparse(url)
        webpage = self._download_webpage(url, playlist_id)
        site_name = self._og_search_property('site_name', webpage, fatal=False, default=None)
        playlist_title = self._og_search_title(webpage, default=None)
        if site_name and playlist_title:
            playlist_title = playlist_title.replace(f' — {site_name}', '', 1)
        playlist_description = self._og_search_description(webpage, default=None)
        if playlist_description:
            playlist_description = playlist_description.replace('\xa0', ' ')

        if parsed_url.path.startswith('/porady/'):
            next_data = self._parse_json(unescapeHTML(self._search_regex(r'<script[^>]+id=[\'"]__NEXT_DATA__[\'"][^>]+>([^<]*)</script>', webpage, 'IDEC id', playlist_id)), playlist_id)
            idec = traverse_obj(next_data, ('props', 'pageProps', 'data', 'show', 'idec')) or traverse_obj(next_data, ('props', 'pageProps', 'data', 'mediaMeta', 'idec'))
            if not idec:
                raise ExtractorError('Failed to find IDEC id')
            webpage = self._download_webpage(self._IFRAME_HASH_URL, playlist_id)
            webpage = self._download_webpage(self._IFRAME_URL, playlist_id, query={'hash': webpage, 'origin': 'iVysilani', 'autoStart': 'true', 'IDEC': idec})

        NOT_AVAILABLE_STRING = 'This content is not available at your territory due to limited copyright.'
        if '%s</p>' % NOT_AVAILABLE_STRING in webpage:
            raise ExtractorError(NOT_AVAILABLE_STRING, expected=True)

        type_ = None
        episode_id = None

        playlist = self._parse_json(
            self._search_regex(
                r'getPlaylistUrl\(\[({.+?})\]', webpage, 'playlist',
                default='{}'), playlist_id)
        if playlist:
            type_ = playlist.get('type')
            episode_id = playlist.get('id')

        if not type_:
            type_ = self._html_search_regex(
                r'getPlaylistUrl\(\[\{"type":"(.+?)","id":".+?"\}\],',
                webpage, 'type')
        if not episode_id:
            episode_id = self._html_search_regex(
                r'getPlaylistUrl\(\[\{"type":".+?","id":"(.+?)"\}\],',
                webpage, 'episode_id')


Review comment (suggestion):
```suggestion
            hash = self._download_webpage(self._IFRAME_HASH_URL, playlist_id)
            webpage = self._download_webpage(self._IFRAME_URL, playlist_id, query={'hash': hash, 'origin': 'iVysilani', 'autoStart': 'true', 'IDEC': idec})
```

Also, since `_IFRAME_HASH_URL` and `_IFRAME_URL` are only ever used here, just hard-code it here, not as class vars

Code after:
        'url': 'http://www.ceskatelevize.cz/porady/10614999031-neviditelni/21251212048/',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        playlist_id = self._match_id(url)
        parsed_url = compat_urllib_parse_urlparse(url)
        webpage = self._download_webpage(url, playlist_id)
        site_name = self._og_search_property('site_name', webpage, fatal=False, default=None)
        playlist_title = self._og_search_title(webpage, default=None)
        if site_name and playlist_title:
            playlist_title = playlist_title.replace(f' — {site_name}', '', 1)
        playlist_description = self._og_search_description(webpage, default=None)
        if playlist_description:
            playlist_description = playlist_description.replace('\xa0', ' ')

        if parsed_url.path.startswith('/porady/'):
            next_data = self._search_nextjs_data(webpage, playlist_id)
            idec = traverse_obj(next_data, ('props', 'pageProps', 'data', ('show', 'mediaMeta'), 'idec'), get_all=False)
            if not idec:
                raise ExtractorError('Failed to find IDEC id')
            iframe_hash = self._download_webpage('https://www.ceskatelevize.cz/v-api/iframe-hash/', playlist_id)
            webpage = self._download_webpage('https://www.ceskatelevize.cz/ivysilani/embed/iFramePlayer.php', playlist_id,
                                             query={'hash': iframe_hash, 'origin': 'iVysilani', 'autoStart': 'true', 'IDEC': idec})

        NOT_AVAILABLE_STRING = 'This content is not available at your territory due to limited copyright.'
        if '%s</p>' % NOT_AVAILABLE_STRING in webpage:
            raise ExtractorError(NOT_AVAILABLE_STRING, expected=True)

        type_ = None
        episode_id = None

        playlist = self._parse_json(
            self._search_regex(
                r'getPlaylistUrl\(\[({.+?})\]', webpage, 'playlist',
                default='{}'), playlist_id)
        if playlist:
            type_ = playlist.get('type')
            episode_id = playlist.get('id')

        if not type_:
            type_ = self._html_search_regex(
                r'getPlaylistUrl\(\[\{"type":"(.+?)","id":".+?"\}\],',
                webpage, 'type')
        if not episode_id:
            episode_id = self._html_search_regex(
                r'getPlaylistUrl\(\[\{"type":".+?","id":"(.+?)"\}\],',
                webpage, 'episode_id')

        data = {
            'playlist[0][type]': type_,