]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/nationalgeographic.py
246f6795a131908bf62c2b8c1477a7bc327afce5
   1 from __future__ 
import unicode_literals
 
   5 from .common 
import InfoExtractor
 
   6 from .adobepass 
import AdobePassIE
 
   7 from .theplatform 
import ThePlatformIE
 
  16 class NationalGeographicVideoIE(InfoExtractor
): 
  17     IE_NAME 
= 'natgeo:video' 
  18     _VALID_URL 
= r
'https?://video\.nationalgeographic\.com/.*?' 
  22             'url': 'http://video.nationalgeographic.com/video/news/150210-news-crab-mating-vin?source=featuredvideo', 
  23             'md5': '730855d559abbad6b42c2be1fa584917', 
  25                 'id': '0000014b-70a1-dd8c-af7f-f7b559330001', 
  27                 'title': 'Mating Crabs Busted by Sharks', 
  28                 'description': 'md5:16f25aeffdeba55aaa8ec37e093ad8b3', 
  29                 'timestamp': 1423523799, 
  30                 'upload_date': '20150209', 
  33             'add_ie': ['ThePlatform'], 
  36             'url': 'http://video.nationalgeographic.com/wild/when-sharks-attack/the-real-jaws', 
  37             'md5': '6a3105eb448c070503b3105fb9b320b5', 
  39                 'id': 'ngc-I0IauNSWznb_UV008GxSbwY35BZvgi2e', 
  41                 'title': 'The Real Jaws', 
  42                 'description': 'md5:8d3e09d9d53a85cd397b4b21b2c77be6', 
  43                 'timestamp': 1433772632, 
  44                 'upload_date': '20150608', 
  47             'add_ie': ['ThePlatform'], 
  51     def _real_extract(self
, url
): 
  52         name 
= url_basename(url
) 
  54         webpage 
= self
._download
_webpage
(url
, name
) 
  55         guid 
= self
._search
_regex
( 
  56             r
'id="(?:videoPlayer|player-container)"[^>]+data-guid="([^"]+)"', 
  60             '_type': 'url_transparent', 
  61             'ie_key': 'ThePlatform', 
  63                 'http://link.theplatform.com/s/ngs/media/guid/2423130747/%s?mbr=true' % guid
, 
  64                 {'force_smil_url': True}), 
  69 class NationalGeographicIE(ThePlatformIE
, AdobePassIE
): 
  71     _VALID_URL 
= r
'https?://channel\.nationalgeographic\.com/(?:(?:wild/)?[^/]+/)?(?:videos|episodes)/(?P<id>[^/?]+)' 
  75             'url': 'http://channel.nationalgeographic.com/the-story-of-god-with-morgan-freeman/videos/uncovering-a-universal-knowledge/', 
  76             'md5': '518c9aa655686cf81493af5cc21e2a04', 
  80                 'title': 'Uncovering a Universal Knowledge', 
  81                 'description': 'md5:1a89148475bf931b3661fcd6ddb2ae3a', 
  82                 'timestamp': 1458680907, 
  83                 'upload_date': '20160322', 
  84                 'uploader': 'NEWA-FNG-NGTV', 
  86             'add_ie': ['ThePlatform'], 
  89             'url': 'http://channel.nationalgeographic.com/wild/destination-wild/videos/the-stunning-red-bird-of-paradise/', 
  90             'md5': 'c4912f656b4cbe58f3e000c489360989', 
  94                 'title': 'The Stunning Red Bird of Paradise', 
  95                 'description': 'md5:7bc8cd1da29686be4d17ad1230f0140c', 
  96                 'timestamp': 1459362152, 
  97                 'upload_date': '20160330', 
  98                 'uploader': 'NEWA-FNG-NGTV', 
 100             'add_ie': ['ThePlatform'], 
 103             'url': 'http://channel.nationalgeographic.com/the-story-of-god-with-morgan-freeman/episodes/the-power-of-miracles/', 
 104             'only_matching': True, 
 107             'url': 'http://channel.nationalgeographic.com/videos/treasures-rediscovered/', 
 108             'only_matching': True, 
 112     def _real_extract(self
, url
): 
 113         display_id 
