]>
Commit | Line | Data |
---|---|---|
dde9fe97 | 1 | import os.path |
e897bd82 | 2 | import re |
add96eb9 | 3 | import urllib.parse |
dde9fe97 | 4 | |
f8705443 | 5 | from .common import InfoExtractor |
dde9fe97 | 6 | from ..utils import ( |
dde9fe97 | 7 | remove_start, |
e897bd82 | 8 | url_basename, |
dde9fe97 | 9 | ) |
f8705443 | 10 | |
11 | ||
12 | class DemocracynowIE(InfoExtractor): | |
92519402 | 13 | _VALID_URL = r'https?://(?:www\.)?democracynow\.org/(?P<id>[^\?]*)' |
f8705443 | 14 | IE_NAME = 'democracynow' |
15 | _TESTS = [{ | |
16 | 'url': 'http://www.democracynow.org/shows/2015/7/3', | |
a134426d | 17 | 'md5': '3757c182d3d84da68f5c8f506c18c196', |
f8705443 | 18 | 'info_dict': { |
19 | 'id': '2015-0703-001', | |
20 | 'ext': 'mp4', | |
77481f13 TF |
21 | 'title': 'Daily Show for July 03, 2015', |
22 | 'description': 'md5:80eb927244d6749900de6072c7cc2c86', | |
f8705443 | 23 | }, |
eb080813 | 24 | }, { |
f8705443 | 25 | 'url': 'http://www.democracynow.org/2015/7/3/this_flag_comes_down_today_bree', |
26 | 'info_dict': { | |
27 | 'id': '2015-0703-001', | |
28 | 'ext': 'mp4', | |
29 | 'title': '"This Flag Comes Down Today": Bree Newsome Scales SC Capitol Flagpole, Takes Down Confederate Flag', | |
30 | 'description': 'md5:4d2bc4f0d29f5553c2210a4bc7761a21', | |
f8705443 | 31 | }, |
a134426d S |
32 | 'params': { |
33 | 'skip_download': True, | |
34 | }, | |
f8705443 | 35 | }] |
36 | ||
37 | def _real_extract(self, url): | |
38 | display_id = self._match_id(url) | |
18da2463 | 39 | |
f8705443 | 40 | webpage = self._download_webpage(url, display_id) |
f8705443 | 41 | |
fd810282 | 42 | json_data = self._parse_json(self._search_regex( |
dde9fe97 YCH |
43 | r'<script[^>]+type="text/json"[^>]*>\s*({[^>]+})', webpage, 'json'), |
44 | display_id) | |
18da2463 S |
45 | |
46 | title = json_data['title'] | |
f8705443 | 47 | formats = [] |
dde9fe97 | 48 | |
18da2463 S |
49 | video_id = None |
50 | ||
51 | for key in ('file', 'audio', 'video', 'high_res_video'): | |
52 | media_url = json_data.get(key, '') | |
53 | if not media_url: | |
54 | continue | |
add96eb9 | 55 | media_url = re.sub(r'\?.*', '', urllib.parse.urljoin(url, media_url)) |
18da2463 S |
56 | video_id = video_id or remove_start(os.path.splitext(url_basename(media_url))[0], 'dn') |
57 | formats.append({ | |
58 | 'url': media_url, | |
59 | 'vcodec': 'none' if key == 'audio' else None, | |
60 | }) | |
dde9fe97 | 61 | |
18da2463 | 62 | default_lang = 'en' |
f8705443 | 63 | subtitles = {} |
dde9fe97 YCH |
64 | |
65 | def add_subtitle_item(lang, info_dict): | |
66 | if lang not in subtitles: | |
67 | subtitles[lang] = [] | |
68 | subtitles[lang].append(info_dict) | |
69 | ||
70 | # chapter_file are not subtitles | |
fd810282 | 71 | if 'caption_file' in json_data: |
dde9fe97 | 72 | add_subtitle_item(default_lang, { |
add96eb9 | 73 | 'url': urllib.parse.urljoin(url, json_data['caption_file']), |
dde9fe97 YCH |
74 | }) |
75 | ||
fd810282 | 76 | for subtitle_item in json_data.get('captions', []): |
dde9fe97 YCH |
77 | lang = subtitle_item.get('language', '').lower() or default_lang |
78 | add_subtitle_item(lang, { | |
add96eb9 | 79 | 'url': urllib.parse.urljoin(url, subtitle_item['url']), |
dde9fe97 YCH |
80 | }) |
81 | ||
18da2463 | 82 | description = self._og_search_description(webpage, default=None) |
dde9fe97 YCH |
83 | |
84 | return { | |
0aeb9a10 | 85 | 'id': video_id or display_id, |
18da2463 | 86 | 'title': title, |
f8705443 | 87 | 'description': description, |
18da2463 | 88 | 'thumbnail': json_data.get('image'), |
f8705443 | 89 | 'subtitles': subtitles, |
90 | 'formats': formats, | |
91 | } |