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

Code before:
        username, event_id = self._match_valid_url(url).group('username', 'id')

        broadcast_info = self._download_json(
            f'https://api.mixlr.com/v3/channels/{username}/events/{event_id}', event_id)

        formats = []
        format_url = traverse_obj(
            broadcast_info, ('included', 0, 'attributes', 'progressive_stream_url', {url_or_none}))
        if format_url:
            urlh = self._request_webpage(
                HEADRequest(format_url), event_id, fatal=False, note='Checking stream')
            if not urlh or urlh.status != 200:
                ext = urlhandle_detect_ext(urlh)
                if ext == 'octet-stream':
                    self.report_warning(
                        'The server did not return a valid file extension for the stream URL, '
                        'defaulting to "mp3". Please ensure that the downloaded audio is actually mp3.')
                    ext = 'mp3'
                formats.append({
                    'url': format_url,
                    'ext': ext,
                    'vcodec': 'none',
                })

        if not formats:
            self.raise_no_formats('No formats found', expected=True)

        return {
            'id': event_id,
            'uploader': username,
            'formats': formats,
            **traverse_obj(broadcast_info, ('included', 0, 'attributes', {
                'title': ('title', {str}),
                'timestamp': ('started_at', {parse_iso8601}),
                'concurrent_view_count': ('concurrent_view_count', {int_or_none}),
                'like_count': ('heart_count', {int_or_none}),
                'is_live': ('live', {bool}),
            })),
            **traverse_obj(broadcast_info, ('data', 'attributes', {
                'title': ('title', {str}),
                'description': ('description', {str}),
                'timestamp': ('started_at', {parse_iso8601}),
                'release_timestamp': ('starts_at', {parse_iso8601}),
                'concurrent_view_count': ('concurrent_view_count', {int_or_none}),
                'like_count': ('heart_count', {int_or_none}),
                'thumbnail': ('artwork_url', {url_or_none}),
                'uploader_id': ('broadcaster_id', {str}),
            })),
        }



Review comment (refactor):
can we extract `release_timestamp` before this point and give a better message if the start time is in the future?

Code after:
    }]

    def _real_extract(self, url):
        username, event_id = self._match_valid_url(url).group('username', 'id')

        broadcast_info = self._download_json(
            f'https://api.mixlr.com/v3/channels/{username}/events/{event_id}', event_id)

        formats = []
        format_url = traverse_obj(
            broadcast_info, ('included', 0, 'attributes', 'progressive_stream_url', {url_or_none}))
        if format_url:
            urlh = self._request_webpage(
                HEADRequest(format_url), event_id, fatal=False, note='Checking stream')
            if urlh and urlh.status == 200:
                ext = urlhandle_detect_ext(urlh)
                if ext == 'octet-stream':
                    self.report_warning(
                        'The server did not return a valid file extension for the stream URL. '
                        'Assuming an mp3 stream; postprocessing may fail if this is incorrect')
                    ext = 'mp3'
                formats.append({
                    'url': format_url,
                    'ext': ext,
                    'vcodec': 'none',
                })

        release_timestamp = traverse_obj(
            broadcast_info, ('data', 'attributes', 'starts_at', {str}))
        if not formats and release_timestamp:
            self.raise_no_formats(f'This event will start at {release_timestamp}', expected=True)

        return {
            'id': event_id,
            'uploader': username,
            'formats': formats,
            'release_timestamp': parse_iso8601(release_timestamp),
            **traverse_obj(broadcast_info, ('included', 0, 'attributes', {
                'title': ('title', {str}),
                'timestamp': ('started_at', {parse_iso8601}),
                'concurrent_view_count': ('concurrent_view_count', {int_or_none}),
                'like_count': ('heart_count', {int_or_none}),
                'is_live': ('live', {bool}),
            })),
            **traverse_obj(broadcast_info, ('data', 'attributes', {
                'title': ('title', {str}),
                'description': ('description', {str}),
                'timestamp': ('started_at', {parse_iso8601}),
                'concurrent_view_count': ('concurrent_view_count', {int_or_none}),
                'like_count': ('heart_count', {int_or_none}),
                'thumbnail': ('artwork_url', {url_or_none}),