]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/bongacams.py
[extractor] Standardize `_live_title`
[yt-dlp.git] / yt_dlp / extractor / bongacams.py
1 from __future__ import unicode_literals
2
3
4 from .common import InfoExtractor
5 from ..compat import compat_str
6 from ..utils import (
7 int_or_none,
8 try_get,
9 urlencode_postdata,
10 )
11
12
13 class BongaCamsIE(InfoExtractor):
14 _VALID_URL = r'https?://(?P<host>(?:[^/]+\.)?bongacams\d*\.com)/(?P<id>[^/?&#]+)'
15 _TESTS = [{
16 'url': 'https://de.bongacams.com/azumi-8',
17 'only_matching': True,
18 }, {
19 'url': 'https://cn.bongacams.com/azumi-8',
20 'only_matching': True,
21 }]
22
23 def _real_extract(self, url):
24 mobj = self._match_valid_url(url)
25 host = mobj.group('host')
26 channel_id = mobj.group('id')
27
28 amf = self._download_json(
29 'https://%s/tools/amf.php' % host, channel_id,
30 data=urlencode_postdata((
31 ('method', 'getRoomData'),
32 ('args[]', channel_id),
33 ('args[]', 'false'),
34 )), headers={'X-Requested-With': 'XMLHttpRequest'})
35
36 server_url = amf['localData']['videoServerUrl']
37
38 uploader_id = try_get(
39 amf, lambda x: x['performerData']['username'], compat_str) or channel_id
40 uploader = try_get(
41 amf, lambda x: x['performerData']['displayName'], compat_str)
42 like_count = int_or_none(try_get(
43 amf, lambda x: x['performerData']['loversCount']))
44
45 formats = self._extract_m3u8_formats(
46 '%s/hls/stream_%s/playlist.m3u8' % (server_url, uploader_id),
47 channel_id, 'mp4', m3u8_id='hls', live=True)
48 self._sort_formats(formats)
49
50 return {
51 'id': channel_id,
52 'title': uploader or uploader_id,
53 'uploader': uploader,
54 'uploader_id': uploader_id,
55 'like_count': like_count,
56 'age_limit': 18,
57 'is_live': True,
58 'formats': formats,
59 }