]>
Commit | Line | Data |
---|---|---|
ca9e7922 PH |
1 | from __future__ import unicode_literals |
2 | ||
aa0c8739 JMF |
3 | import re |
4 | ||
5 | from .common import InfoExtractor | |
6 | from ..utils import ( | |
aea6e7fc | 7 | int_or_none, |
ca9e7922 | 8 | unescapeHTML, |
009a3408 | 9 | find_xpath_attr, |
2fe1b5bd | 10 | smuggle_url, |
672f1bd8 | 11 | determine_ext, |
355c7ad3 | 12 | ExtractorError, |
aa0c8739 | 13 | ) |
2fe1b5bd | 14 | from .senateisvp import SenateISVPIE |
aa0c8739 | 15 | |
ca9e7922 | 16 | |
aa0c8739 | 17 | class CSpanIE(InfoExtractor): |
5886b38d | 18 | _VALID_URL = r'https?://(?:www\.)?c-span\.org/video/\?(?P<id>[0-9a-f]+)' |
ca9e7922 | 19 | IE_DESC = 'C-SPAN' |
11a15be4 | 20 | _TESTS = [{ |
009a3408 | 21 | 'url': 'http://www.c-span.org/video/?313572-1/HolderonV', |
355c7ad3 | 22 | 'md5': '94b29a4f131ff03d23471dd6f60b6a1d', |
ca9e7922 | 23 | 'info_dict': { |
009a3408 JMF |
24 | 'id': '315139', |
25 | 'ext': 'mp4', | |
ca9e7922 | 26 | 'title': 'Attorney General Eric Holder on Voting Rights Act Decision', |
30787f72 | 27 | 'description': 'Attorney General Eric Holder speaks to reporters following the Supreme Court decision in [Shelby County v. Holder], in which the court ruled that the preclearance provisions of the Voting Rights Act could not be enforced.', |
6f5ac90c | 28 | }, |
11577ec0 | 29 | 'skip': 'Regularly fails on travis, for unknown reasons', |
11a15be4 PH |
30 | }, { |
31 | 'url': 'http://www.c-span.org/video/?c4486943/cspan-international-health-care-models', | |
355c7ad3 | 32 | 'md5': '8e5fbfabe6ad0f89f3012a7943c1287b', |
11a15be4 | 33 | 'info_dict': { |
30787f72 | 34 | 'id': 'c4486943', |
11a15be4 | 35 | 'ext': 'mp4', |
30787f72 | 36 | 'title': 'CSPAN - International Health Care Models', |
11a15be4 PH |
37 | 'description': 'md5:7a985a2d595dba00af3d9c9f0783c967', |
38 | } | |
22a6f150 PH |
39 | }, { |
40 | 'url': 'http://www.c-span.org/video/?318608-1/gm-ignition-switch-recall', | |
355c7ad3 | 41 | 'md5': '2ae5051559169baadba13fc35345ae74', |
22a6f150 PH |
42 | 'info_dict': { |
43 | 'id': '342759', | |
92dcba1e | 44 | 'ext': 'mp4', |
22a6f150 | 45 | 'title': 'General Motors Ignition Switch Recall', |
92dcba1e | 46 | 'duration': 14848, |
30787f72 | 47 | 'description': 'md5:118081aedd24bf1d3b68b3803344e7f3' |
22a6f150 | 48 | }, |
2fe1b5bd YCH |
49 | }, { |
50 | # Video from senate.gov | |
51 | 'url': 'http://www.c-span.org/video/?104517-1/immigration-reforms-needed-protect-skilled-american-workers', | |
2fe1b5bd YCH |
52 | 'info_dict': { |
53 | 'id': 'judiciary031715', | |
7b0d333a | 54 | 'ext': 'mp4', |
2fe1b5bd | 55 | 'title': 'Immigration Reforms Needed to Protect Skilled American Workers', |
7b0d333a NP |
56 | }, |
57 | 'params': { | |
58 | 'skip_download': True, # m3u8 downloads | |
2fe1b5bd | 59 | } |
11a15be4 | 60 | }] |
aa0c8739 JMF |
61 | |
62 | def _real_extract(self, url): | |
30787f72 | 63 | video_id = self._match_id(url) |
04e24906 | 64 | video_type = None |
30787f72 | 65 | webpage = self._download_webpage(url, video_id) |
6c6b8bd5 JMF |
66 | # We first look for clipid, because clipprog always appears before |
67 | patterns = [r'id=\'clip(%s)\'\s*value=\'([0-9]+)\'' % t for t in ('id', 'prog')] | |
68 | results = list(filter(None, (re.search(p, webpage) for p in patterns))) | |
69 | if results: | |
70 | matches = results[0] | |
30787f72 | 71 | video_type, video_id = matches.groups() |
6c6b8bd5 | 72 | video_type = 'clip' if video_type == 'id' else 'program' |
30787f72 | 73 | else: |
f6932135 S |
74 | m = re.search(r'data-(?P<type>clip|prog)id=["\'](?P<id>\d+)', webpage) |
75 | if m: | |
76 | video_id = m.group('id') | |
77 | video_type = 'program' if m.group('type') == 'prog' else 'clip' | |
78 | else: | |
79 | senate_isvp_url = SenateISVPIE._search_iframe_url(webpage) | |
80 | if senate_isvp_url: | |
81 | title = self._og_search_title(webpage) | |
82 | surl = smuggle_url(senate_isvp_url, {'force_title': title}) | |
83 | return self.url_result(surl, 'SenateISVP', video_id, title) | |
04e24906 JMF |
84 | if video_type is None or video_id is None: |
85 | raise ExtractorError('unable to find video id and type') | |
ca9e7922 | 86 | |
2a776f97 | 87 | def get_text_attr(d, attr): |
88 | return d.get(attr, {}).get('#text') | |
89 | ||
30787f72 | 90 | data = self._download_json( |
355c7ad3 | 91 | 'http://www.c-span.org/assets/player/ajax-player.php?os=android&html5=%s&id=%s' % (video_type, video_id), |
92 | video_id)['video'] | |
93 | if data['@status'] != 'Success': | |
2a776f97 | 94 | raise ExtractorError('%s said: %s' % (self.IE_NAME, get_text_attr(data, 'error')), expected=True) |
ca9e7922 | 95 | |
aea6e7fc | 96 | doc = self._download_xml( |
30787f72 | 97 | 'http://www.c-span.org/common/services/flashXml.php?%sid=%s' % (video_type, video_id), |
009a3408 JMF |
98 | video_id) |
99 | ||
30787f72 | 100 | description = self._html_search_meta('description', webpage) |
101 | ||
aea6e7fc PH |
102 | title = find_xpath_attr(doc, './/string', 'name', 'title').text |
103 | thumbnail = find_xpath_attr(doc, './/string', 'name', 'poster').text | |
104 | ||
355c7ad3 | 105 | files = data['files'] |
2a776f97 | 106 | capfile = get_text_attr(data, 'capfile') |
aea6e7fc | 107 | |
355c7ad3 | 108 | entries = [] |
109 | for partnum, f in enumerate(files): | |
110 | formats = [] | |
111 | for quality in f['qualities']: | |
112 | formats.append({ | |
2a776f97 | 113 | 'format_id': '%s-%sp' % (get_text_attr(quality, 'bitrate'), get_text_attr(quality, 'height')), |
114 | 'url': unescapeHTML(get_text_attr(quality, 'file')), | |
115 | 'height': int_or_none(get_text_attr(quality, 'height')), | |
116 | 'tbr': int_or_none(get_text_attr(quality, 'bitrate')), | |
355c7ad3 | 117 | }) |
af9c2a07 | 118 | if not formats: |
68a0ea15 | 119 | path = unescapeHTML(get_text_attr(f, 'path')) |
af9c2a07 S |
120 | if not path: |
121 | continue | |
122 | formats = self._extract_m3u8_formats( | |
123 | path, video_id, 'mp4', entry_protocol='m3u8_native', | |
124 | m3u8_id='hls') if determine_ext(path) == 'm3u8' else [{'url': path, }] | |
355c7ad3 | 125 | self._sort_formats(formats) |
126 | entries.append({ | |
127 | 'id': '%s_%d' % (video_id, partnum + 1), | |
128 | 'title': ( | |
129 | title if len(files) == 1 else | |
130 | '%s part %d' % (title, partnum + 1)), | |
131 | 'formats': formats, | |
132 | 'description': description, | |
133 | 'thumbnail': thumbnail, | |
2a776f97 | 134 | 'duration': int_or_none(get_text_attr(f, 'length')), |
355c7ad3 | 135 | 'subtitles': { |
136 | 'en': [{ | |
137 | 'url': capfile, | |
138 | 'ext': determine_ext(capfile, 'dfxp') | |
139 | }], | |
140 | } if capfile else None, | |
141 | }) | |
009a3408 | 142 | |
92dcba1e YCH |
143 | if len(entries) == 1: |
144 | entry = dict(entries[0]) | |
30787f72 | 145 | entry['id'] = 'c' + video_id if video_type == 'clip' else video_id |
92dcba1e YCH |
146 | return entry |
147 | else: | |
148 | return { | |
149 | '_type': 'playlist', | |
150 | 'entries': entries, | |
151 | 'title': title, | |
30787f72 | 152 | 'id': 'c' + video_id if video_type == 'clip' else video_id, |
92dcba1e | 153 | } |