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