logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

cloudflarestream.py (2677B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import base64
  4. import re
  5. from .common import InfoExtractor
  6. class CloudflareStreamIE(InfoExtractor):
  7. _DOMAIN_RE = r'(?:cloudflarestream\.com|(?:videodelivery|bytehighway)\.net)'
  8. _EMBED_RE = r'embed\.%s/embed/[^/]+\.js\?.*?\bvideo=' % _DOMAIN_RE
  9. _ID_RE = r'[\da-f]{32}|[\w-]+\.[\w-]+\.[\w-]+'
  10. _VALID_URL = r'''(?x)
  11. https?://
  12. (?:
  13. (?:watch\.)?%s/|
  14. %s
  15. )
  16. (?P<id>%s)
  17. ''' % (_DOMAIN_RE, _EMBED_RE, _ID_RE)
  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. 'url': 'https://embed.videodelivery.net/embed/r4xu.fla9.latest.js?video=81d80727f3022488598f68d323c1ad5e',
  36. 'only_matching': True,
  37. }]
  38. @staticmethod
  39. def _extract_urls(webpage):
  40. return [
  41. mobj.group('url')
  42. for mobj in re.finditer(
  43. r'<script[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//%s(?:%s).*?)\1' % (CloudflareStreamIE._EMBED_RE, CloudflareStreamIE._ID_RE),
  44. webpage)]
  45. def _real_extract(self, url):
  46. video_id = self._match_id(url)
  47. domain = 'bytehighway.net' if 'bytehighway.net/' in url else 'videodelivery.net'
  48. base_url = 'https://%s/%s/' % (domain, video_id)
  49. if '.' in video_id:
  50. video_id = self._parse_json(base64.urlsafe_b64decode(
  51. video_id.split('.')[1]), video_id)['sub']
  52. manifest_base_url = base_url + 'manifest/video.'
  53. formats = self._extract_m3u8_formats(
  54. manifest_base_url + 'm3u8', video_id, 'mp4',
  55. 'm3u8_native', m3u8_id='hls', fatal=False)
  56. formats.extend(self._extract_mpd_formats(
  57. manifest_base_url + 'mpd', video_id, mpd_id='dash', fatal=False))
  58. self._sort_formats(formats)
  59. return {
  60. 'id': video_id,
  61. 'title': video_id,
  62. 'thumbnail': base_url + 'thumbnails/thumbnail.jpg',
  63. 'formats': formats,
  64. }