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.

60 lines
1.9 KiB

  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..utils import int_or_none
  4. class SprutoBaseIE(InfoExtractor):
  5. def _extract_spruto(self, spruto, video_id):
  6. playlist = spruto['playlist'][0]
  7. title = playlist['title']
  8. video_id = playlist.get('videoId') or video_id
  9. thumbnail = playlist.get('posterUrl') or playlist.get('thumbnailUrl')
  10. duration = int_or_none(playlist.get('duration'))
  11. formats = [{
  12. 'url': f['url'],
  13. } for f in playlist['video']]
  14. self._sort_formats(formats)
  15. return {
  16. 'id': video_id,
  17. 'title': title,
  18. 'thumbnail': thumbnail,
  19. 'duration': duration,
  20. 'formats': formats,
  21. }
  22. class VimpleIE(SprutoBaseIE):
  23. IE_DESC = 'Vimple - one-click video hosting'
  24. _VALID_URL = r'https?://(?:player\.vimple\.ru/iframe|vimple\.ru)/(?P<id>[\da-f-]{32,36})'
  25. _TESTS = [
  26. {
  27. 'url': 'http://vimple.ru/c0f6b1687dcd4000a97ebe70068039cf',
  28. 'md5': '2e750a330ed211d3fd41821c6ad9a279',
  29. 'info_dict': {
  30. 'id': 'c0f6b168-7dcd-4000-a97e-be70068039cf',
  31. 'ext': 'mp4',
  32. 'title': 'Sunset',
  33. 'duration': 20,
  34. 'thumbnail': 're:https?://.*?\.jpg',
  35. },
  36. }, {
  37. 'url': 'http://player.vimple.ru/iframe/52e1beec-1314-4a83-aeac-c61562eadbf9',
  38. 'only_matching': True,
  39. }
  40. ]
  41. def _real_extract(self, url):
  42. video_id = self._match_id(url)
  43. webpage = self._download_webpage(
  44. 'http://player.vimple.ru/iframe/%s' % video_id, video_id)
  45. spruto = self._parse_json(
  46. self._search_regex(
  47. r'sprutoData\s*:\s*({.+?}),\r\n', webpage, 'spruto data'),
  48. video_id)
  49. return self._extract_spruto(spruto, video_id)