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

Code before:
        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,
            series=series.get('name') or self._og_search_title(webpage, fatal=False),
            playlist_description=self._og_search_description(webpage),
            season_number=str_to_int(season))

    def _talk_info(self, url, video_name):
        webpage = self._download_webpage(url, video_name)
        info = self._extract_info(webpage, video_name)
        talk_info = try_get(info, lambda x: x['props']['pageProps']['videoData'], dict)

        video_id = talk_info.get('id')

        playerData = self._parse_json(talk_info.get('playerData'), video_id)
        resources_ = playerData.get('resources')

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

Code after:
            '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')
        info = self._search_nextjs_data(webpage, display_id)['props']['pageProps']

        entries = itertools.chain.from_iterable(
            self._parse_playlist(s) for s in info['seasons'] if season in [None, s.get('seasonNumber')])

        series_id = try_get(info, lambda x: x['series']['id'])
        series_name = try_get(info, lambda x: x['series']['name']) or self._og_search_title(webpage, fatal=False)

        return self.playlist_result(
            entries,
            f'{series_id}_{season}' if season and series_id else series_id,
            f'{series_name} Season {season}' if season else series_name,
            self._og_search_description(webpage),