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.

63 lines
1.8 KiB

  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. float_or_none,
  8. )
  9. class VzaarIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:(?:www|view)\.)?vzaar\.com/(?:videos/)?(?P<id>\d+)'
  11. _TESTS = [{
  12. 'url': 'https://vzaar.com/videos/1152805',
  13. 'md5': 'bde5ddfeb104a6c56a93a06b04901dbf',
  14. 'info_dict': {
  15. 'id': '1152805',
  16. 'ext': 'mp4',
  17. 'title': 'sample video (public)',
  18. },
  19. }, {
  20. 'url': 'https://view.vzaar.com/27272/player',
  21. 'md5': '3b50012ac9bbce7f445550d54e0508f2',
  22. 'info_dict': {
  23. 'id': '27272',
  24. 'ext': 'mp3',
  25. 'title': 'MP3',
  26. },
  27. }]
  28. @staticmethod
  29. def _extract_urls(webpage):
  30. return re.findall(
  31. r'<iframe[^>]+src=["\']((?:https?:)?//(?:view\.vzaar\.com)/[0-9]+)',
  32. webpage)
  33. def _real_extract(self, url):
  34. video_id = self._match_id(url)
  35. video_data = self._download_json(
  36. 'http://view.vzaar.com/v2/%s/video' % video_id, video_id)
  37. source_url = video_data['sourceUrl']
  38. info = {
  39. 'id': video_id,
  40. 'title': video_data['videoTitle'],
  41. 'url': source_url,
  42. 'thumbnail': self._proto_relative_url(video_data.get('poster')),
  43. 'duration': float_or_none(video_data.get('videoDuration')),
  44. }
  45. if 'audio' in source_url:
  46. info.update({
  47. 'vcodec': 'none',
  48. 'ext': 'mp3',
  49. })
  50. else:
  51. info.update({
  52. 'width': int_or_none(video_data.get('width')),
  53. 'height': int_or_none(video_data.get('height')),
  54. 'ext': 'mp4',
  55. })
  56. return info