2
0

voot.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. class VootIE(InfoExtractor):
  5. _VALID_URL = r'https?://(?:www\.)?voot\.com/shows/(?:.+?[/-]?)/1/(?:.+?[0-9]?)/(?:.+?[/-]?)/(?P<id>[0-9]+)'
  6. _TEST = {
  7. 'url': 'https://www.voot.com/shows/ishq-ka-rang-safed/1/360558/is-this-the-end-of-kamini-/441353',
  8. 'info_dict': {
  9. 'id': '441353',
  10. 'ext': 'mp4',
  11. 'title': 'Ishq Ka Rang Safed - Season 01 - Episode 340',
  12. 'thumbnail': r're:^https?://.*\.jpg$',
  13. }
  14. }
  15. _GET_CONTENT_TEMPLATE = 'https://wapi.voot.com/ws/ott/getMediaInfo.json?platform=Web&pId=3&mediaId=%s'
  16. def _download_json(self, url_or_request, video_id, note='Downloading JSON metadata', fatal=True):
  17. json_data = super(VootIE, self)._download_json(url_or_request, video_id, note, fatal=fatal)
  18. if json_data['status']['code'] != 0:
  19. if fatal:
  20. raise ExtractorError(json_data['status']['message'])
  21. return None
  22. return json_data['assets']
  23. def _real_extract(self, url):
  24. video_id = self._match_id(url)
  25. video_data = self._download_json(
  26. self._GET_CONTENT_TEMPLATE % video_id,
  27. video_id)
  28. thumbnail = ''
  29. formats = []
  30. if video_data:
  31. format_url = video_data.get('URL')
  32. formats.extend(self._extract_m3u8_formats(format_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
  33. if video_data['Pictures']:
  34. for picture in video_data['Pictures']:
  35. #Get only first available thumbnail
  36. thumbnail = picture.get('URL')
  37. break
  38. self._sort_formats(formats)
  39. return {
  40. 'id': video_id,
  41. 'title': video_data.get('MediaName'),
  42. 'thumbnail': thumbnail,
  43. 'formats':formats,
  44. }