]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/cloudflarestream.py
debian/patch: Refresh all patches to avoid FTBFS.
[youtubedl] / youtube_dl / extractor / cloudflarestream.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7
8
9 class CloudflareStreamIE(InfoExtractor):
10 _VALID_URL = r'''(?x)
11 https?://
12 (?:
13 (?:watch\.)?cloudflarestream\.com/|
14 embed\.cloudflarestream\.com/embed/[^/]+\.js\?.*?\bvideo=
15 )
16 (?P<id>[\da-f]+)
17 '''
18 _TESTS = [{
19 'url': 'https://embed.cloudflarestream.com/embed/we4g.fla9.latest.js?video=31c9291ab41fac05471db4e73aa11717',
20 'info_dict': {
21 'id': '31c9291ab41fac05471db4e73aa11717',
22 'ext': 'mp4',
23 'title': '31c9291ab41fac05471db4e73aa11717',
24 },
25 'params': {
26 'skip_download': True,
27 },
28 }, {
29 'url': 'https://watch.cloudflarestream.com/9df17203414fd1db3e3ed74abbe936c1',
30 'only_matching': True,
31 }, {
32 'url': 'https://cloudflarestream.com/31c9291ab41fac05471db4e73aa11717/manifest/video.mpd',
33 'only_matching': True,
34 }]
35
36 @staticmethod
37 def _extract_urls(webpage):
38 return [
39 mobj.group('url')
40 for mobj in re.finditer(
41 r'<script[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//embed\.cloudflarestream\.com/embed/[^/]+\.js\?.*?\bvideo=[\da-f]+?.*?)\1',
42 webpage)]
43
44 def _real_extract(self, url):
45 video_id = self._match_id(url)
46
47 formats = self._extract_m3u8_formats(
48 'https://cloudflarestream.com/%s/manifest/video.m3u8' % video_id,
49 video_id, 'mp4', entry_protocol='m3u8_native', m3u8_id='hls',
50 fatal=False)
51 formats.extend(self._extract_mpd_formats(
52 'https://cloudflarestream.com/%s/manifest/video.mpd' % video_id,
53 video_id, mpd_id='dash', fatal=False))
54 self._sort_formats(formats)
55
56 return {
57 'id': video_id,
58 'title': video_id,
59 'formats': formats,
60 }