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

Generated by cgit