vzaar.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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/10165560/player',
  34. 'md5': '5f66f121fb28b9d16cce3d4f3df7e72e',
  35. 'info_dict': {
  36. 'id': '10165560',
  37. 'ext': 'mp4',
  38. 'title': 'Video Demo vzaar Secure.mp4',
  39. },
  40. }, {
  41. # with null videoTitle
  42. 'url': 'https://view.vzaar.com/20313539/download',
  43. 'only_matching': True,
  44. }]
  45. @staticmethod
  46. def _extract_urls(webpage):
  47. return re.findall(
  48. r'<iframe[^>]+src=["\']((?:https?:)?//(?:view\.vzaar\.com)/[0-9]+)',
  49. webpage)
  50. def _real_extract(self, url):
  51. video_id = self._match_id(url)
  52. video_data = self._download_json(
  53. 'http://view.vzaar.com/v2/%s/video' % video_id, video_id)
  54. title = video_data.get('videoTitle') or video_id
  55. formats = []
  56. source_url = url_or_none(video_data.get('sourceUrl'))
  57. if source_url:
  58. f = {
  59. 'url': source_url,
  60. 'format_id': 'http',
  61. 'preference': 1,
  62. }
  63. if 'audio' in source_url:
  64. f.update({
  65. 'vcodec': 'none',
  66. 'ext': 'mp3',
  67. })
  68. else:
  69. f.update({
  70. 'width': int_or_none(video_data.get('width')),
  71. 'height': int_or_none(video_data.get('height')),
  72. 'ext': 'mp4',
  73. 'fps': float_or_none(video_data.get('fps')),
  74. })
  75. formats.append(f)
  76. video_guid = video_data.get('guid')
  77. usp = video_data.get('usp')
  78. if video_data.get('uspEnabled') and isinstance(video_guid, compat_str) and isinstance(usp, dict):
  79. hls_aes = video_data.get('hlsAes')
  80. qs = '&'.join('%s=%s' % (k, v) for k, v in usp.items())
  81. url_templ = 'http://%%s.vzaar.com/v5/usp%s/%s/%s.ism%%s?' % ('aes' if hls_aes else '', video_guid, video_id)
  82. m3u8_formats = self._extract_m3u8_formats(
  83. url_templ % ('fable', '/.m3u8') + qs, video_id, 'mp4', 'm3u8_native',
  84. m3u8_id='hls', fatal=False)
  85. if hls_aes:
  86. for f in m3u8_formats:
  87. f['_decryption_key_url'] = url_templ % ('goose', '') + qs
  88. formats.extend(m3u8_formats)
  89. self._sort_formats(formats)
  90. return {
  91. 'id': video_id,
  92. 'title': title,
  93. 'thumbnail': self._proto_relative_url(video_data.get('poster')),
  94. 'duration': float_or_none(video_data.get('videoDuration')),
  95. 'timestamp': unified_timestamp(video_data.get('ts')),
  96. 'formats': formats,
  97. }