You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.9 KiB

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