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.

102 lines
3.7 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. parse_iso8601,
  7. float_or_none,
  8. ExtractorError,
  9. int_or_none,
  10. )
  11. class NineCNineMediaIE(InfoExtractor):
  12. IE_NAME = '9c9media'
  13. _GEO_COUNTRIES = ['CA']
  14. _VALID_URL = r'9c9media:(?P<destination_code>[^:]+):(?P<id>\d+)'
  15. _API_BASE_TEMPLATE = 'http://capi.9c9media.com/destinations/%s/platforms/desktop/contents/%s/'
  16. def _real_extract(self, url):
  17. destination_code, content_id = re.match(self._VALID_URL, url).groups()
  18. api_base_url = self._API_BASE_TEMPLATE % (destination_code, content_id)
  19. content = self._download_json(api_base_url, content_id, query={
  20. '$include': '[Media,Season,ContentPackages]',
  21. })
  22. title = content['Name']
  23. if len(content['ContentPackages']) > 1:
  24. raise ExtractorError('multiple content packages')
  25. content_package = content['ContentPackages'][0]
  26. package_id = content_package['Id']
  27. content_package_url = api_base_url + 'contentpackages/%s/' % package_id
  28. content_package = self._download_json(
  29. content_package_url, content_id, query={
  30. '$include': '[HasClosedCaptions]',
  31. })
  32. if content_package.get('Constraints', {}).get('Security', {}).get('Type'):
  33. raise ExtractorError('This video is DRM protected.', expected=True)
  34. manifest_base_url = content_package_url + 'manifest.'
  35. formats = []
  36. formats.extend(self._extract_m3u8_formats(
  37. manifest_base_url + 'm3u8', content_id, 'mp4',
  38. 'm3u8_native', m3u8_id='hls', fatal=False))
  39. formats.extend(self._extract_f4m_formats(
  40. manifest_base_url + 'f4m', content_id,
  41. f4m_id='hds', fatal=False))
  42. formats.extend(self._extract_mpd_formats(
  43. manifest_base_url + 'mpd', content_id,
  44. mpd_id='dash', fatal=False))
  45. self._sort_formats(formats)
  46. thumbnails = []
  47. for image in content.get('Images', []):
  48. image_url = image.get('Url')
  49. if not image_url:
  50. continue
  51. thumbnails.append({
  52. 'url': image_url,
  53. 'width': int_or_none(image.get('Width')),
  54. 'height': int_or_none(image.get('Height')),
  55. })
  56. tags, categories = [], []
  57. for source_name, container in (('Tags', tags), ('Genres', categories)):
  58. for e in content.get(source_name, []):
  59. e_name = e.get('Name')
  60. if not e_name:
  61. continue
  62. container.append(e_name)
  63. season = content.get('Season', {})
  64. info = {
  65. 'id': content_id,
  66. 'title': title,
  67. 'description': content.get('Desc') or content.get('ShortDesc'),
  68. 'timestamp': parse_iso8601(content.get('BroadcastDateTime')),
  69. 'episode_number': int_or_none(content.get('Episode')),
  70. 'season': season.get('Name'),
  71. 'season_number': season.get('Number'),
  72. 'season_id': season.get('Id'),
  73. 'series': content.get('Media', {}).get('Name'),
  74. 'tags': tags,
  75. 'categories': categories,
  76. 'duration': float_or_none(content_package.get('Duration')),
  77. 'formats': formats,
  78. }
  79. if content_package.get('HasClosedCaptions'):
  80. info['subtitles'] = {
  81. 'en': [{
  82. 'url': manifest_base_url + 'vtt',
  83. 'ext': 'vtt',
  84. }, {
  85. 'url': manifest_base_url + 'srt',
  86. 'ext': 'srt',
  87. }]
  88. }
  89. return info