1 from __future__ import unicode_literals
5 from .common import InfoExtractor
11 class PBSIE(InfoExtractor):
12 _VALID_URL = r'''(?x)https?://
15 video\.pbs\.org/(?:viralplayer|video)/(?P<id>[0-9]+)/? |
16 # Article with embedded player
17 (?:www\.)?pbs\.org/(?:[^/]+/){2,5}(?P<presumptive_id>[^/]+)/?(?:$|[?\#]) |
19 video\.pbs\.org/(?:widget/)?partnerplayer/(?P<player_id>[^/]+)/
24 'url': 'http://www.pbs.org/tpt/constitution-usa-peter-sagal/watch/a-more-perfect-union/',
25 'md5': 'ce1888486f0908d555a8093cac9a7362',
29 'title': 'A More Perfect Union',
30 'description': 'md5:ba0c207295339c8d6eced00b7c363c6a',
35 def _real_extract(self, url):
36 mobj = re.match(self._VALID_URL, url)
38 presumptive_id = mobj.group('presumptive_id')
39 display_id = presumptive_id
41 webpage = self._download_webpage(url, display_id)
42 url = self._search_regex(
43 r'<iframe\s+id=["\']partnerPlayer["\'].*?\s+src=["\'](.*?)["\']>',
44 webpage, 'player URL')
45 mobj = re.match(self._VALID_URL, url)
47 player_id = mobj.group('player_id')
49 display_id = player_id
51 player_page = self._download_webpage(
52 url, display_id, note='Downloading player page',
53 errnote='Could not download player page')
54 video_id = self._search_regex(
55 r'<div\s+id="video_([0-9]+)"', player_page, 'video ID')
57 video_id = mobj.group('id')
60 info_url = 'http://video.pbs.org/videoInfo/%s?format=json' % video_id
61 info = self._download_json(info_url, display_id)
63 rating_str = info.get('rating')
64 if rating_str is not None:
65 rating_str = rating_str.rpartition('-')[2]
66 age_limit = US_RATINGS.get(rating_str)
70 'title': info['title'],
71 'url': info['alternate_encoding']['url'],
73 'description': info['program'].get('description'),
74 'thumbnail': info.get('image_url'),
75 'duration': info.get('duration'),
76 'age_limit': age_limit,