]>
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 |
4447fb23 | 15 | from .ustream import UstreamIE |
aa0c8739 | 16 | |
ca9e7922 | 17 | |
aa0c8739 | 18 | class CSpanIE(InfoExtractor): |
5886b38d | 19 | _VALID_URL = r'https?://(?:www\.)?c-span\.org/video/\?(?P<id>[0-9a-f]+)' |
ca9e7922 | 20 | IE_DESC = 'C-SPAN' |
11a15be4 | 21 | _TESTS = [{ |
009a3408 | 22 | 'url': 'http://www.c-span.org/video/?313572-1/HolderonV', |
355c7ad3 | 23 | 'md5': '94b29a4f131ff03d23471dd6f60b6a1d', |
ca9e7922 | 24 | 'info_dict': { |
009a3408 | 25 | 'id': '315139', |
ca9e7922 | 26 | 'title': 'Attorney General Eric Holder on Voting Rights Act Decision', |
6f5ac90c | 27 | }, |
f3c21cb7 | 28 | 'playlist_mincount': 2, |
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', | |
f3c21cb7 | 32 | # md5 is unstable |
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', | |
41 | 'info_dict': { | |
42 | 'id': '342759', | |
43 | 'title': 'General Motors Ignition Switch Recall', | |
44 | }, | |
f3c21cb7 | 45 | 'playlist_mincount': 6, |
2fe1b5bd YCH |
46 | }, { |
47 | # Video from senate.gov | |
48 | 'url': 'http://www.c-span.org/video/?104517-1/immigration-reforms-needed-protect-skilled-american-workers', | |
2fe1b5bd YCH |
49 | 'info_dict': { |
50 | 'id': 'judiciary031715', | |
7b0d333a | 51 | 'ext': 'mp4', |
2fe1b5bd | 52 | 'title': 'Immigration Reforms Needed to Protect Skilled American Workers', |
7b0d333a NP |
53 | }, |
54 | 'params': { | |
55 | 'skip_download': True, # m3u8 downloads | |
2fe1b5bd | 56 | } |
4447fb23 YCH |
57 | }, { |
58 | # Ustream embedded video | |
59 | 'url': 'https://www.c-span.org/video/?114917-1/armed-services', | |
60 | 'info_dict': { | |
61 | 'id': '58428542', | |
62 | 'ext': 'flv', | |
63 | 'title': 'USHR07 Armed Services Committee', | |
64 | 'description': 'hsas00-2118-20150204-1000et-07\n\n\nUSHR07 Armed Services Committee', | |
65 | 'timestamp': 1423060374, | |
66 | 'upload_date': '20150204', | |
67 | 'uploader': 'HouseCommittee', | |
68 | 'uploader_id': '12987475', | |
69 | }, | |
11a15be4 | 70 | }] |
aa0c8739 JMF |
71 | |
72 | def _real_extract(self, url): | |
30787f72 | 73 | video_id = self._match_id(url) |
04e24906 | 74 | video_type = None |
30787f72 | 75 | webpage = self._download_webpage(url, video_id) |
4447fb23 YCH |
76 | |
77 | ustream_url = UstreamIE._extract_url(webpage) | |
78 | if ustream_url: | |
79 | return self.url_result(ustream_url, UstreamIE.ie_key()) | |
80 | ||
6c6b8bd5 JMF |
81 | # We first look for clipid, because clipprog always appears before |
82 | patterns = [r'id=\'clip(%s)\'\s*value=\'([0-9]+)\'' % t for t in ('id', 'prog')] | |
83 | results = list(filter(None, (re.search(p, webpage) for p in patterns))) | |
84 | if results: | |
85 | matches = results[0] | |
30787f72 | 86 | video_type, video_id = matches.groups() |
6c6b8bd5 | 87 | video_type = 'clip' if video_type == 'id' else 'program' |
30787f72 | 88 | else: |
f6932135 S |
89 | m = re.search(r'data-(?P<type>clip|prog)id=["\'](?P<id>\d+)', webpage) |
90 | if m: | |
91 | video_id = m.group('id') | |
92 | video_type = 'program' if m.group('type') == 'prog' else 'clip' | |
93 | else: | |
94 | senate_isvp_url = SenateISVPIE._search_iframe_url(webpage) | |
95 | if senate_isvp_url: | |
96 | title = self._og_search_title(webpage) | |
97 | surl = smuggle_url(senate_isvp_url, {'force_title': title}) | |
98 | return self.url_result(surl, 'SenateISVP', video_id, title) | |
04e24906 JMF |
99 | if video_type is None or video_id is None: |
100 | raise ExtractorError('unable to find video id and type') | |
ca9e7922 | 101 | |
2a776f97 | 102 | def get_text_attr(d, attr): |
103 | return d.get(attr, {}).get('#text') | |
104 | ||
30787f72 | 105 | data = self._download_json( |
355c7ad3 | 106 | 'http://www.c-span.org/assets/player/ajax-player.php?os=android&html5=%s&id=%s' % (video_type, video_id), |
107 | video_id)['video'] | |
108 | if data['@status'] != 'Success': | |
2a776f97 | 109 | raise ExtractorError('%s said: %s' % (self.IE_NAME, get_text_attr(data, 'error')), expected=True) |
ca9e7922 | 110 | |
aea6e7fc | 111 | doc = self._download_xml( |
30787f72 | 112 | 'http://www.c-span.org/common/services/flashXml.php?%sid=%s' % (video_type, video_id), |
009a3408 JMF |
113 | video_id) |
114 | ||
30787f72 | 115 | description = self._html_search_meta('description', webpage) |
116 | ||
aea6e7fc PH |
117 | title = find_xpath_attr(doc, './/string', 'name', 'title').text |
118 | thumbnail = find_xpath_attr(doc, './/string', 'name', 'poster').text | |
119 | ||
355c7ad3 | 120 | files = data['files'] |
2a776f97 | 121 | capfile = get_text_attr(data, 'capfile') |
aea6e7fc | 122 | |
355c7ad3 | 123 | entries = [] |
124 | for partnum, f in enumerate(files): | |
125 | formats = [] | |
126 | for quality in f['qualities']: | |
127 | formats.append({ | |
2a776f97 | 128 | 'format_id': '%s-%sp' % (get_text_attr(quality, 'bitrate'), get_text_attr(quality, 'height')), |
129 | 'url': unescapeHTML(get_text_attr(quality, 'file')), | |
130 | 'height': int_or_none(get_text_attr(quality, 'height')), | |
131 | 'tbr': int_or_none(get_text_attr(quality, 'bitrate')), | |
355c7ad3 | 132 | }) |
af9c2a07 | 133 | if not formats: |
68a0ea15 | 134 | path = unescapeHTML(get_text_attr(f, 'path')) |
af9c2a07 S |
135 | if not path: |
136 | continue | |
137 | formats = self._extract_m3u8_formats( | |
138 | path, video_id, 'mp4', entry_protocol='m3u8_native', | |
139 | m3u8_id='hls') if determine_ext(path) == 'm3u8' else [{'url': path, }] | |
355c7ad3 | 140 | self._sort_formats(formats) |
141 | entries.append({ | |
142 | 'id': '%s_%d' % (video_id, partnum + 1), | |
143 | 'title': ( | |
144 | title if len(files) == 1 else | |
145 | '%s part %d' % (title, partnum + 1)), | |
146 | 'formats': formats, | |
147 | 'description': description, | |
148 | 'thumbnail': thumbnail, | |
2a776f97 | 149 | 'duration': int_or_none(get_text_attr(f, 'length')), |
355c7ad3 | 150 | 'subtitles': { |
151 | 'en': [{ | |
152 | 'url': capfile, | |
153 | 'ext': determine_ext(capfile, 'dfxp') | |
154 | }], | |
155 | } if capfile else None, | |
156 | }) | |
009a3408 | 157 | |
92dcba1e YCH |
158 | if len(entries) == 1: |
159 | entry = dict(entries[0]) | |
30787f72 | 160 | entry['id'] = 'c' + video_id if video_type == 'clip' else video_id |
92dcba1e YCH |
161 | return entry |
162 | else: | |
163 | return { | |
164 | '_type': 'playlist', | |
165 | 'entries': entries, | |
166 | 'title': title, | |
30787f72 | 167 | 'id': 'c' + video_id if video_type == 'clip' else video_id, |
92dcba1e | 168 | } |