vimple.py 1.8 KB

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