]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/pbs.py
debian/NEWS: Write news about new behavior of youtube-dl.
[youtubedl] / youtube_dl / extractor / pbs.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6
7
8 class PBSIE(InfoExtractor):
9 _VALID_URL = r'''(?x)https?://
10 (?:
11 # Direct video URL
12 video\.pbs\.org/(?:viralplayer|video)/(?P<id>[0-9]+)/? |
13 # Article with embedded player
14 (?:www\.)?pbs\.org/(?:[^/]+/){2,5}(?P<presumptive_id>[^/]+)/?(?:$|[?\#]) |
15 # Player
16 video\.pbs\.org/partnerplayer/(?P<player_id>[^/]+)/
17 )
18 '''
19
20 _TEST = {
21 'url': 'http://www.pbs.org/tpt/constitution-usa-peter-sagal/watch/a-more-perfect-union/',
22 'md5': 'ce1888486f0908d555a8093cac9a7362',
23 'info_dict': {
24 'id': '2365006249',
25 'ext': 'mp4',
26 'title': 'A More Perfect Union',
27 'description': 'md5:ba0c207295339c8d6eced00b7c363c6a',
28 'duration': 3190,
29 },
30 }
31
32 def _real_extract(self, url):
33 mobj = re.match(self._VALID_URL, url)
34
35 presumptive_id = mobj.group('presumptive_id')
36 display_id = presumptive_id
37 if presumptive_id:
38 webpage = self._download_webpage(url, display_id)
39 url = self._search_regex(
40 r'<iframe\s+id=["\']partnerPlayer["\'].*?\s+src=["\'](.*?)["\']>',
41 webpage, 'player URL')
42 mobj = re.match(self._VALID_URL, url)
43
44 player_id = mobj.group('player_id')
45 if not display_id:
46 display_id = player_id
47 if player_id:
48 player_page = self._download_webpage(
49 url, display_id, note='Downloading player page',
50 errnote='Could not download player page')
51 video_id = self._search_regex(
52 r'<div\s+id="video_([0-9]+)"', player_page, 'video ID')
53 else:
54 video_id = mobj.group('id')
55 display_id = video_id
56
57 info_url = 'http://video.pbs.org/videoInfo/%s?format=json' % video_id
58 info = self._download_json(info_url, display_id)
59
60 return {
61 'id': video_id,
62 'title': info['title'],
63 'url': info['alternate_encoding']['url'],
64 'ext': 'mp4',
65 'description': info['program'].get('description'),
66 'thumbnail': info.get('image_url'),
67 'duration': info.get('duration'),
68 }