logo

youtube-dl

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

viqeo.py (3298B)


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