[aliexpress:live] Add extractor
[youtube-dl] / youtube_dl / extractor / aliexpress.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4
5 import re
6
7 from .common import InfoExtractor
8 from ..utils import try_get, float_or_none
9 from ..compat import compat_str
10
11
12 class AliExpressLiveIE(InfoExtractor):
13
14     _VALID_URL = r'https?://live\.aliexpress\.com/live/(?P<id>[0-9]{16})'
15     _TEST = {
16         'url': 'https://live.aliexpress.com/live/2800002704436634',
17         'md5': '7ac2bc46afdd18f0b45a0a340fc47ffe',
18         'info_dict': {
19             'id': '2800002704436634',
20             'ext': 'm3u8',
21             'title': 'CASIMA7.22',
22             'uploader': 'CASIMA Official Store',
23             'upload_date': '20170714',
24             'timestamp': 1500027138,
25         },
26     }
27
28     def _real_extract(self, url):
29         video_id = self._match_id(url)
30         page = self._download_webpage(url, video_id)
31         run_params_json = self._search_regex(r'runParams = (.+)[\s+]var myCtl', page, 'runParams', flags=re.DOTALL)
32         run_params = self._parse_json(run_params_json, video_id)
33
34         return {
35             'id': video_id,
36             'title': run_params['title'],
37             'url': run_params['replyStreamUrl'],
38             'uploader': try_get(run_params, lambda x: x['followBar']['name'], compat_str),
39             'timestamp': float_or_none(try_get(run_params, lambda x: x['followBar']['createTime']) / 1000),
40         }