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