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

Code before:
    def _fetch_jwt(self, webpage):
        return self._search_regex(r'{"passedToken":"([A-Za-z0-9-_]*\.[A-Za-z0-9-_]*\.[A-Za-z0-9-_]+)",', webpage, 'jwt')

    def _check_if_logged_in(self, webpage):
        if '{ member: null' in webpage:
            raise self.raise_login_required(method='cookies')

    def _real_extract(self, url):
        QUALITIES = qualities(['low', 'medium', 'high', 'veryhigh'])

        episode_id = self._match_id(url)
        webpage = self._download_webpage(url, episode_id)
        self._check_if_logged_in(webpage)

        course_name = re.match(r'https?://.*/course/(?P<course_name>[0-9a-z-]+)/.*', url).group(1)
        course_api = self._get_course_api_json(webpage, course_name)
        course = course_api['course']

        episode_api = self._get_episode_api_json(webpage, episode_id)
        episode = episode_api['episode']

        for i in range(len(course.get('topics'))):
            if traverse_obj(course, ('topics', i, 'id'), expected_type=str) == episode.get('topic'):
                chapter_name = traverse_obj(course, ('topics', i, 'title'), expected_type=str)
                chapter_id = traverse_obj(course, ('topics', i, 'id'), expected_type=str)
                chapter_number = i + 1

        return {
            'id': episode_id,
            'title': episode['title'],
            'description': episode.get('description'),
            'thumbnail': episode.get('thumbnail'),
            'formats': [
                {'url': episode.get('jwVideo320Embed'), 'height': 320, 'quality': QUALITIES('low')},
                {'url': episode.get('jwVideo480Embed'), 'height': 480, 'quality': QUALITIES('medium')},
                {'url': episode.get('jwVideo720Embed'), 'height': 720, 'quality': QUALITIES('high')},
                {'url': episode.get('jwVideo1080Embed'), 'height': 1080, 'quality': QUALITIES('veryhigh')}
            ],
            'duration': episode.get('length'),
            'series': course.get('name'),
            'series_id': course.get('url'),
            'availability': self._availability(
                needs_premium=False, needs_subscription=False, needs_auth=True,
                is_private=False, is_unlisted=False),
            'chapter': chapter_name,
            'chapter_number': chapter_number,
            'chapter_id': chapter_id,
            'subtitles': {'en': [{'ext': 'vtt', 'data': episode.get('enCaptionData')}]}
        }



Review comment (suggestion):
```suggestion
        chapter_number, chapter = next((
            (i, topic) for i, topic in enumerate(course.get('topics') or [], 1)
            if traverse_obj(topic, 'id') == episode.get('topic')), {})
```
then u can return 
```py
'chapter': str_or_none(chapter.get('title')),
...
```

Code after:
        episode = self._call_api('episode', episode_id, webpage)

        chapter_number, chapter = next((
            (i, topic) for i, topic in enumerate(course.get('topics') or [], 1)
            if traverse_obj(topic, 'id') == episode.get('topic')), {})

        return {
            'id': episode_id,
            'title': episode.get('title'),
            'description': episode.get('description'),
            'thumbnail': episode.get('thumbnail'),
            'formats': [
                {'url': episode[f'jwVideo{h}Embed'], 'height': h}
                for h in (320, 480, 720, 1080) if episode.get(f'jwVideo{h}Embed')
            ],
            'duration': int_or_none(episode.get('length')),
            'series': course.get('name'),
            'series_id': course.get('url'),
            'chapter': str_or_none(chapter.get('title')),
            'chapter_number': chapter_number,
            'chapter_id': str_or_none(chapter.get('id')),
            'subtitles': {
                'en': [{'ext': 'vtt', 'data': episode['enCaptionData']}]
            } if episode.get('enCaptionData') else None,
        }


class ITProTVCourseIE(ITProTVBaseIE):
    _VALID_URL = r'https?://app.itpro.tv/course/(?P<id>[\w-]+)/?(?:$|[#?])'
    _TESTS = [
        {
            'url': 'https://app.itpro.tv/course/guided-tour',
            'info_dict': {
                'id': 'guided-tour',
                'description': 'md5:b175c2c3061ce35a4dd33865b2c1da4e',
                'title': 'ITProTV 101',
            },
            'playlist_count': 6
        },
        {
            'url': 'https://app.itpro.tv/course/beyond-tech',
            'info_dict': {
                'id': 'beyond-tech',
                'description': 'md5:44cd99855e7f81a15ce1269bd0621fed',
                'title': 'Beyond Tech'
            },
            'playlist_count': 15
        },
    ]

    def _real_extract(self, url):