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.

79 lines
3.0 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. determine_ext,
  7. int_or_none,
  8. )
  9. class HotStarIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?hotstar\.com/.*?[/-](?P<id>\d{10})'
  11. _TEST = {
  12. 'url': 'http://www.hotstar.com/on-air-with-aib--english-1000076273',
  13. 'info_dict': {
  14. 'id': '1000076273',
  15. 'ext': 'mp4',
  16. 'title': 'On Air With AIB - English',
  17. 'description': 'md5:c957d8868e9bc793ccb813691cc4c434',
  18. 'timestamp': 1447227000,
  19. 'upload_date': '20151111',
  20. 'duration': 381,
  21. },
  22. 'params': {
  23. # m3u8 download
  24. 'skip_download': True,
  25. }
  26. }
  27. _GET_CONTENT_TEMPLATE = 'http://account.hotstar.com/AVS/besc?action=GetAggregatedContentDetails&channel=PCTV&contentId=%s'
  28. _GET_CDN_TEMPLATE = 'http://getcdn.hotstar.com/AVS/besc?action=GetCDN&asJson=Y&channel=%s&id=%s&type=%s'
  29. def _download_json(self, url_or_request, video_id, note='Downloading JSON metadata', fatal=True):
  30. json_data = super(HotStarIE, self)._download_json(url_or_request, video_id, note, fatal=fatal)
  31. if json_data['resultCode'] != 'OK':
  32. if fatal:
  33. raise ExtractorError(json_data['errorDescription'])
  34. return None
  35. return json_data['resultObj']
  36. def _real_extract(self, url):
  37. video_id = self._match_id(url)
  38. video_data = self._download_json(
  39. self._GET_CONTENT_TEMPLATE % video_id,
  40. video_id)['contentInfo'][0]
  41. formats = []
  42. # PCTV for extracting f4m manifest
  43. for f in ('TABLET',):
  44. format_data = self._download_json(
  45. self._GET_CDN_TEMPLATE % (f, video_id, 'VOD'),
  46. video_id, 'Downloading %s JSON metadata' % f, fatal=False)
  47. if format_data:
  48. format_url = format_data['src']
  49. ext = determine_ext(format_url)
  50. if ext == 'm3u8':
  51. m3u8_formats = self._extract_m3u8_formats(format_url, video_id, 'mp4', m3u8_id='hls', fatal=False)
  52. if m3u8_formats:
  53. formats.extend(m3u8_formats)
  54. elif ext == 'f4m':
  55. # produce broken files
  56. continue
  57. else:
  58. formats.append({
  59. 'url': format_url,
  60. 'width': int_or_none(format_data.get('width')),
  61. 'height': int_or_none(format_data.get('height')),
  62. })
  63. self._sort_formats(formats)
  64. return {
  65. 'id': video_id,
  66. 'title': video_data['episodeTitle'],
  67. 'description': video_data.get('description'),
  68. 'duration': int_or_none(video_data.get('duration')),
  69. 'timestamp': int_or_none(video_data.get('broadcastDate')),
  70. 'formats': formats,
  71. }