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