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',
87 def _extract_webpage(self, url):
88 mobj = re.match(self._VALID_URL, url)
90 presumptive_id = mobj.group('presumptive_id')
91 display_id = presumptive_id
93 webpage = self._download_webpage(url, display_id)
95 upload_date = unified_strdate(self._search_regex(
96 r'<input type="hidden" id="air_date_[0-9]+" value="([^"]+)"',
97 webpage, 'upload date', default=None))
100 r"div\s*:\s*'videoembed'\s*,\s*mediaid\s*:\s*'(\d+)'", # frontline video embed
101 r'class="coveplayerid">([^<]+)<', # coveplayer
102 r'<input type="hidden" id="pbs_video_id_[0-9]+" value="([0-9]+)"/>', # jwplayer
105 media_id = self._search_regex(
106 MEDIA_ID_REGEXES, webpage, 'media ID', fatal=False, default=None)
108 return media_id, presumptive_id, upload_date
110 url = self._search_regex(
111 r'<iframe\s+(?:class|id)=["\']partnerPlayer["\'].*?\s+src=["\'](.*?)["\']>',
112 webpage, 'player URL')
113 mobj = re.match(self._VALID_URL, url)
115 player_id = mobj.group('player_id')
117 display_id = player_id
119 player_page = self._download_webpage(
120 url, display_id, note='Downloading player page',
121 errnote='Could not download player page')
122 video_id = self._search_regex(
123 r'<div\s+id="video_([0-9]+)"', player_page, 'video ID')
125 video_id = mobj.group('id')
126 display_id = video_id
128 return video_id, display_id, None
130 def _real_extract(self, url):
131 video_id, display_id, upload_date = self._extract_webpage(url)
133 info_url = 'http://video.pbs.org/videoInfo/%s?format=json' % video_id
134 info = self._download_json(info_url, display_id)
136 rating_str = info.get('rating')
137 if rating_str is not None:
138 rating_str = rating_str.rpartition('-')[2]
139 age_limit = US_RATINGS.get(rating_str)
143 'display_id': display_id,
144 'title': info['title'],
145 'url': info['alternate_encoding']['url'],
147 'description': info['program'].get('description'),
148 'thumbnail': info.get('image_url'),
149 'duration': info.get('duration'),
150 'age_limit': age_limit,
151 'upload_date': upload_date,