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>[^/]+)/
25 'url': 'http://www.pbs.org/tpt/constitution-usa-peter-sagal/watch/a-more-perfect-union/',
26 'md5': 'ce1888486f0908d555a8093cac9a7362',
30 'title': 'A More Perfect Union',
31 'description': 'md5:ba0c207295339c8d6eced00b7c363c6a',
36 'url': 'http://www.pbs.org/wgbh/pages/frontline/losing-iraq/',
37 'md5': '143c98aa54a346738a3d78f54c925321',
41 'title': 'Losing Iraq',
42 'description': 'md5:f5bfbefadf421e8bb8647602011caf8e',
47 'url': 'http://www.pbs.org/newshour/bb/education-jan-june12-cyberschools_02-23/',
48 'md5': 'b19856d7f5351b17a5ab1dc6a64be633',
52 'title': 'Cyber Schools Gain Popularity, but Quality Questions Persist',
53 'description': 'md5:5871c15cba347c1b3d28ac47a73c7c28',
58 'url': 'http://www.pbs.org/wnet/gperf/dudamel-conducts-verdi-requiem-hollywood-bowl-full-episode/3374/',
59 'md5': 'c62859342be2a0358d6c9eb306595978',
63 'description': 'md5:68d87ef760660eb564455eb30ca464fe',
64 'title': 'Dudamel Conducts Verdi Requiem at the Hollywood Bowl - Full',
66 'thumbnail': 're:^https?://.*\.jpg$',
71 def _extract_ids(self, url):
72 mobj = re.match(self._VALID_URL, url)
74 presumptive_id = mobj.group('presumptive_id')
75 display_id = presumptive_id
77 webpage = self._download_webpage(url, display_id)
80 r"div\s*:\s*'videoembed'\s*,\s*mediaid\s*:\s*'(\d+)'", # frontline video embed
81 r'class="coveplayerid">([^<]+)<', # coveplayer
84 media_id = self._search_regex(
85 MEDIA_ID_REGEXES, webpage, 'media ID', fatal=False, default=None)
87 return media_id, presumptive_id
89 url = self._search_regex(
90 r'<iframe\s+(?:class|id)=["\']partnerPlayer["\'].*?\s+src=["\'](.*?)["\']>',
91 webpage, 'player URL')
92 mobj = re.match(self._VALID_URL, url)
94 player_id = mobj.group('player_id')
96 display_id = player_id
98 player_page = self._download_webpage(
99 url, display_id, note='Downloading player page',
100 errnote='Could not download player page')
101 video_id = self._search_regex(
102 r'<div\s+id="video_([0-9]+)"', player_page, 'video ID')
104 video_id = mobj.group('id')
105 display_id = video_id
107 return video_id, display_id
109 def _real_extract(self, url):
110 video_id, display_id = self._extract_ids(url)
112 info_url = 'http://video.pbs.org/videoInfo/%s?format=json' % video_id
113 info = self._download_json(info_url, display_id)
115 rating_str = info.get('rating')
116 if rating_str is not None:
117 rating_str = rating_str.rpartition('-')[2]
118 age_limit = US_RATINGS.get(rating_str)
122 'title': info['title'],
123 'url': info['alternate_encoding']['url'],
125 'description': info['program'].get('description'),
126 'thumbnail': info.get('image_url'),
127 'duration': info.get('duration'),
128 'age_limit': age_limit,