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

Code before:

    def _real_extract(self, url):
        channel_id = self._match_id(url)
        params = parse_qs(url)
        media_id = traverse_obj(params, ('wmediaid', 0))
        if not self._yes_playlist(channel_id, media_id, playlist_label='channel'):
            return self.url_result(f'wistia:{media_id}', 'Wistia')

        try:
            data = self._download_embed_config('channel', channel_id, url)
        except (ExtractorError, urllib.error.HTTPError):
            # Some channels give a 403 from the JSON API
            self.report_warning('Failed to download channel data from API, falling back to webpage.')
            webpage = self._download_webpage(f'https://fast.wistia.net/embed/channel/{channel_id}', channel_id)
            data = self._parse_json(
                self._search_regex(r'wchanneljsonp-%s\'\]\s*=[^\"]*\"([A-Za-z0-9=/]*)' % channel_id, webpage, 'jsonp', channel_id),
                channel_id, transform_source=lambda x: urllib.parse.unquote_plus(b64decode(x).decode('utf-8')))

        # XXX: the response suggests there can be multiple "series" but I've never seen one
        series = traverse_obj(data, ('series', 0), default={})

        entries = []
        for video in traverse_obj(series, ('sections', ..., 'videos', ...)) or []:
            hashed_id = video.get('hashedId')
            if hashed_id:
                entries.append(self.url_result(f'wistia:{hashed_id}', 'Wistia', title=video.get('name')))

        return self.playlist_result(
            entries, channel_id, playlist_title=series.get('title'), playlist_description=series.get('description'))

    @classmethod
    def _extract_embed_urls(cls, url, webpage):
        yield from super()._extract_embed_urls(url, webpage)
        for match in cls._extract_wistia_async_embed(webpage):
            if match.group('type') == 'wistia_channel':
                # original url may contain wmediaid query param
                yield update_url_query(f'wistiachannel:{match.group("id")}', parse_qs(url))


Review comment (suggestion):
```suggestion
        entries = [
        	self.url_result(f'wistia:{video["hashedId"]}', WistiaIE, title=video.get('name'))
        	for video in traverse_obj(series, ('sections', ..., 'videos', ...)) or []
        	if video.get('hashedId')
        ]
```

Code after:
    }]
    _WEBPAGE_TESTS = [{
        'url': 'https://www.profitwell.com/recur/boxed-out',
        'info_dict': {
            'id': '6jyvmqz6zs',
            'title': 'Boxed Out',
            'description': 'md5:14a8a93a1dbe236718e6a59f8c8c7bae',
        },
        'playlist_mincount': 30,
    }, {
        # section instead of div
        'url': 'https://360learning.com/studio/onboarding-joei/',
        'info_dict': {
            'id': 'z874k93n2o',
            'title': 'Onboarding Joei.',
            'description': 'Coming to you weekly starting Feb 19th.',
        },
        'playlist_mincount': 20,
    }, {
        'url': 'https://amplitude.com/amplify-sessions?amp%5Bwmediaid%5D=pz0m0l0if3&amp%5Bwvideo%5D=pz0m0l0if3&wchannelid=emyjmwjf79&wmediaid=i8um783bdt',
        'info_dict': {
            'id': 'pz0m0l0if3',
            'title': 'A Framework for Improving Product Team Performance',
            'ext': 'bin',
            'timestamp': 1653935275,
            'upload_date': '20220530',
            'description': 'Learn how to help your company improve and achieve your product related goals.',
            'duration': 1854.39,
            'thumbnail': 'https://embed-ssl.wistia.com/deliveries/12fd19e56413d9d6f04e2185c16a6f8854e25226.bin',
        },
        'params': {'noplaylist': True, 'skip_download': True},
    }]

    def _real_extract(self, url):
        channel_id = self._match_id(url)
        media_id = self._extract_url_media_id(url)
        if not self._yes_playlist(channel_id, media_id, playlist_label='channel'):
            return self.url_result(f'wistia:{media_id}', 'Wistia')

        try:
            data = self._download_embed_config('channel', channel_id, url)
        except (ExtractorError, urllib.error.HTTPError):
            # Some channels give a 403 from the JSON API
            self.report_warning('Failed to download channel data from API, falling back to webpage.')
            webpage = self._download_webpage(f'https://fast.wistia.net/embed/channel/{channel_id}', channel_id)
            data = self._parse_json(
                self._search_regex(r'wchanneljsonp-%s\'\]\s*=[^\"]*\"([A-Za-z0-9=/]*)' % channel_id, webpage, 'jsonp', channel_id),
                channel_id, transform_source=lambda x: urllib.parse.unquote_plus(b64decode(x).decode('utf-8')))

        # XXX: can there be more than one series?
        series = traverse_obj(data, ('series', 0), default={})