]> jfr.im git - yt-dlp.git/blame - youtube_dlc/extractor/rumble.py
Update to release 2020.11.24 except youtube and skyit extractors
[yt-dlp.git] / youtube_dlc / extractor / rumble.py
CommitLineData
70c5802b 1# coding: utf-8
2from __future__ import unicode_literals
3
4from .common import InfoExtractor
5from ..compat import compat_str
6from ..utils import (
7 determine_ext,
8 int_or_none,
9 parse_iso8601,
10 try_get,
11)
12
13
14class RumbleEmbedIE(InfoExtractor):
15 _VALID_URL = r'https?://(?:www\.)?rumble\.com/embed/(?:[0-9a-z]+\.)?(?P<id>[0-9a-z]+)'
16 _TESTS = [{
17 'url': 'https://rumble.com/embed/v5pv5f',
18 'md5': '36a18a049856720189f30977ccbb2c34',
19 'info_dict': {
20 'id': 'v5pv5f',
21 'ext': 'mp4',
22 'title': 'WMAR 2 News Latest Headlines | October 20, 6pm',
23 'timestamp': 1571611968,
24 'upload_date': '20191020',
25 }
26 }, {
27 'url': 'https://rumble.com/embed/ufe9n.v5pv5f',
28 'only_matching': True,
29 }]
30
31 def _real_extract(self, url):
32 video_id = self._match_id(url)
33 video = self._download_json(
34 'https://rumble.com/embedJS/', video_id,
35 query={'request': 'video', 'v': video_id})
36 title = video['title']
37
38 formats = []
39 for height, ua in (video.get('ua') or {}).items():
40 for i in range(2):
41 f_url = try_get(ua, lambda x: x[i], compat_str)
42 if f_url:
43 ext = determine_ext(f_url)
44 f = {
45 'ext': ext,
46 'format_id': '%s-%sp' % (ext, height),
47 'height': int_or_none(height),
48 'url': f_url,
49 }
50 bitrate = try_get(ua, lambda x: x[i + 2]['bitrate'])
51 if bitrate:
52 f['tbr'] = int_or_none(bitrate)
53 formats.append(f)
54 self._sort_formats(formats)
55
56 author = video.get('author') or {}
57
58 return {
59 'id': video_id,
60 'title': title,
61 'formats': formats,
62 'thumbnail': video.get('i'),
63 'timestamp': parse_iso8601(video.get('pubDate')),
64 'channel': author.get('name'),
65 'channel_url': author.get('url'),
66 'duration': int_or_none(video.get('duration')),
67 }