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

Code before:

        for entry in try_get(playlist, lambda x: x['videos']['nodes'], list):
            if entry.get('__typename') == 'Video':
                playlist_entries.append(self.url_result(entry.get('canonicalUrl'), self.ie_key()))

        return playlist_entries

    def _real_extract(self, url):
        m = re.match(self._VALID_URL, url, re.VERBOSE)
        if m.group('type').startswith('embed'):
            desktop_url = m.group('proto') + 'www' + m.group('urlmain')
            return self.url_result(desktop_url, 'TED')
        name = m.group('name')
        if m.group('type_talk'):
            return self._talk_info(url, name)
        elif m.group('type_playlist'):
            return self._playlist_videos_info(url, name)
        else:
            return self._series_videos_info(url, name, m.group('season'))

    def _playlist_videos_info(self, url, name):
        '''Returns the videos of the playlist'''
        webpage = self._download_webpage(url, name, 'Downloading playlist webpage')
        info = self._extract_info(webpage, 'json')

        playlist = try_get(info, lambda x: x['props']['pageProps']['playlist'], dict)
        playlist_id = playlist.get('id')
        playlist_entries = self._parse_playlist(playlist)

        return self.playlist_result(
            playlist_entries, playlist_id=playlist_id,
            playlist_title=playlist.get('title') or self._og_search_title(webpage, fatal=False).replace(' | TED Talks', ''),
            playlist_description=self._og_search_description(webpage))

    def _series_videos_info(self, url, name, season):
        '''Returns the videos of the series playlist'''
        webpage = self._download_webpage(url, name, 'Downloading series webpage')
        info = self._extract_info(webpage, 'json')
        series = try_get(info, lambda x: x['props']['pageProps']['series'])
        series_id = series.get('id')

        seasonlist = try_get(info, lambda x: x['props']['pageProps']['seasons'], list)

        playlist_entries = []
        if season:
            [playlist_entries.extend(self._parse_playlist(s)) for s in seasonlist if s.get('seasonNumber') == season]
        else:
            [playlist_entries.extend(self._parse_playlist(s)) for s in seasonlist]

        return self.playlist_result(
            playlist_entries, playlist_id=series_id,

Review comment (suggestion):
```suggestion
        playlist = try_get(info, lambda x: x['props']['pageProps']['playlist'], dict) or {}
```

Code after:
            return self.url_result(ext_url or external['uri'])

        self._sort_formats(formats)

        thumbnail = playerData.get('thumb') or self._og_search_property('image', webpage)
        if thumbnail:
            # trim thumbnail resize parameters
            thumbnail = thumbnail.split('?')[0]

        return {
            'id': video_id,
            'title': talk_info.get('title') or self._og_search_title(webpage),
            'uploader': talk_info.get('presenterDisplayName'),
            'thumbnail': thumbnail,
            'description': talk_info.get('description') or self._og_search_description(webpage),
            'subtitles': subtitles,
            'formats': formats,
            'duration': talk_info.get('duration') or parse_duration(self._og_search_property('video:duration', webpage)),
            'view_count': str_to_int(talk_info.get('viewedCount')),
            'upload_date': unified_strdate(talk_info.get('publishedAt')),
            'release_date': unified_strdate(talk_info.get('recordedOn')),
            'tags': try_get(playerData, lambda x: x['targeting']['tag'].split(',')),
        }


class TedSeriesIE(TedBaseIE):
    _VALID_URL = fr'{TedBaseIE._VALID_URL_BASE.format(type=r"series")}(?:#season_(?P<season>\d+))?'
    _TESTS = [{
        'url': 'https://www.ted.com/series/small_thing_big_idea',
        'info_dict': {
            'id': '3',
            'title': 'Small Thing Big Idea',
            'series': 'Small Thing Big Idea',
            'description': 'md5:6869ca52cec661aef72b3e9f7441c55c'
        },
        'playlist_mincount': 16,
    }, {
        'url': 'https://www.ted.com/series/the_way_we_work#season_2',
        'info_dict': {
            'id': '8_2',
            'title': 'The Way We Work Season 2',
            'series': 'The Way We Work',
            'description': 'md5:59469256e533e1a48c4aa926a382234c',
            'season_number': 2
        },
        'playlist_mincount': 8,
    }]

    def _real_extract(self, url):
        display_id, season = self._match_valid_url(url).group('id', 'season')
        webpage = self._download_webpage(url, display_id, 'Downloading series webpage')