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.

60 lines
2.0 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/|
  10. embed\.cloudflarestream\.com/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. @staticmethod
  32. def _extract_urls(webpage):
  33. return [
  34. mobj.group('url')
  35. for mobj in re.finditer(
  36. r'<script[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//embed\.cloudflarestream\.com/embed/[^/]+\.js\?.*?\bvideo=[\da-f]+?.*?)\1',
  37. webpage)]
  38. def _real_extract(self, url):
  39. video_id = self._match_id(url)
  40. formats = self._extract_m3u8_formats(
  41. 'https://cloudflarestream.com/%s/manifest/video.m3u8' % video_id,
  42. video_id, 'mp4', entry_protocol='m3u8_native', m3u8_id='hls',
  43. fatal=False)
  44. formats.extend(self._extract_mpd_formats(
  45. 'https://cloudflarestream.com/%s/manifest/video.mpd' % video_id,
  46. video_id, mpd_id='dash', fatal=False))
  47. self._sort_formats(formats)
  48. return {
  49. 'id': video_id,
  50. 'title': video_id,
  51. 'formats': formats,
  52. }