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

Code before:
                'channel_id': 'radio-wave',
                'chapter': 'Neklid #4',
                'chapter_number': 4,
            },
        }, {
            'md5': '6e729fa39b647325b868d419c76f3efa',
            'info_dict': {
                'id': '9890734',
                'ext': 'mp3',
                'title': 'Neklid #5',
                'description': '5. díl: Neklid: 5. díl',
                'duration': 908,
                'artist': 'Josef Kokta',
                'channel_id': 'radio-wave',
                'chapter': 'Neklid #5',
                'chapter_number': 5,
            },
        }]
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)

        # FIXME: Use get_element_text_and_html_by_tag when it accepts less strict html
        player_div = self._parse_json(extract_attributes(self._search_regex(
            '<div class="mujRozhlasPlayer" data-player=\'[^>]+\'>',
            webpage, 'player'))['data-player'], video_id)['data']


        return {
            '_type': 'playlist',
            'id': data.get('embedId'),
            'title': traverse_obj(data, ('series', 'title')),
            'entries': [{
                'id': entry['meta']['ga']['contentId'],
                'title': traverse_obj(entry, ('meta', 'ga', 'contentName')),
                'description': entry.get('title'),
                'duration': entry.get('duration'),
                'artist': traverse_obj(entry, ('meta', 'ga', 'contentAuthor')),
                'channel_id': traverse_obj(entry, ('meta', 'ga', 'contentCreator')),
                'chapter': traverse_obj(entry, ('meta', 'ga', 'contentNameShort')),
                'chapter_number': int_or_none(traverse_obj(entry, ('meta', 'ga', 'contentSerialPart'))),
                'formats': [{
                    'url': audio_link['url'],
                    'ext': audio_link.get('variant'),
                    'format_id': audio_link.get('variant'),
                    'abr': audio_link.get('bitrate'),
                    'acodec': audio_link.get('variant'),
                    'vcodec': 'none',
                } for audio_link in entry['audioLinks']],

Review comment (refactor):
```suggestion
        data = self._parse_json(extract_attributes(self._search_regex(
```

Code after:
            'info_dict': {
                'id': '9890734',
                'ext': 'mp3',
                'title': 'Neklid #5',
                'description': '5. díl: Neklid: 5. díl',
                'duration': 908,
                'artist': 'Josef Kokta',
                'channel_id': 'radio-wave',
                'chapter': 'Neklid #5',
                'chapter_number': 5,
            },
        }]
    }]

    def _extract_video(self, entry):
        chapter_number = int_or_none(traverse_obj(entry, ('meta', 'ga', 'contentSerialPart')))
        return {
            'id': entry['meta']['ga']['contentId'],
            'title': traverse_obj(entry, ('meta', 'ga', 'contentName')),
            'description': entry.get('title'),
            'duration': entry.get('duration'),
            'artist': traverse_obj(entry, ('meta', 'ga', 'contentAuthor')),
            'channel_id': traverse_obj(entry, ('meta', 'ga', 'contentCreator')),
            'chapter': traverse_obj(entry, ('meta', 'ga', 'contentNameShort')) if chapter_number else None,
            'chapter_number': chapter_number,
            'formats': [{
                'url': audio_link['url'],
                'ext': audio_link.get('variant'),
                'format_id': audio_link.get('variant'),
                'abr': audio_link.get('bitrate'),
                'acodec': audio_link.get('variant'),
                'vcodec': 'none',
            } for audio_link in entry['audioLinks']],
        }

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)

        # FIXME: Use get_element_text_and_html_by_tag when it accepts less strict html
        data = self._parse_json(extract_attributes(self._search_regex(
            r'(<div class="mujRozhlasPlayer" data-player=\'[^\']+\'>)',
            webpage, 'player'))['data-player'], video_id)['data']

        return {
            '_type': 'playlist',
            'id': data.get('embedId'),
            'title': traverse_obj(data, ('series', 'title')),
            'entries': map(self._extract_video, data['playlist']),
        }