logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

ninecninemedia.py (3772B)


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