]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/nationalgeographic.py
debian/rules: Adapt to new upstream build system.
[youtubedl] / youtube_dl / extractor / nationalgeographic.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..utils import (
5 smuggle_url,
6 url_basename,
7 update_url_query,
8 )
9
10
11 class NationalGeographicIE(InfoExtractor):
12 IE_NAME = 'natgeo'
13 _VALID_URL = r'https?://video\.nationalgeographic\.com/.*?'
14
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
46 def _real_extract(self, url):
47 name = url_basename(url)
48
49 webpage = self._download_webpage(url, name)
50 guid = self._search_regex(
51 r'id="(?:videoPlayer|player-container)"[^>]+data-guid="([^"]+)"',
52 webpage, 'guid')
53
54 return {
55 '_type': 'url_transparent',
56 'ie_key': 'ThePlatform',
57 'url': smuggle_url(
58 'http://link.theplatform.com/s/ngs/media/guid/2423130747/%s?mbr=true' % guid,
59 {'force_smil_url': True}),
60 'id': guid,
61 }
62
63
64 class NationalGeographicChannelIE(InfoExtractor):
65 IE_NAME = 'natgeo:channel'
66 _VALID_URL = r'https?://channel\.nationalgeographic\.com/(?:wild/)?[^/]+/videos/(?P<id>[^/?]+)'
67
68 _TESTS = [
69 {
70 'url': 'http://channel.nationalgeographic.com/the-story-of-god-with-morgan-freeman/videos/uncovering-a-universal-knowledge/',
71 'md5': '518c9aa655686cf81493af5cc21e2a04',
72 'info_dict': {
73 'id': 'nB5vIAfmyllm',
74 'ext': 'mp4',
75 'title': 'Uncovering a Universal Knowledge',
76 'description': 'md5:1a89148475bf931b3661fcd6ddb2ae3a',
77 'timestamp': 1458680907,
78 'upload_date': '20160322',
79 'uploader': 'NEWA-FNG-NGTV',
80 },
81 'add_ie': ['ThePlatform'],
82 },
83 {
84 'url': 'http://channel.nationalgeographic.com/wild/destination-wild/videos/the-stunning-red-bird-of-paradise/',
85 'md5': 'c4912f656b4cbe58f3e000c489360989',
86 'info_dict': {
87 'id': '3TmMv9OvGwIR',
88 'ext': 'mp4',
89 'title': 'The Stunning Red Bird of Paradise',
90 'description': 'md5:7bc8cd1da29686be4d17ad1230f0140c',
91 'timestamp': 1459362152,
92 'upload_date': '20160330',
93 'uploader': 'NEWA-FNG-NGTV',
94 },
95 'add_ie': ['ThePlatform'],
96 },
97 ]
98
99 def _real_extract(self, url):
100 display_id = self._match_id(url)
101 webpage = self._download_webpage(url, display_id)
102 release_url = self._search_regex(
103 r'video_auth_playlist_url\s*=\s*"([^"]+)"',
104 webpage, 'release url')
105
106 return {
107 '_type': 'url_transparent',
108 'ie_key': 'ThePlatform',
109 'url': smuggle_url(
110 update_url_query(release_url, {'mbr': 'true', 'switch': 'http'}),
111 {'force_smil_url': True}),
112 'display_id': display_id,
113 }