viqeo.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. int_or_none,
  4. str_or_none,
  5. url_or_none,
  6. )
  7. class ViqeoIE(InfoExtractor):
  8. _WORKING = False
  9. _VALID_URL = r'''(?x)
  10. (?:
  11. viqeo:|
  12. https?://cdn\.viqeo\.tv/embed/*\?.*?\bvid=|
  13. https?://api\.viqeo\.tv/v\d+/data/startup?.*?\bvideo(?:%5B%5D|\[\])=
  14. )
  15. (?P<id>[\da-f]+)
  16. '''
  17. _EMBED_REGEX = [r'<iframe[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//cdn\.viqeo\.tv/embed/*\?.*?\bvid=[\da-f]+.*?)\1']
  18. _TESTS = [{
  19. 'url': 'https://cdn.viqeo.tv/embed/?vid=cde96f09d25f39bee837',
  20. 'md5': 'a169dd1a6426b350dca4296226f21e76',
  21. 'info_dict': {
  22. 'id': 'cde96f09d25f39bee837',
  23. 'ext': 'mp4',
  24. 'title': 'cde96f09d25f39bee837',
  25. 'thumbnail': r're:^https?://.*\.jpg$',
  26. 'duration': 76,
  27. },
  28. }, {
  29. 'url': 'viqeo:cde96f09d25f39bee837',
  30. 'only_matching': True,
  31. }, {
  32. 'url': 'https://api.viqeo.tv/v1/data/startup?video%5B%5D=71bbec412ade45c3216c&profile=112',
  33. 'only_matching': True,
  34. }]
  35. def _real_extract(self, url):
  36. video_id = self._match_id(url)
  37. webpage = self._download_webpage(
  38. f'https://cdn.viqeo.tv/embed/?vid={video_id}', video_id)
  39. data = self._parse_json(
  40. self._search_regex(
  41. r'SLOT_DATA\s*=\s*({.+?})\s*;', webpage, 'slot data'),
  42. video_id)
  43. formats = []
  44. thumbnails = []
  45. for media_file in data['mediaFiles']:
  46. if not isinstance(media_file, dict):
  47. continue
  48. media_url = url_or_none(media_file.get('url'))
  49. if not media_url or not media_url.startswith(('http', '//')):
  50. continue
  51. media_type = str_or_none(media_file.get('type'))
  52. if not media_type:
  53. continue
  54. media_kind = media_type.split('/')[0].lower()
  55. f = {
  56. 'url': media_url,
  57. 'width': int_or_none(media_file.get('width')),
  58. 'height': int_or_none(media_file.get('height')),
  59. }
  60. format_id = str_or_none(media_file.get('quality'))
  61. if media_kind == 'image':
  62. f['id'] = format_id
  63. thumbnails.append(f)
  64. elif media_kind in ('video', 'audio'):
  65. is_audio = media_kind == 'audio'
  66. f.update({
  67. 'format_id': 'audio' if is_audio else format_id,
  68. 'fps': int_or_none(media_file.get('fps')),
  69. 'vcodec': 'none' if is_audio else None,
  70. })
  71. formats.append(f)
  72. duration = int_or_none(data.get('duration'))
  73. return {
  74. 'id': video_id,
  75. 'title': video_id,
  76. 'duration': duration,
  77. 'thumbnails': thumbnails,
  78. 'formats': formats,
  79. }