clipchamp.py 2.4 KB

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