[cleanup] Make more playlist entries lazy (#11763)
[yt-dlp.git] / yt_dlp / extractor / bongacams.py
blobab85477de45c094a121ea777319b6f1438d7bfa4
1 from .common import InfoExtractor
2 from ..utils import (
3 int_or_none,
4 try_get,
5 urlencode_postdata,
9 class BongaCamsIE(InfoExtractor):
10 _VALID_URL = r'https?://(?P<host>(?:[^/]+\.)?bongacams\d*\.(?:com|net))/(?P<id>[^/?&#]+)'
11 _TESTS = [{
12 'url': 'https://de.bongacams.com/azumi-8',
13 'only_matching': True,
14 }, {
15 'url': 'https://cn.bongacams.com/azumi-8',
16 'only_matching': True,
17 }, {
18 'url': 'https://de.bongacams.net/claireashton',
19 'info_dict': {
20 'id': 'claireashton',
21 'ext': 'mp4',
22 'title': r're:ClaireAshton \d{4}-\d{2}-\d{2} \d{2}:\d{2}',
23 'age_limit': 18,
24 'uploader_id': 'ClaireAshton',
25 'uploader': 'ClaireAshton',
26 'like_count': int,
27 'is_live': True,
29 'params': {
30 'skip_download': True,
34 def _real_extract(self, url):
35 mobj = self._match_valid_url(url)
36 host = mobj.group('host')
37 channel_id = mobj.group('id')
39 amf = self._download_json(
40 f'https://{host}/tools/amf.php', channel_id,
41 data=urlencode_postdata((
42 ('method', 'getRoomData'),
43 ('args[]', channel_id),
44 ('args[]', 'false'),
45 )), headers={'X-Requested-With': 'XMLHttpRequest'})
47 server_url = amf['localData']['videoServerUrl']
49 uploader_id = try_get(
50 amf, lambda x: x['performerData']['username'], str) or channel_id
51 uploader = try_get(
52 amf, lambda x: x['performerData']['displayName'], str)
53 like_count = int_or_none(try_get(
54 amf, lambda x: x['performerData']['loversCount']))
56 formats = self._extract_m3u8_formats(
57 f'{server_url}/hls/stream_{uploader_id}/playlist.m3u8',
58 channel_id, 'mp4', m3u8_id='hls', live=True)
60 return {
61 'id': channel_id,
62 'title': uploader or uploader_id,
63 'uploader': uploader,
64 'uploader_id': uploader_id,
65 'like_count': like_count,
66 'age_limit': 18,
67 'is_live': True,
68 'formats': formats,