veo.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. int_or_none,
  4. mimetype2ext,
  5. str_or_none,
  6. unified_timestamp,
  7. url_or_none,
  8. )
  9. class VeoIE(InfoExtractor):
  10. _VALID_URL = r'https?://app\.veo\.co/matches/(?P<id>[0-9A-Za-z-_]+)'
  11. _TESTS = [{
  12. 'url': 'https://app.veo.co/matches/20201027-last-period/',
  13. 'info_dict': {
  14. 'id': '20201027-last-period',
  15. 'ext': 'mp4',
  16. 'title': 'Akidemy u11s v Bradford Boys u11s (Game 3)',
  17. 'thumbnail': 're:https://c.veocdn.com/.+/thumbnail.jpg',
  18. 'upload_date': '20201028',
  19. 'timestamp': 1603847208,
  20. 'duration': 1916,
  21. 'view_count': int,
  22. },
  23. }, {
  24. 'url': 'https://app.veo.co/matches/20220313-2022-03-13_u15m-plsjq-vs-csl/',
  25. 'only_matching': True,
  26. }]
  27. def _real_extract(self, url):
  28. video_id = self._match_id(url)
  29. metadata = self._download_json(
  30. f'https://app.veo.co/api/app/matches/{video_id}', video_id)
  31. video_data = self._download_json(
  32. f'https://app.veo.co/api/app/matches/{video_id}/videos', video_id, 'Downloading video data')
  33. formats = []
  34. for fmt in video_data:
  35. mimetype = str_or_none(fmt.get('mime_type'))
  36. format_url = url_or_none(fmt.get('url'))
  37. # skip configuration file for panoramic video
  38. if not format_url or mimetype == 'video/mp2t':
  39. continue
  40. height = int_or_none(fmt.get('height'))
  41. render_type = str_or_none(fmt.get('render_type'))
  42. format_id = f'{render_type}-{height}p' if render_type and height else None
  43. # Veo returns panoramic video information even if panoramic video is not available.
  44. # e.g. https://app.veo.co/matches/20201027-last-period/
  45. if render_type == 'panorama':
  46. if not self._is_valid_url(format_url, video_id, format_id):
  47. continue
  48. formats.append({
  49. 'url': format_url,
  50. 'format_id': format_id,
  51. 'ext': mimetype2ext(mimetype),
  52. 'width': int_or_none(fmt.get('width')),
  53. 'height': height,
  54. 'vbr': int_or_none(fmt.get('bit_rate'), scale=1000),
  55. })
  56. return {
  57. 'id': video_id,
  58. 'title': str_or_none(metadata.get('title')),
  59. 'formats': formats,
  60. 'thumbnail': url_or_none(metadata.get('thumbnail')),
  61. 'timestamp': unified_timestamp(metadata.get('created')),
  62. 'view_count': int_or_none(metadata.get('view_count')),
  63. 'duration': int_or_none(metadata.get('duration')),
  64. }