]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/bongacams.py
[extractor/FranceCulture] Fix extractor (#3874)
[yt-dlp.git] / yt_dlp / extractor / bongacams.py
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,
7 )
8
9
10 class BongaCamsIE(InfoExtractor):
11 _VALID_URL = r'https?://(?P<host>(?:[^/]+\.)?bongacams\d*\.com)/(?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
20 def _real_extract(self, url):
21 mobj = self._match_valid_url(url)
22 host = mobj.group('host')
23 channel_id = mobj.group('id')
24
25 amf = self._download_json(
26 'https://%s/tools/amf.php' % host, channel_id,
27 data=urlencode_postdata((
28 ('method', 'getRoomData'),
29 ('args[]', channel_id),
30 ('args[]', 'false'),
31 )), headers={'X-Requested-With': 'XMLHttpRequest'})
32
33 server_url = amf['localData']['videoServerUrl']
34
35 uploader_id = try_get(
36 amf, lambda x: x['performerData']['username'], compat_str) or channel_id
37 uploader = try_get(
38 amf, lambda x: x['performerData']['displayName'], compat_str)
39 like_count = int_or_none(try_get(
40 amf, lambda x: x['performerData']['loversCount']))
41
42 formats = self._extract_m3u8_formats(
43 '%s/hls/stream_%s/playlist.m3u8' % (server_url, uploader_id),
44 channel_id, 'mp4', m3u8_id='hls', live=True)
45 self._sort_formats(formats)
46
47 return {
48 'id': channel_id,
49 'title': uploader or uploader_id,
50 'uploader': uploader,
51 'uploader_id': uploader_id,
52 'like_count': like_count,
53 'age_limit': 18,
54 'is_live': True,
55 'formats': formats,
56 }