= self
._match
_id
(url
) 
 114         webpage 
= self
._download
_webpage
(url
, display_id
) 
 115         release_url 
= self
._search
_regex
( 
 116             r
'video_auth_playlist_url\s*=\s*"([^"]+)"', 
 117             webpage
, 'release url') 
 118         theplatform_path 
= self
._search
_regex
(r
'https?://link\.theplatform\.com/s/([^?]+)', release_url
, 'theplatform path') 
 119         video_id 
= theplatform_path
.split('/')[-1] 
 123         is_auth 
= self
._search
_regex
(r
'video_is_auth\s*=\s*"([^"]+)"', webpage
, 'is auth', fatal
=False) 
 124         if is_auth 
== 'auth': 
 125             auth_resource_id 
= self
._search
_regex
( 
 126                 r
"video_auth_resourceId\s*=\s*'([^']+)'", 
 127                 webpage
, 'auth resource id') 
 128             query
['auth'] = self
._extract
_mvpd
_auth
(url
, video_id
, 'natgeo', auth_resource_id
) 
 132         for key
, value 
in (('switch', 'http'), ('manifest', 'm3u')): 
 133             tp_query 
= query
.copy() 
 137             tp_formats
, tp_subtitles 
= self
._extract
_theplatform
_smil
( 
 138                 update_url_query(release_url
, tp_query
), video_id
, 'Downloading %s SMIL data' % value
) 
 139             formats
.extend(tp_formats
) 
 140             subtitles 
= self
._merge
_subtitles
(subtitles
, tp_subtitles
) 
 141         self
._sort
_formats
(formats
) 
 143         info 
= self
._extract
_theplatform
_metadata
(theplatform_path
, display_id
) 
 147             'subtitles': subtitles
, 
 148             'display_id': display_id
, 
 153 class NationalGeographicEpisodeGuideIE(InfoExtractor
): 
 154     IE_NAME 
= 'natgeo:episodeguide' 
 155     _VALID_URL 
= r
'https?://channel\.nationalgeographic\.com/(?:wild/)?(?P<id>[^/]+)/episode-guide' 
 158             'url': 'http://channel.nationalgeographic.com/the-story-of-god-with-morgan-freeman/episode-guide/', 
 160                 'id': 'the-story-of-god-with-morgan-freeman-season-1', 
 161                 'title': 'The Story of God with Morgan Freeman - Season 1', 
 163             'playlist_mincount': 6, 
 166             'url': 'http://channel.nationalgeographic.com/underworld-inc/episode-guide/?s=2', 
 168                 'id': 'underworld-inc-season-2', 
 169                 'title': 'Underworld, Inc. - Season 2', 
 171             'playlist_mincount': 7, 
 175     def _real_extract(self
, url
): 
 176         display_id 
= self
._match
_id
(url
) 
 177         webpage 
= self
._download
_webpage
(url
, display_id
) 
 178         show 
= get_element_by_class('show', webpage
) 
 179         selected_season 
= self
._search
_regex
( 
 180             r
'<div[^>]+class="select-seasons[^"]*".*?<a[^>]*>(.*?)</a>', 
 181             webpage
, 'selected season') 
 183             self
.url_result(self
._proto
_relative
_url
(entry_url
), 'NationalGeographic') 
 184             for entry_url 
in re
.findall('(?s)<div[^>]+class="col-inner"[^>]*?>.*?<a[^>]+href="([^"]+)"', webpage
)] 
 185         return self
.playlist_result( 
 186             entries
, '%s-%s' % (display_id
, selected_season
.lower().replace(' ', '-')), 
 187             '%s - %s' % (show
, selected_season
))