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.

55 lines
2.1 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. parse_duration,
  8. ExtractorError
  9. )
  10. class NineCNineMediaIE(InfoExtractor):
  11. _VALID_URL = r'9c9media:(?P<destination_code>[^:]+):(?P<id>\d+)'
  12. def _real_extract(self, url):
  13. destination_code, video_id = re.match(self._VALID_URL, url).groups()
  14. api_base_url = 'http://capi.9c9media.com/destinations/%s/platforms/desktop/contents/%s/' % (destination_code, video_id)
  15. content = self._download_json(api_base_url, video_id, query={
  16. '$include': '[contentpackages]',
  17. })
  18. title = content['Name']
  19. if len(content['ContentPackages']) > 1:
  20. raise ExtractorError('multiple content packages')
  21. content_package = content['ContentPackages'][0]
  22. stacks_base_url = api_base_url + 'contentpackages/%s/stacks/' % content_package['Id']
  23. stacks = self._download_json(stacks_base_url, video_id)['Items']
  24. if len(stacks) > 1:
  25. raise ExtractorError('multiple stacks')
  26. stack = stacks[0]
  27. stack_base_url = '%s%s/manifest.' % (stacks_base_url, stack['Id'])
  28. formats = []
  29. formats.extend(self._extract_m3u8_formats(
  30. stack_base_url + 'm3u8', video_id, 'mp4',
  31. 'm3u8_native', m3u8_id='hls', fatal=False))
  32. formats.extend(self._extract_f4m_formats(
  33. stack_base_url + 'f4m', video_id,
  34. f4m_id='hds', fatal=False))
  35. mp4_url = self._download_webpage(stack_base_url + 'pd', video_id, fatal=False)
  36. if mp4_url:
  37. formats.append({
  38. 'url': mp4_url,
  39. 'format_id': 'mp4',
  40. })
  41. self._sort_formats(formats)
  42. return {
  43. 'id': video_id,
  44. 'title': title,
  45. 'description': content.get('Desc') or content.get('ShortDesc'),
  46. 'timestamp': parse_iso8601(content.get('BroadcastDateTime')),
  47. 'duration': parse_duration(content.get('BroadcastTime')),
  48. 'formats': formats,
  49. }