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.

183 lines
7.0 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from .adobepass import AdobePassIE
  5. from .theplatform import ThePlatformIE
  6. from ..utils import (
  7. smuggle_url,
  8. url_basename,
  9. update_url_query,
  10. get_element_by_class,
  11. )
  12. class NationalGeographicVideoIE(InfoExtractor):
  13. IE_NAME = 'natgeo:video'
  14. _VALID_URL = r'https?://video\.nationalgeographic\.com/.*?'
  15. _TESTS = [
  16. {
  17. 'url': 'http://video.nationalgeographic.com/video/news/150210-news-crab-mating-vin?source=featuredvideo',
  18. 'md5': '730855d559abbad6b42c2be1fa584917',
  19. 'info_dict': {
  20. 'id': '0000014b-70a1-dd8c-af7f-f7b559330001',
  21. 'ext': 'mp4',
  22. 'title': 'Mating Crabs Busted by Sharks',
  23. 'description': 'md5:16f25aeffdeba55aaa8ec37e093ad8b3',
  24. 'timestamp': 1423523799,
  25. 'upload_date': '20150209',
  26. 'uploader': 'NAGS',
  27. },
  28. 'add_ie': ['ThePlatform'],
  29. },
  30. {
  31. 'url': 'http://video.nationalgeographic.com/wild/when-sharks-attack/the-real-jaws',
  32. 'md5': '6a3105eb448c070503b3105fb9b320b5',
  33. 'info_dict': {
  34. 'id': 'ngc-I0IauNSWznb_UV008GxSbwY35BZvgi2e',
  35. 'ext': 'mp4',
  36. 'title': 'The Real Jaws',
  37. 'description': 'md5:8d3e09d9d53a85cd397b4b21b2c77be6',
  38. 'timestamp': 1433772632,
  39. 'upload_date': '20150608',
  40. 'uploader': 'NAGS',
  41. },
  42. 'add_ie': ['ThePlatform'],
  43. },
  44. ]
  45. def _real_extract(self, url):
  46. name = url_basename(url)
  47. webpage = self._download_webpage(url, name)
  48. guid = self._search_regex(
  49. r'id="(?:videoPlayer|player-container)"[^>]+data-guid="([^"]+)"',
  50. webpage, 'guid')
  51. return {
  52. '_type': 'url_transparent',
  53. 'ie_key': 'ThePlatform',
  54. 'url': smuggle_url(
  55. 'http://link.theplatform.com/s/ngs/media/guid/2423130747/%s?mbr=true' % guid,
  56. {'force_smil_url': True}),
  57. 'id': guid,
  58. }
  59. class NationalGeographicIE(ThePlatformIE, AdobePassIE):
  60. IE_NAME = 'natgeo'
  61. _VALID_URL = r'https?://channel\.nationalgeographic\.com/(?:wild/)?[^/]+/(?:videos|episodes)/(?P<id>[^/?]+)'
  62. _TESTS = [
  63. {
  64. 'url': 'http://channel.nationalgeographic.com/the-story-of-god-with-morgan-freeman/videos/uncovering-a-universal-knowledge/',
  65. 'md5': '518c9aa655686cf81493af5cc21e2a04',
  66. 'info_dict': {
  67. 'id': 'vKInpacll2pC',
  68. 'ext': 'mp4',
  69. 'title': 'Uncovering a Universal Knowledge',
  70. 'description': 'md5:1a89148475bf931b3661fcd6ddb2ae3a',
  71. 'timestamp': 1458680907,
  72. 'upload_date': '20160322',
  73. 'uploader': 'NEWA-FNG-NGTV',
  74. },
  75. 'add_ie': ['ThePlatform'],
  76. },
  77. {
  78. 'url': 'http://channel.nationalgeographic.com/wild/destination-wild/videos/the-stunning-red-bird-of-paradise/',
  79. 'md5': 'c4912f656b4cbe58f3e000c489360989',
  80. 'info_dict': {
  81. 'id': 'Pok5lWCkiEFA',
  82. 'ext': 'mp4',
  83. 'title': 'The Stunning Red Bird of Paradise',
  84. 'description': 'md5:7bc8cd1da29686be4d17ad1230f0140c',
  85. 'timestamp': 1459362152,
  86. 'upload_date': '20160330',
  87. 'uploader': 'NEWA-FNG-NGTV',
  88. },
  89. 'add_ie': ['ThePlatform'],
  90. },
  91. {
  92. 'url': 'http://channel.nationalgeographic.com/the-story-of-god-with-morgan-freeman/episodes/the-power-of-miracles/',
  93. 'only_matching': True,
  94. }
  95. ]
  96. def _real_extract(self, url):
  97. display_id = self._match_id(url)
  98. webpage = self._download_webpage(url, display_id)
  99. release_url = self._search_regex(
  100. r'video_auth_playlist_url\s*=\s*"([^"]+)"',
  101. webpage, 'release url')
  102. theplatform_path = self._search_regex(r'https?://link.theplatform.com/s/([^?]+)', release_url, 'theplatform path')
  103. video_id = theplatform_path.split('/')[-1]
  104. query = {
  105. 'mbr': 'true',
  106. }
  107. is_auth = self._search_regex(r'video_is_auth\s*=\s*"([^"]+)"', webpage, 'is auth', fatal=False)
  108. if is_auth == 'auth':
  109. auth_resource_id = self._search_regex(
  110. r"video_auth_resourceId\s*=\s*'([^']+)'",
  111. webpage, 'auth resource id')
  112. query['auth'] = self._extract_mvpd_auth(url, video_id, 'natgeo', auth_resource_id)
  113. formats = []
  114. subtitles = {}
  115. for key, value in (('switch', 'http'), ('manifest', 'm3u')):
  116. tp_query = query.copy()
  117. tp_query.update({
  118. key: value,
  119. })
  120. tp_formats, tp_subtitles = self._extract_theplatform_smil(
  121. update_url_query(release_url, tp_query), video_id, 'Downloading %s SMIL data' % value)
  122. formats.extend(tp_formats)
  123. subtitles = self._merge_subtitles(subtitles, tp_subtitles)
  124. self._sort_formats(formats)
  125. info = self._extract_theplatform_metadata(theplatform_path, display_id)
  126. info.update({
  127. 'id': video_id,
  128. 'formats': formats,
  129. 'subtitles': subtitles,
  130. 'display_id': display_id,
  131. })
  132. return info
  133. class NationalGeographicEpisodeGuideIE(InfoExtractor):
  134. IE_NAME = 'natgeo:episodeguide'
  135. _VALID_URL = r'https?://channel\.nationalgeographic\.com/(?:wild/)?(?P<id>[^/]+)/episode-guide'
  136. _TESTS = [
  137. {
  138. 'url': 'http://channel.nationalgeographic.com/the-story-of-god-with-morgan-freeman/episode-guide/',
  139. 'info_dict': {
  140. 'id': 'the-story-of-god-with-morgan-freeman-season-1',
  141. 'title': 'The Story of God with Morgan Freeman - Season 1',
  142. },
  143. 'playlist_mincount': 6,
  144. },
  145. {
  146. 'url': 'http://channel.nationalgeographic.com/underworld-inc/episode-guide/?s=2',
  147. 'info_dict': {
  148. 'id': 'underworld-inc-season-2',
  149. 'title': 'Underworld, Inc. - Season 2',
  150. },
  151. 'playlist_mincount': 7,
  152. },
  153. ]
  154. def _real_extract(self, url):
  155. display_id = self._match_id(url)
  156. webpage = self._download_webpage(url, display_id)
  157. show = get_element_by_class('show', webpage)
  158. selected_season = self._search_regex(
  159. r'<div[^>]+class="select-seasons[^"]*".*?<a[^>]*>(.*?)</a>',
  160. webpage, 'selected season')
  161. entries = [
  162. self.url_result(self._proto_relative_url(entry_url), 'NationalGeographic')
  163. for entry_url in re.findall('(?s)<div[^>]+class="col-inner"[^>]*?>.*?<a[^>]+href="([^"]+)"', webpage)]
  164. return self.playlist_result(
  165. entries, '%s-%s' % (display_id, selected_season.lower().replace(' ', '-')),
  166. '%s - %s' % (show, selected_season))