logo

youtube-dl

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

vzaar.py (3611B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_str
  6. from ..utils import (
  7. int_or_none,
  8. float_or_none,
  9. unified_timestamp,
  10. url_or_none,
  11. )
  12. class VzaarIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:(?:www|view)\.)?vzaar\.com/(?:videos/)?(?P<id>\d+)'
  14. _TESTS = [{
  15. # HTTP and HLS
  16. 'url': 'https://vzaar.com/videos/1152805',
  17. 'md5': 'bde5ddfeb104a6c56a93a06b04901dbf',
  18. 'info_dict': {
  19. 'id': '1152805',
  20. 'ext': 'mp4',
  21. 'title': 'sample video (public)',
  22. },
  23. }, {
  24. 'url': 'https://view.vzaar.com/27272/player',
  25. 'md5': '3b50012ac9bbce7f445550d54e0508f2',
  26. 'info_dict': {
  27. 'id': '27272',
  28. 'ext': 'mp3',
  29. 'title': 'MP3',
  30. },
  31. }, {
  32. # hlsAes = true
  33. 'url': 'https://view.vzaar.com/11379930/player',
  34. 'info_dict': {
  35. 'id': '11379930',
  36. 'ext': 'mp4',
  37. 'title': 'Videoaula',
  38. },
  39. 'params': {
  40. # m3u8 download
  41. 'skip_download': True,
  42. },
  43. }, {
  44. # with null videoTitle
  45. 'url': 'https://view.vzaar.com/20313539/download',
  46. 'only_matching': True,
  47. }]
  48. @staticmethod
  49. def _extract_urls(webpage):
  50. return re.findall(
  51. r'<iframe[^>]+src=["\']((?:https?:)?//(?:view\.vzaar\.com)/[0-9]+)',
  52. webpage)
  53. def _real_extract(self, url):
  54. video_id = self._match_id(url)
  55. video_data = self._download_json(
  56. 'http://view.vzaar.com/v2/%s/video' % video_id, video_id)
  57. title = video_data.get('videoTitle') or video_id
  58. formats = []
  59. source_url = url_or_none(video_data.get('sourceUrl'))
  60. if source_url:
  61. f = {
  62. 'url': source_url,
  63. 'format_id': 'http',
  64. 'preference': 1,
  65. }
  66. if 'audio' in source_url:
  67. f.update({
  68. 'vcodec': 'none',
  69. 'ext': 'mp3',
  70. })
  71. else:
  72. f.update({
  73. 'width': int_or_none(video_data.get('width')),
  74. 'height': int_or_none(video_data.get('height')),
  75. 'ext': 'mp4',
  76. 'fps': float_or_none(video_data.get('fps')),
  77. })
  78. formats.append(f)
  79. video_guid = video_data.get('guid')
  80. usp = video_data.get('usp')
  81. if video_data.get('uspEnabled') and isinstance(video_guid, compat_str) and isinstance(usp, dict):
  82. hls_aes = video_data.get('hlsAes')
  83. qs = '&'.join('%s=%s' % (k, v) for k, v in usp.items())
  84. url_templ = 'http://%%s.vzaar.com/v5/usp%s/%s/%s.ism%%s?' % ('aes' if hls_aes else '', video_guid, video_id)
  85. m3u8_formats = self._extract_m3u8_formats(
  86. url_templ % ('fable', '/.m3u8') + qs, video_id, 'mp4', 'm3u8_native',
  87. m3u8_id='hls', fatal=False)
  88. if hls_aes:
  89. for f in m3u8_formats:
  90. f['_decryption_key_url'] = url_templ % ('goose', '') + qs
  91. formats.extend(m3u8_formats)
  92. self._sort_formats(formats)
  93. return {
  94. 'id': video_id,
  95. 'title': title,
  96. 'thumbnail': self._proto_relative_url(video_data.get('poster')),
  97. 'duration': float_or_none(video_data.get('videoDuration')),
  98. 'timestamp': unified_timestamp(video_data.get('ts')),
  99. 'formats': formats,
  100. }