]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/pbs.py
6118ed5c2021492ee91e22dccd642d564918604c
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
12 class PBSIE(InfoExtractor
):
13 _VALID_URL
= r
'''(?x)https?://
16 video\.pbs\.org/(?:viralplayer|video)/(?P<id>[0-9]+)/? |
17 # Article with embedded player (or direct video)
18 (?:www\.)?pbs\.org/(?:[^/]+/){2,5}(?P<presumptive_id>[^/]+?)(?:\.html)?/?(?:$|[?\#]) |
20 video\.pbs\.org/(?:widget/)?partnerplayer/(?P<player_id>[^/]+)/
26 'url': 'http://www.pbs.org/tpt/constitution-usa-peter-sagal/watch/a-more-perfect-union/',
27 'md5': 'ce1888486f0908d555a8093cac9a7362',
31 'title': 'A More Perfect Union',
32 'description': 'md5:ba0c207295339c8d6eced00b7c363c6a',
37 'url': 'http://www.pbs.org/wgbh/pages/frontline/losing-iraq/',
38 'md5': '143c98aa54a346738a3d78f54c925321',
42 'title': 'Losing Iraq',
43 'description': 'md5:f5bfbefadf421e8bb8647602011caf8e',
48 'url': 'http://www.pbs.org/newshour/bb/education-jan-june12-cyberschools_02-23/',
49 'md5': 'b19856d7f5351b17a5ab1dc6a64be633',
53 'title': 'Cyber Schools Gain Popularity, but Quality Questions Persist',
54 'description': 'md5:5871c15cba347c1b3d28ac47a73c7c28',
59 'url': 'http://www.pbs.org/wnet/gperf/dudamel-conducts-verdi-requiem-hollywood-bowl-full-episode/3374/',
60 'md5': 'c62859342be2a0358d6c9eb306595978',
64 'description': 'md5:68d87ef760660eb564455eb30ca464fe',
65 'title': 'Dudamel Conducts Verdi Requiem at the Hollywood Bowl - Full',
67 'thumbnail': 're:^https?://.*\.jpg$',
71 'url': 'http://www.pbs.org/wgbh/nova/earth/killer-typhoon.html',
72 'md5': '908f3e5473a693b266b84e25e1cf9703',
75 'display_id': 'killer-typhoon',
77 'description': 'md5:c741d14e979fc53228c575894094f157',
78 'title': 'Killer Typhoon',
80 'thumbnail': 're:^https?://.*\.jpg$',
81 'upload_date': '20140122',
85 'url': 'http://www.pbs.org/wgbh/pages/frontline/united-states-of-secrets/',
87 'id': 'united-states-of-secrets',
93 def _extract_webpage(self
, url
):
94 mobj
= re
.match(self
._VALID
_URL
, url
)
96 presumptive_id
= mobj
.group('presumptive_id')
97 display_id
= presumptive_id
99 webpage
= self
._download
_webpage
(url
, display_id
)
101 upload_date
= unified_strdate(self
._search
_regex
(
102 r
'<input type="hidden" id="air_date_[0-9]+" value="([^"]+)"',
103 webpage
, 'upload date', default
=None))
105 # tabbed frontline videos
106 tabbed_videos
= re
.findall(
107 r
'<div[^>]+class="videotab[^"]*"[^>]+vid="(\d+)"', webpage
)
109 return tabbed_videos
, presumptive_id
, upload_date
112 r
"div\s*:\s*'videoembed'\s*,\s*mediaid\s*:\s*'(\d+)'", # frontline video embed
113 r
'class="coveplayerid">([^<]+)<', # coveplayer
114 r
'<input type="hidden" id="pbs_video_id_[0-9]+" value="([0-9]+)"/>', # jwplayer
117 media_id
= self
._search
_regex
(
118 MEDIA_ID_REGEXES
, webpage
, 'media ID', fatal
=False, default
=None)
120 return media_id
, presumptive_id
, upload_date
122 url
= self
._search
_regex
(
123 r
'<iframe\s+(?:class|id)=["\']partnerPlayer
["\'].*?\s+src=["\'](.*?
)["\']>',
124 webpage, 'player URL')
125 mobj = re.match(self._VALID_URL, url)
127 player_id = mobj.group('player_id')
129 display_id = player_id
131 player_page = self._download_webpage(
132 url, display_id, note='Downloading player page',
133 errnote='Could not download player page')
134 video_id = self._search_regex(
135 r'<div\s+id="video_([0-9]+)"', player_page, 'video ID')
137 video_id = mobj.group('id')
138 display_id = video_id
140 return video_id, display_id, None
142 def _real_extract(self, url):
143 video_id, display_id, upload_date = self._extract_webpage(url)
145 if isinstance(video_id, list):
146 entries = [self.url_result(
147 'http://video.pbs.org/video/%s' % vid_id, 'PBS', vid_id)
148 for vid_id in video_id]
149 return self.playlist_result(entries, display_id)
151 info_url = 'http://video.pbs.org/videoInfo/%s?format=json' % video_id
152 info = self._download_json(info_url, display_id)
154 rating_str = info.get('rating')
155 if rating_str is not None:
156 rating_str = rating_str.rpartition('-')[2]
157 age_limit = US_RATINGS.get(rating_str)
161 'display_id': display_id,
162 'title': info['title'],
163 'url': info['alternate_encoding']['url'],
165 'description': info['program'].get('description'),
166 'thumbnail': info.get('image_url'),
167 'duration': info.get('duration'),
168 'age_limit': age_limit,
169 'upload_date': upload_date,