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

Code before:
import re

from .common import InfoExtractor


class MixlrIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?(?P<username>[\w-]+)\.mixlr\.com/events/(?P<id>\d+)'
    _TESTS = [{
        'url': 'https://suncity-104-9fm.mixlr.com/events/4261962',
        'info_dict': {
            'id': '4261962',
            'title': re.compile(r'.+'),
            'description': re.compile(r'.+'),
            'ext': 'mp3',
            'is_live': True,
            'uploader': 'suncity-104-9fm',
        },
        'skip': 'Live broadcast may not be available',
    }]

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

        api_url = f'https://apicdn.mixlr.com/v3/channel_view/{username}'
        channel_info = self._download_json(api_url, event_id)
        user_data = channel_info.get('data', {}).get('attributes', {})

        broadcast_data = None
        event_data = None
        included = channel_info.get('included', [])
        for item in included:
            if item.get('type') == 'broadcast':
                broadcast_data = item.get('attributes', {})
            elif item.get('type') == 'event' and item.get('id') == event_id:
                event_data = item.get('attributes', {})

            if broadcast_data and event_data:
                break

        if not broadcast_data or not broadcast_data.get('live', False):
            self.raise_no_formats('No active broadcast found', expected=True)
        if not event_data:
            self.raise_no_formats('No event data found', expected=True)

        streaming_url = broadcast_data.get('progressive_stream_url')
        title = event_data.get('title') or f'Mixlr broadcast by {username}'
        description = event_data.get('description') or broadcast_data.get('description') or ''

        formats = []
        if streaming_url:
            formats.append({
                'url': streaming_url,
                'format_id': 'http',
                'ext': 'mp3',
                'vcodec': 'none',
            })

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

        return {
            'id': event_id,
            'title': title,
            'description': description,
            'uploader': username,
            'uploader_id': user_data.get('id'),
            'uploader_url': f'https://{username}.mixlr.com',
            'thumbnail': user_data.get('avatar_full_url') or user_data.get('avatar_url'),
            'is_live': broadcast_data.get('live', True),
            'formats': formats,
        }


Review comment (refactor):
I also added an extractor for recordings:
```suggestion
        }


class MixlrRecoringIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?(?P<username>[\w-]+)\.mixlr\.com/recordings/(?P<id>\d+)'
    _TESTS = [{
        'url': 'https://biblewayng.mixlr.com/recordings/2375193',
        'info_dict': {
            'id': '2375193',
            'ext': 'mp3',
            'title': "God's Jewels and Their Resting Place Bro. Adeniji",
            'description': 'Preached February 21, 2024 in the evening',
            'uploader_id': '8659190',
            'duration': 10968,
            'thumbnail': r're:https://imagecdn\.mixlr\.com/cdn-cgi/image/[^/?#]+/ceca120ef707f642abeea6e29cd74238.jpg',
            'timestamp': 1708544542,
            'upload_date': '20240221',
        },
    }]

    def _real_extract(self, url):
        username, recording_id = self._match_valid_url(url).group('username', 'id')

        recording_info = self._download_json(
            f'https://api.mixlr.com/v3/channels/{username}/recordings/{recording_id}', recording_id)

        return {
            'id': recording_id,
            'is_live': False,
            **traverse_obj(recording_info, ('data', 'attributes', {
                'ext': ('file_format', {str}),
                'url': ('url', {url_or_none}),
                'title': ('title', {str}),
                'description': ('description', {str}),
                'timestamp': ('created_at', {parse_iso8601}),
                'duration': ('duration', {int_or_none}),
                'thumbnail': ('artwork_url', {url_or_none}),
                'uploader_id': ('user_id', {str}),
            })),
        }

```

Code after:
            'duration': 10968,
            'thumbnail': r're:https://imagecdn\.mixlr\.com/cdn-cgi/image/[^/?#]+/ceca120ef707f642abeea6e29cd74238.jpg',
            'timestamp': 1708544542,
            'upload_date': '20240221',
        },
    }]

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

        recording_info = self._download_json(
            f'https://api.mixlr.com/v3/channels/{username}/recordings/{recording_id}', recording_id)

        return {
            'id': recording_id,
            **traverse_obj(recording_info, ('data', 'attributes', {
                'ext': ('file_format', {str}),
                'url': ('url', {url_or_none}),
                'title': ('title', {str}),
                'description': ('description', {str}),
                'timestamp': ('created_at', {parse_iso8601}),
                'duration': ('duration', {int_or_none}),
                'thumbnail': ('artwork_url', {url_or_none}),
                'uploader_id': ('user_id', {str}),
            })),
        }