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.

83 lines
3.1 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. _GET_CONTENT_TEMPLATE = 'http://account.hotstar.com/AVS/besc?action=GetAggregatedContentDetails&channel=PCTV&contentId=%s'
  34. _GET_CDN_TEMPLATE = 'http://getcdn.hotstar.com/AVS/besc?action=GetCDN&asJson=Y&channel=%s&id=%s&type=%s'
  35. def _download_json(self, url_or_request, video_id, note='Downloading JSON metadata', fatal=True):
  36. json_data = super(HotStarIE, self)._download_json(url_or_request, video_id, note, fatal=fatal)
  37. if json_data['resultCode'] != 'OK':
  38. if fatal:
  39. raise ExtractorError(json_data['errorDescription'])
  40. return None
  41. return json_data['resultObj']
  42. def _real_extract(self, url):
  43. video_id = self._match_id(url)
  44. video_data = self._download_json(
  45. self._GET_CONTENT_TEMPLATE % video_id,
  46. video_id)['contentInfo'][0]
  47. formats = []
  48. # PCTV for extracting f4m manifest
  49. for f in ('TABLET',):
  50. format_data = self._download_json(
  51. self._GET_CDN_TEMPLATE % (f, video_id, 'VOD'),
  52. video_id, 'Downloading %s JSON metadata' % f, fatal=False)
  53. if format_data:
  54. format_url = format_data['src']
  55. ext = determine_ext(format_url)
  56. if ext == 'm3u8':
  57. formats.extend(self._extract_m3u8_formats(format_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
  58. elif ext == 'f4m':
  59. # produce broken files
  60. continue
  61. else:
  62. formats.append({
  63. 'url': format_url,
  64. 'width': int_or_none(format_data.get('width')),
  65. 'height': int_or_none(format_data.get('height')),
  66. })
  67. self._sort_formats(formats)
  68. return {
  69. 'id': video_id,
  70. 'title': video_data['episodeTitle'],
  71. 'description': video_data.get('description'),
  72. 'duration': int_or_none(video_data.get('duration')),
  73. 'timestamp': int_or_none(video_data.get('broadcastDate')),
  74. 'formats': formats,
  75. }