]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/bongacams.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / bongacams.py
CommitLineData
29f7c58a 1from .common import InfoExtractor
29f7c58a 2from ..utils import (
3 int_or_none,
4 try_get,
5 urlencode_postdata,
6)
7
8
9class BongaCamsIE(InfoExtractor):
573a98d6 10 _VALID_URL = r'https?://(?P<host>(?:[^/]+\.)?bongacams\d*\.(?:com|net))/(?P<id>[^/?&#]+)'
29f7c58a 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,
573a98d6
D
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,
28 },
29 'params': {
30 'skip_download': True,
31 },
29f7c58a 32 }]
33
34 def _real_extract(self, url):
5ad28e7f 35 mobj = self._match_valid_url(url)
29f7c58a 36 host = mobj.group('host')
37 channel_id = mobj.group('id')
38
39 amf = self._download_json(
add96eb9 40 f'https://{host}/tools/amf.php', channel_id,
29f7c58a 41 data=urlencode_postdata((
42 ('method', 'getRoomData'),
43 ('args[]', channel_id),
44 ('args[]', 'false'),
45 )), headers={'X-Requested-With': 'XMLHttpRequest'})
46
47 server_url = amf['localData']['videoServerUrl']
48
49 uploader_id = try_get(
add96eb9 50 amf, lambda x: x['performerData']['username'], str) or channel_id
29f7c58a 51 uploader = try_get(
add96eb9 52 amf, lambda x: x['performerData']['displayName'], str)
29f7c58a 53 like_count = int_or_none(try_get(
54 amf, lambda x: x['performerData']['loversCount']))
55
56 formats = self._extract_m3u8_formats(
add96eb9 57 f'{server_url}/hls/stream_{uploader_id}/playlist.m3u8',
29f7c58a 58 channel_id, 'mp4', m3u8_id='hls', live=True)
29f7c58a 59
60 return {
61 'id': channel_id,
39ca3b5c 62 'title': uploader or uploader_id,
29f7c58a 63 'uploader': uploader,
64 'uploader_id': uploader_id,
65 'like_count': like_count,
66 'age_limit': 18,
67 'is_live': True,
68 'formats': formats,
69 }