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

Code before:

    def _get_video_info(self, video_id):
        url = self._GET_LIVESTREAM_API + '/recent/' + video_id
        data = self._download_json(url, video_id)
        return traverse_obj(data, {
            'channel': ('user_name', {str}),
            'thumbnail': ('event_file', {str}),
            'categories': ('category', {lambda c: [c]}),
            'url': ('livestream_recording', {str}),
            'title': ('event_title', {str}),
            'upload_date': ('event_start_ts', {lambda ts: datetime.date.fromtimestamp(ts).strftime('%Y%m%d')}),
        })

    def _real_extract(self, url):
        video_id = self._match_id(url)
        video_info = self._get_video_info(video_id)
        full_recording_url = self._build_recording_url(video_info['url'])
        formats = self._get_formats(full_recording_url, video_info['channel'], is_live=False)

        return {
            'id': video_id,
            'url': url,
            'formats': formats,
            'is_live': False,
            **video_info,
        }


class PartiLivestreamIE(PartiBaseIE):
    IE_NAME = 'parti:livestream'
    IE_DESC = 'Download a stream from parti.com'
    _VALID_URL = r'https://parti\.com/creator/(parti|discord|telegram)/(?P<id>[\w-]+)'
    _TESTS = [
        {
            'url': 'https://parti.com/creator/parti/SpartanTheDog',
            'info_dict': {
                'id': 'SpartanTheDog',
                'ext': 'mp4',
                'title': str,
                'description': str,
                'upload_date': str,
                'is_live': True,
                'live_status': 'is_live',
            },
            'params': {'skip_download': 'm3u8'},
        },
    ]
    _CREATOR_API = 'https://api-backend.parti.com/parti_v2/profile/get_user_by_social_media/parti'

    def _get_creator_id(self, creator):
        """ The creator ID is a number returned as plain text """

Review comment (refactor):
Imo. no use in using a separate function here
```suggestion
    def _real_extract(self, url):
        video_id = self._match_id(url)
        data = self._call_api(f'get_livestream_channel_info/recent/{video_id}', video_id)
        formats = self._extract_m3u8_formats(
            urljoin('https://watch.parti.com', data['livestream_recording']), video_id, 'mp4')

        return {
            'id': video_id,
            'formats': formats,
            'is_live': False,
            **traverse_obj(data, {
                'title': ('event_title', {str}),
                'channel': ('user_name', {str}),
                'thumbnail': ('event_file', {url_or_none}),
                'categories': ('category_name', {str}, all),
                'timestamp': ('event_start_ts', {int_or_none}),
            }),
        }
```

Code after:
            }),
        }


class PartiLivestreamIE(PartiBaseIE):
    IE_NAME = 'parti:livestream'
    _VALID_URL = r'https?://(?:www\.)?parti\.com/creator/(?P<service>[\w]+)/(?P<id>[\w/-]+)'
    _TESTS = [{
        'url': 'https://parti.com/creator/parti/Capt_Robs_Adventures',
        'info_dict': {
            'id': 'Capt_Robs_Adventures',
            'ext': 'mp4',
            'title': r"re:I'm Live on Parti \d{4}-\d{2}-\d{2} \d{2}:\d{2}",
            'view_count': int,
            'thumbnail': r're:https://assets\.parti\.com/.+\.png',
            'timestamp': 1743879776,
            'upload_date': '20250405',
            'live_status': 'is_live',
        },
        'params': {'skip_download': 'm3u8'},
    }, {
        'url': 'https://parti.com/creator/discord/sazboxgaming/0',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        service, creator_slug = self._match_valid_url(url).group('service', 'id')

        encoded_creator_slug = creator_slug.replace('/', '%23')
        creator_id = self._call_api(
            f'get_user_by_social_media/{service}/{encoded_creator_slug}',
            creator_slug, note='Fetching user ID')

        data = self._call_api(
            f'get_livestream_channel_info/{creator_id}', creator_id,
            note='Fetching user profile feed')['channel_info']

        if not traverse_obj(data, ('channel', 'is_live', {bool})):
            raise UserNotLive(video_id=creator_id)

        channel_info = data['channel']

        return {
            'id': creator_slug,
            'formats': self._extract_m3u8_formats(
                channel_info['playback_url'], creator_slug, live=True, query={
                    'token': channel_info['playback_auth_token'],
                    'player_version': '1.17.0',
                }),
            'is_live': True,
            **traverse_obj(data, {