]>
Commit | Line | Data |
---|---|---|
cd55c6cc | 1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | from .common import InfoExtractor | |
5 | from ..utils import ( | |
6 | ExtractorError, | |
7 | clean_html, | |
8 | compat_str, | |
9 | int_or_none, | |
10 | parse_iso8601, | |
11 | try_get, | |
12 | ) | |
13 | ||
14 | ||
15 | class BeamProLiveIE(InfoExtractor): | |
16 | IE_NAME = 'Beam:live' | |
af62de10 | 17 | _VALID_URL = r'https?://(?:\w+\.)?beam\.pro/(?P<id>[^/?#&]+)' |
cd55c6cc | 18 | _RATINGS = {'family': 0, 'teen': 13, '18+': 18} |
cd55c6cc | 19 | _TEST = { |
20 | 'url': 'http://www.beam.pro/niterhayven', | |
21 | 'info_dict': { | |
22 | 'id': '261562', | |
23 | 'ext': 'mp4', | |
cd55c6cc | 24 | 'title': 'Introducing The Witcher 3 // The Grind Starts Now!', |
af62de10 | 25 | 'description': 'md5:0b161ac080f15fe05d18a07adb44a74d', |
cd55c6cc | 26 | 'thumbnail': r're:https://.*\.jpg$', |
af62de10 | 27 | 'timestamp': 1483477281, |
cd55c6cc | 28 | 'upload_date': '20170103', |
af62de10 S |
29 | 'uploader': 'niterhayven', |
30 | 'uploader_id': '373396', | |
31 | 'age_limit': 18, | |
cd55c6cc | 32 | 'is_live': True, |
af62de10 | 33 | 'view_count': int, |
cd55c6cc | 34 | }, |
35 | 'skip': 'niterhayven is offline', | |
36 | 'params': { | |
37 | 'skip_download': True, | |
38 | }, | |
39 | } | |
40 | ||
41 | def _real_extract(self, url): | |
af62de10 | 42 | channel_name = self._match_id(url) |
cd55c6cc | 43 | |
af62de10 S |
44 | chan = self._download_json( |
45 | 'https://beam.pro/api/v1/channels/%s' % channel_name, channel_name) | |
cd55c6cc | 46 | |
af62de10 S |
47 | if chan.get('online') is False: |
48 | raise ExtractorError( | |
49 | '{0} is offline'.format(channel_name), expected=True) | |
cd55c6cc | 50 | |
af62de10 | 51 | channel_id = chan['id'] |
cd55c6cc | 52 | |
af62de10 S |
53 | formats = self._extract_m3u8_formats( |
54 | 'https://beam.pro/api/v1/channels/%s/manifest.m3u8' % channel_id, | |
55 | channel_name, ext='mp4', m3u8_id='hls', fatal=False) | |
56 | self._sort_formats(formats) | |
cd55c6cc | 57 | |
af62de10 | 58 | user_id = chan.get('userId') or try_get(chan, lambda x: x['user']['id']) |
cd55c6cc | 59 | |
60 | return { | |
af62de10 S |
61 | 'id': compat_str(chan.get('id') or channel_name), |
62 | 'title': self._live_title(chan.get('name') or channel_name), | |
63 | 'description': clean_html(chan.get('description')), | |
64 | 'thumbnail': try_get(chan, lambda x: x['thumbnail']['url'], compat_str), | |
65 | 'timestamp': parse_iso8601(chan.get('updatedAt')), | |
66 | 'uploader': chan.get('token') or try_get( | |
67 | chan, lambda x: x['user']['username'], compat_str), | |
68 | 'uploader_id': compat_str(user_id) if user_id else None, | |
69 | 'age_limit': self._RATINGS.get(chan.get('audience')), | |
70 | 'is_live': True, | |
71 | 'view_count': int_or_none(chan.get('viewersTotal')), | |
72 | 'formats': formats, | |
cd55c6cc | 73 | } |