logo

youtube-dl

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

clipchamp.py (2630B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import compat_str
  5. from ..utils import (
  6. ExtractorError,
  7. merge_dicts,
  8. T,
  9. traverse_obj,
  10. unified_timestamp,
  11. url_or_none,
  12. )
  13. class ClipchampIE(InfoExtractor):
  14. _VALID_URL = r'https?://(?:www\.)?clipchamp\.com/watch/(?P<id>[\w-]+)'
  15. _TESTS = [{
  16. 'url': 'https://clipchamp.com/watch/gRXZ4ZhdDaU',
  17. 'info_dict': {
  18. 'id': 'gRXZ4ZhdDaU',
  19. 'ext': 'mp4',
  20. 'title': 'Untitled video',
  21. 'uploader': 'Alexander Schwartz',
  22. 'timestamp': 1680805580,
  23. 'upload_date': '20230406',
  24. 'thumbnail': r're:^https?://.+\.jpg',
  25. },
  26. 'params': {
  27. 'skip_download': 'm3u8',
  28. 'format': 'bestvideo',
  29. },
  30. }]
  31. _STREAM_URL_TMPL = 'https://%s.cloudflarestream.com/%s/manifest/video.%s'
  32. _STREAM_URL_QUERY = {'parentOrigin': 'https://clipchamp.com'}
  33. def _real_extract(self, url):
  34. video_id = self._match_id(url)
  35. webpage = self._download_webpage(url, video_id)
  36. data = self._search_nextjs_data(webpage, video_id)['props']['pageProps']['video']
  37. storage_location = data.get('storage_location')
  38. if storage_location != 'cf_stream':
  39. raise ExtractorError('Unsupported clip storage location "%s"' % (storage_location,))
  40. path = data['download_url']
  41. iframe = self._download_webpage(
  42. 'https://iframe.cloudflarestream.com/' + path, video_id, 'Downloading player iframe')
  43. subdomain = self._search_regex(
  44. r'''\bcustomer-domain-prefix\s*=\s*("|')(?P<sd>[\w-]+)\1''', iframe,
  45. 'subdomain', group='sd', fatal=False) or 'customer-2ut9yn3y6fta1yxe'
  46. formats = self._extract_mpd_formats(
  47. self._STREAM_URL_TMPL % (subdomain, path, 'mpd'), video_id,
  48. query=self._STREAM_URL_QUERY, fatal=False, mpd_id='dash')
  49. formats.extend(self._extract_m3u8_formats(
  50. self._STREAM_URL_TMPL % (subdomain, path, 'm3u8'), video_id, 'mp4',
  51. query=self._STREAM_URL_QUERY, fatal=False, m3u8_id='hls'))
  52. return merge_dicts({
  53. 'id': video_id,
  54. 'formats': formats,
  55. 'uploader': ' '.join(traverse_obj(data, ('creator', ('first_name', 'last_name'), T(compat_str)))) or None,
  56. }, traverse_obj(data, {
  57. 'title': ('project', 'project_name', T(compat_str)),
  58. 'timestamp': ('created_at', T(unified_timestamp)),
  59. 'thumbnail': ('thumbnail_url', T(url_or_none)),
  60. }), rev=True)