2020-01-08 14:42:53 -07:00
|
|
|
import base64
|
2018-05-04 12:21:52 -06:00
|
|
|
|
|
|
|
from .common import InfoExtractor
|
|
|
|
|
|
|
|
|
|
|
|
class CloudflareStreamIE(InfoExtractor):
|
2024-02-24 16:13:26 -07:00
|
|
|
_SUBDOMAIN_RE = r'(?:(?:watch|iframe|customer-\w+)\.)?'
|
2020-01-08 14:42:53 -07:00
|
|
|
_DOMAIN_RE = r'(?:cloudflarestream\.com|(?:videodelivery|bytehighway)\.net)'
|
2024-06-20 16:05:25 -06:00
|
|
|
_EMBED_RE = rf'(?:embed\.|{_SUBDOMAIN_RE}){_DOMAIN_RE}/embed/[^/?#]+\.js\?(?:[^#]+&)?video='
|
|
|
|
_ID_RE = r'[\da-f]{32}|eyJ[\w-]+\.[\w-]+\.[\w-]+'
|
2024-02-24 16:13:26 -07:00
|
|
|
_VALID_URL = rf'https?://(?:{_SUBDOMAIN_RE}{_DOMAIN_RE}/|{_EMBED_RE})(?P<id>{_ID_RE})'
|
|
|
|
_EMBED_REGEX = [
|
2024-06-20 16:05:25 -06:00
|
|
|
rf'<script[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//{_EMBED_RE}(?:{_ID_RE})(?:(?!\1).)*)\1',
|
2024-02-24 16:13:26 -07:00
|
|
|
rf'<iframe[^>]+\bsrc=["\'](?P<url>https?://{_SUBDOMAIN_RE}{_DOMAIN_RE}/[\da-f]{{32}})',
|
|
|
|
]
|
2018-05-04 12:21:52 -06:00
|
|
|
_TESTS = [{
|
|
|
|
'url': 'https://embed.cloudflarestream.com/embed/we4g.fla9.latest.js?video=31c9291ab41fac05471db4e73aa11717',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '31c9291ab41fac05471db4e73aa11717',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': '31c9291ab41fac05471db4e73aa11717',
|
2024-02-24 16:13:26 -07:00
|
|
|
'thumbnail': 'https://videodelivery.net/31c9291ab41fac05471db4e73aa11717/thumbnails/thumbnail.jpg',
|
2018-05-04 12:21:52 -06:00
|
|
|
},
|
|
|
|
'params': {
|
2024-02-24 16:13:26 -07:00
|
|
|
'skip_download': 'm3u8',
|
2018-05-04 12:21:52 -06:00
|
|
|
},
|
2024-06-20 16:05:25 -06:00
|
|
|
}, {
|
|
|
|
'url': 'https://watch.cloudflarestream.com/embed/sdk-iframe-integration.fla9.latest.js?video=0e8e040aec776862e1d632a699edf59e',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '0e8e040aec776862e1d632a699edf59e',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': '0e8e040aec776862e1d632a699edf59e',
|
|
|
|
'thumbnail': 'https://videodelivery.net/0e8e040aec776862e1d632a699edf59e/thumbnails/thumbnail.jpg',
|
|
|
|
},
|
2018-05-04 12:21:52 -06:00
|
|
|
}, {
|
|
|
|
'url': 'https://watch.cloudflarestream.com/9df17203414fd1db3e3ed74abbe936c1',
|
|
|
|
'only_matching': True,
|
|
|
|
}, {
|
|
|
|
'url': 'https://cloudflarestream.com/31c9291ab41fac05471db4e73aa11717/manifest/video.mpd',
|
|
|
|
'only_matching': True,
|
2019-05-10 14:09:00 -06:00
|
|
|
}, {
|
|
|
|
'url': 'https://embed.videodelivery.net/embed/r4xu.fla9.latest.js?video=81d80727f3022488598f68d323c1ad5e',
|
|
|
|
'only_matching': True,
|
2024-02-24 15:02:13 -07:00
|
|
|
}, {
|
|
|
|
'url': 'https://customer-aw5py76sw8wyqzmh.cloudflarestream.com/2463f6d3e06fa29710a337f5f5389fd8/iframe',
|
|
|
|
'only_matching': True,
|
2024-06-20 16:05:25 -06:00
|
|
|
}, {
|
|
|
|
'url': 'https://watch.cloudflarestream.com/eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJraWQiOiJmYTA0YjViMzQ2NDkwYTM5NWJiNzQ1NWFhZTA2YzYwZSIsInN1YiI6Ijg4ZDQxMDhhMzY0MjA3M2VhYmFhZjg3ZGExODJkMjYzIiwiZXhwIjoxNjAwNjA5MzE5fQ.xkRJwLGkt0nZ%5F0BlPiwU7iW4pqb4lKkznbKfAhGg0tGcxSS6ZBA3lcTUwu7W%2DyCFbnAl%2Dhqk3Fn%5FqeQS%5FQydP27qTHpB9iIFFsMtk1tqzGZV5v4yrYDnwLSKzEKvVd6QwJnfABtxH2JdpSNuWlMUiVXFxGWgjOw6QeTNDDklTQYXV%5FNLV7sErSn5CeOPeRRkdXb%2D8ip%5FVOcfk1nDsFoOo4fctFtGP0wYMyY5ae8nhhatydHwevuvJCcEvEfh%2D4qjq9mCZOodevmtSQ4YWmggf4BxtWnDWYrGW8Otp6oqezrR8oY4%2DbKdV6PaqBj49aJdcls6xK7PmM8%5Fvjy3xfm0Mg',
|
|
|
|
'only_matching': True,
|
2018-05-04 12:21:52 -06:00
|
|
|
}]
|
2024-02-24 16:13:26 -07:00
|
|
|
_WEBPAGE_TESTS = [{
|
|
|
|
'url': 'https://upride.cc/incident/shoulder-pass-at-light/',
|
|
|
|
'info_dict': {
|
|
|
|
'id': 'eaef9dea5159cf968be84241b5cedfe7',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'eaef9dea5159cf968be84241b5cedfe7',
|
|
|
|
'thumbnail': 'https://videodelivery.net/eaef9dea5159cf968be84241b5cedfe7/thumbnails/thumbnail.jpg',
|
|
|
|
},
|
|
|
|
'params': {
|
|
|
|
'skip_download': 'm3u8',
|
|
|
|
},
|
|
|
|
}]
|
2018-05-04 12:21:52 -06:00
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
video_id = self._match_id(url)
|
2020-01-08 14:42:53 -07:00
|
|
|
domain = 'bytehighway.net' if 'bytehighway.net/' in url else 'videodelivery.net'
|
2024-06-11 17:09:58 -06:00
|
|
|
base_url = f'https://{domain}/{video_id}/'
|
2020-01-08 14:42:53 -07:00
|
|
|
if '.' in video_id:
|
|
|
|
video_id = self._parse_json(base64.urlsafe_b64decode(
|
2022-07-30 04:57:54 -06:00
|
|
|
video_id.split('.')[1] + '==='), video_id)['sub']
|
2020-01-08 14:42:53 -07:00
|
|
|
manifest_base_url = base_url + 'manifest/video.'
|
2018-05-04 12:21:52 -06:00
|
|
|
|
2024-01-18 14:20:04 -07:00
|
|
|
formats, subtitles = self._extract_m3u8_formats_and_subtitles(
|
2020-01-08 14:42:53 -07:00
|
|
|
manifest_base_url + 'm3u8', video_id, 'mp4',
|
|
|
|
'm3u8_native', m3u8_id='hls', fatal=False)
|
2024-01-18 14:20:04 -07:00
|
|
|
fmts, subs = self._extract_mpd_formats_and_subtitles(
|
|
|
|
manifest_base_url + 'mpd', video_id, mpd_id='dash', fatal=False)
|
|
|
|
formats.extend(fmts)
|
|
|
|
self._merge_subtitles(subs, target=subtitles)
|
2018-05-04 12:21:52 -06:00
|
|
|
|
|
|
|
return {
|
|
|
|
'id': video_id,
|
|
|
|
'title': video_id,
|
2020-01-08 14:42:53 -07:00
|
|
|
'thumbnail': base_url + 'thumbnails/thumbnail.jpg',
|
2018-05-04 12:21:52 -06:00
|
|
|
'formats': formats,
|
2024-01-18 14:20:04 -07:00
|
|
|
'subtitles': subtitles,
|
2018-05-04 12:21:52 -06:00
|
|
|
}
|