]>
Commit | Line | Data |
---|---|---|
a71c1d1a | 1 | import base64 |
660a230b S |
2 | |
3 | from .common import InfoExtractor | |
4 | ||
5 | ||
6 | class CloudflareStreamIE(InfoExtractor): | |
464c919e | 7 | _SUBDOMAIN_RE = r'(?:(?:watch|iframe|customer-\w+)\.)?' |
a71c1d1a | 8 | _DOMAIN_RE = r'(?:cloudflarestream\.com|(?:videodelivery|bytehighway)\.net)' |
464c919e | 9 | _EMBED_RE = rf'embed\.{_DOMAIN_RE}/embed/[^/]+\.js\?.*?\bvideo=' |
483b858d | 10 | _ID_RE = r'[\da-f]{32}|[\w-]+\.[\w-]+\.[\w-]+' |
464c919e | 11 | _VALID_URL = rf'https?://(?:{_SUBDOMAIN_RE}{_DOMAIN_RE}/|{_EMBED_RE})(?P<id>{_ID_RE})' |
12 | _EMBED_REGEX = [ | |
13 | rf'<script[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//{_EMBED_RE}(?:{_ID_RE}).*?)\1', | |
14 | rf'<iframe[^>]+\bsrc=["\'](?P<url>https?://{_SUBDOMAIN_RE}{_DOMAIN_RE}/[\da-f]{{32}})', | |
15 | ] | |
660a230b S |
16 | _TESTS = [{ |
17 | 'url': 'https://embed.cloudflarestream.com/embed/we4g.fla9.latest.js?video=31c9291ab41fac05471db4e73aa11717', | |
18 | 'info_dict': { | |
19 | 'id': '31c9291ab41fac05471db4e73aa11717', | |
20 | 'ext': 'mp4', | |
21 | 'title': '31c9291ab41fac05471db4e73aa11717', | |
464c919e | 22 | 'thumbnail': 'https://videodelivery.net/31c9291ab41fac05471db4e73aa11717/thumbnails/thumbnail.jpg', |
660a230b S |
23 | }, |
24 | 'params': { | |
464c919e | 25 | 'skip_download': 'm3u8', |
660a230b S |
26 | }, |
27 | }, { | |
28 | 'url': 'https://watch.cloudflarestream.com/9df17203414fd1db3e3ed74abbe936c1', | |
29 | 'only_matching': True, | |
30 | }, { | |
31 | 'url': 'https://cloudflarestream.com/31c9291ab41fac05471db4e73aa11717/manifest/video.mpd', | |
32 | 'only_matching': True, | |
169f8d0f | 33 | }, { |
34 | 'url': 'https://embed.videodelivery.net/embed/r4xu.fla9.latest.js?video=81d80727f3022488598f68d323c1ad5e', | |
35 | 'only_matching': True, | |
f3d5face | 36 | }, { |
37 | 'url': 'https://customer-aw5py76sw8wyqzmh.cloudflarestream.com/2463f6d3e06fa29710a337f5f5389fd8/iframe', | |
38 | 'only_matching': True, | |
660a230b | 39 | }] |
464c919e | 40 | _WEBPAGE_TESTS = [{ |
41 | 'url': 'https://upride.cc/incident/shoulder-pass-at-light/', | |
42 | 'info_dict': { | |
43 | 'id': 'eaef9dea5159cf968be84241b5cedfe7', | |
44 | 'ext': 'mp4', | |
45 | 'title': 'eaef9dea5159cf968be84241b5cedfe7', | |
46 | 'thumbnail': 'https://videodelivery.net/eaef9dea5159cf968be84241b5cedfe7/thumbnails/thumbnail.jpg', | |
47 | }, | |
48 | 'params': { | |
49 | 'skip_download': 'm3u8', | |
50 | }, | |
51 | }] | |
660a230b | 52 | |
660a230b S |
53 | def _real_extract(self, url): |
54 | video_id = self._match_id(url) | |
a71c1d1a RA |
55 | domain = 'bytehighway.net' if 'bytehighway.net/' in url else 'videodelivery.net' |
56 | base_url = 'https://%s/%s/' % (domain, video_id) | |
57 | if '.' in video_id: | |
58 | video_id = self._parse_json(base64.urlsafe_b64decode( | |
7f71cee0 | 59 | video_id.split('.')[1] + '==='), video_id)['sub'] |
a71c1d1a | 60 | manifest_base_url = base_url + 'manifest/video.' |
660a230b | 61 | |
4d9dc0ab | 62 | formats, subtitles = self._extract_m3u8_formats_and_subtitles( |
a71c1d1a RA |
63 | manifest_base_url + 'm3u8', video_id, 'mp4', |
64 | 'm3u8_native', m3u8_id='hls', fatal=False) | |
4d9dc0ab B |
65 | fmts, subs = self._extract_mpd_formats_and_subtitles( |
66 | manifest_base_url + 'mpd', video_id, mpd_id='dash', fatal=False) | |
67 | formats.extend(fmts) | |
68 | self._merge_subtitles(subs, target=subtitles) | |
660a230b S |
69 | |
70 | return { | |
71 | 'id': video_id, | |
72 | 'title': video_id, | |
a71c1d1a | 73 | 'thumbnail': base_url + 'thumbnails/thumbnail.jpg', |
660a230b | 74 | 'formats': formats, |
4d9dc0ab | 75 | 'subtitles': subtitles, |
660a230b | 76 | } |