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.

168 lines
6.2 KiB

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