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.

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