1 from __future__ import unicode_literals
6 from .common import InfoExtractor
9 class PBSIE(InfoExtractor):
10 _VALID_URL = r'''(?x)https?://
13 video\.pbs\.org/video/(?P<id>[0-9]+)/? |
14 # Article with embedded player
15 (?:www\.)?pbs\.org/(?:[^/]+/){2,5}(?P<presumptive_id>[^/]+)/?(?:$|[?\#]) |
17 video\.pbs\.org/partnerplayer/(?P<player_id>[^/]+)/
22 'url': 'http://www.pbs.org/tpt/constitution-usa-peter-sagal/watch/a-more-perfect-union/',
23 'md5': 'ce1888486f0908d555a8093cac9a7362',
27 'title': 'A More Perfect Union',
28 'description': 'md5:ba0c207295339c8d6eced00b7c363c6a',
33 def _real_extract(self, url):
34 mobj = re.match(self._VALID_URL, url)
36 presumptive_id = mobj.group('presumptive_id')
37 display_id = presumptive_id
39 webpage = self._download_webpage(url, display_id)
40 url = self._search_regex(
41 r'<iframe\s+id=["\']partnerPlayer["\'].*?\s+src=["\'](.*?)["\']>',
42 webpage, 'player URL')
43 mobj = re.match(self._VALID_URL, url)
45 player_id = mobj.group('player_id')
47 display_id = player_id
49 player_page = self._download_webpage(
50 url, display_id, note='Downloading player page',
51 errnote='Could not download player page')
52 video_id = self._search_regex(
53 r'<div\s+id="video_([0-9]+)"', player_page, 'video ID')
55 video_id = mobj.group('id')
58 info_url = 'http://video.pbs.org/videoInfo/%s?format=json' % video_id
59 info = self._download_json(info_url, display_id)
63 'title': info['title'],
64 'url': info['alternate_encoding']['url'],
66 'description': info['program'].get('description'),
67 'thumbnail': info.get('image_url'),
68 'duration': info.get('duration'),