]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/bongacams.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / bongacams.py
CommitLineData
29f7c58a 1from .common import InfoExtractor
2from ..compat import compat_str
3from ..utils import (
4 int_or_none,
5 try_get,
6 urlencode_postdata,
7)
8
9
10class BongaCamsIE(InfoExtractor):
573a98d6 11 _VALID_URL = r'https?://(?P<host>(?:[^/]+\.)?bongacams\d*\.(?:com|net))/(?P<id>[^/?&#]+)'
29f7c58a 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,
573a98d6
D
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,
29 },
30 'params': {
31 'skip_download': True,
32 },
29f7c58a 33 }]
34
35 def _real_extract(self, url):
5ad28e7f 36 mobj = self._match_valid_url(url)
29f7c58a 37 host = mobj.group('host')
38 channel_id = mobj.group('id')
39
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'})
47
48 server_url = amf['localData']['videoServerUrl']
49
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']))
56
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)
29f7c58a 60
61 return {
62 'id': channel_id,
39ca3b5c 63 'title': uploader or uploader_id,
29f7c58a 64 'uploader': uploader,
65 'uploader_id': uploader_id,
66 'like_count': like_count,
67 'age_limit': 18,
68 'is_live': True,
69 'formats': formats,
70 }