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.

101 lines
3.6 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. _TESTS = [{
  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. 'url': 'http://www.hotstar.com/sports/cricket/rajitha-sizzles-on-debut-with-329/2001477583',
  28. 'only_matching': True,
  29. }, {
  30. 'url': 'http://www.hotstar.com/1000000515',
  31. 'only_matching': True,
  32. }]
  33. def _download_json(self, url_or_request, video_id, note='Downloading JSON metadata', fatal=True, query=None):
  34. json_data = super(HotStarIE, self)._download_json(
  35. url_or_request, video_id, note, fatal=fatal, query=query)
  36. if json_data['resultCode'] != 'OK':
  37. if fatal:
  38. raise ExtractorError(json_data['errorDescription'])
  39. return None
  40. return json_data['resultObj']
  41. def _real_extract(self, url):
  42. video_id = self._match_id(url)
  43. video_data = self._download_json(
  44. 'http://account.hotstar.com/AVS/besc', video_id, query={
  45. 'action': 'GetAggregatedContentDetails',
  46. 'channel': 'PCTV',
  47. 'contentId': video_id,
  48. })['contentInfo'][0]
  49. title = video_data['episodeTitle']
  50. if video_data.get('encrypted') == 'Y':
  51. raise ExtractorError('This video is DRM protected.', expected=True)
  52. formats = []
  53. for f in ('JIO',):
  54. format_data = self._download_json(
  55. 'http://getcdn.hotstar.com/AVS/besc',
  56. video_id, 'Downloading %s JSON metadata' % f,
  57. fatal=False, query={
  58. 'action': 'GetCDN',
  59. 'asJson': 'Y',
  60. 'channel': f,
  61. 'id': video_id,
  62. 'type': 'VOD',
  63. })
  64. if format_data:
  65. format_url = format_data.get('src')
  66. if not format_url:
  67. continue
  68. ext = determine_ext(format_url)
  69. if ext == 'm3u8':
  70. formats.extend(self._extract_m3u8_formats(
  71. format_url, video_id, 'mp4',
  72. m3u8_id='hls', fatal=False))
  73. elif ext == 'f4m':
  74. # produce broken files
  75. continue
  76. else:
  77. formats.append({
  78. 'url': format_url,
  79. 'width': int_or_none(format_data.get('width')),
  80. 'height': int_or_none(format_data.get('height')),
  81. })
  82. self._sort_formats(formats)
  83. return {
  84. 'id': video_id,
  85. 'title': title,
  86. 'description': video_data.get('description'),
  87. 'duration': int_or_none(video_data.get('duration')),
  88. 'timestamp': int_or_none(video_data.get('broadcastDate')),
  89. 'formats': formats,
  90. 'episode': title,
  91. 'episode_number': int_or_none(video_data.get('episodeNumber')),
  92. 'series': video_data.get('contentTitle'),
  93. }