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.

124 lines
4.5 KiB

  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from .theplatform import ThePlatformIE
  4. from ..utils import (
  5. smuggle_url,
  6. url_basename,
  7. update_url_query,
  8. )
  9. class NationalGeographicIE(InfoExtractor):
  10. IE_NAME = 'natgeo'
  11. _VALID_URL = r'https?://video\.nationalgeographic\.com/.*?'
  12. _TESTS = [
  13. {
  14. 'url': 'http://video.nationalgeographic.com/video/news/150210-news-crab-mating-vin?source=featuredvideo',
  15. 'md5': '730855d559abbad6b42c2be1fa584917',
  16. 'info_dict': {
  17. 'id': '0000014b-70a1-dd8c-af7f-f7b559330001',
  18. 'ext': 'mp4',
  19. 'title': 'Mating Crabs Busted by Sharks',
  20. 'description': 'md5:16f25aeffdeba55aaa8ec37e093ad8b3',
  21. 'timestamp': 1423523799,
  22. 'upload_date': '20150209',
  23. 'uploader': 'NAGS',
  24. },
  25. 'add_ie': ['ThePlatform'],
  26. },
  27. {
  28. 'url': 'http://video.nationalgeographic.com/wild/when-sharks-attack/the-real-jaws',
  29. 'md5': '6a3105eb448c070503b3105fb9b320b5',
  30. 'info_dict': {
  31. 'id': 'ngc-I0IauNSWznb_UV008GxSbwY35BZvgi2e',
  32. 'ext': 'mp4',
  33. 'title': 'The Real Jaws',
  34. 'description': 'md5:8d3e09d9d53a85cd397b4b21b2c77be6',
  35. 'timestamp': 1433772632,
  36. 'upload_date': '20150608',
  37. 'uploader': 'NAGS',
  38. },
  39. 'add_ie': ['ThePlatform'],
  40. },
  41. ]
  42. def _real_extract(self, url):
  43. name = url_basename(url)
  44. webpage = self._download_webpage(url, name)
  45. guid = self._search_regex(
  46. r'id="(?:videoPlayer|player-container)"[^>]+data-guid="([^"]+)"',
  47. webpage, 'guid')
  48. return {
  49. '_type': 'url_transparent',
  50. 'ie_key': 'ThePlatform',
  51. 'url': smuggle_url(
  52. 'http://link.theplatform.com/s/ngs/media/guid/2423130747/%s?mbr=true' % guid,
  53. {'force_smil_url': True}),
  54. 'id': guid,
  55. }
  56. class NationalGeographicChannelIE(ThePlatformIE):
  57. IE_NAME = 'natgeo:channel'
  58. _VALID_URL = r'https?://channel\.nationalgeographic\.com/(?:wild/)?[^/]+/videos/(?P<id>[^/?]+)'
  59. _TESTS = [
  60. {
  61. 'url': 'http://channel.nationalgeographic.com/the-story-of-god-with-morgan-freeman/videos/uncovering-a-universal-knowledge/',
  62. 'md5': '518c9aa655686cf81493af5cc21e2a04',
  63. 'info_dict': {
  64. 'id': 'nB5vIAfmyllm',
  65. 'ext': 'mp4',
  66. 'title': 'Uncovering a Universal Knowledge',
  67. 'description': 'md5:1a89148475bf931b3661fcd6ddb2ae3a',
  68. 'timestamp': 1458680907,
  69. 'upload_date': '20160322',
  70. 'uploader': 'NEWA-FNG-NGTV',
  71. },
  72. 'add_ie': ['ThePlatform'],
  73. },
  74. {
  75. 'url': 'http://channel.nationalgeographic.com/wild/destination-wild/videos/the-stunning-red-bird-of-paradise/',
  76. 'md5': 'c4912f656b4cbe58f3e000c489360989',
  77. 'info_dict': {
  78. 'id': '3TmMv9OvGwIR',
  79. 'ext': 'mp4',
  80. 'title': 'The Stunning Red Bird of Paradise',
  81. 'description': 'md5:7bc8cd1da29686be4d17ad1230f0140c',
  82. 'timestamp': 1459362152,
  83. 'upload_date': '20160330',
  84. 'uploader': 'NEWA-FNG-NGTV',
  85. },
  86. 'add_ie': ['ThePlatform'],
  87. },
  88. ]
  89. def _real_extract(self, url):
  90. display_id = self._match_id(url)
  91. webpage = self._download_webpage(url, display_id)
  92. release_url = self._search_regex(
  93. r'video_auth_playlist_url\s*=\s*"([^"]+)"',
  94. webpage, 'release url')
  95. query = {
  96. 'mbr': 'true',
  97. 'switch': 'http',
  98. }
  99. is_auth = self._search_regex(r'video_is_auth\s*=\s*"([^"]+)"', webpage, 'is auth', fatal=False)
  100. if is_auth == 'auth':
  101. auth_resource_id = self._search_regex(
  102. r"video_auth_resourceId\s*=\s*'([^']+)'",
  103. webpage, 'auth resource id')
  104. query['auth'] = self._extract_mvpd_auth(url, display_id, 'natgeo', auth_resource_id) or ''
  105. return {
  106. '_type': 'url_transparent',
  107. 'ie_key': 'ThePlatform',
  108. 'url': smuggle_url(
  109. update_url_query(release_url, query),
  110. {'force_smil_url': True}),
  111. 'display_id': display_id,
  112. }