You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.2 KiB

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