]>
jfr.im git - yt-dlp.git/blob - youtube_dlc/extractor/cspan.py
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
18 from .senateisvp
import SenateISVPIE
19 from .ustream
import UstreamIE
22 class CSpanIE(InfoExtractor
):
23 _VALID_URL
= r
'https?://(?:www\.)?c-span\.org/video/\?(?P<id>[0-9a-f]+)'
26 'url': 'http://www.c-span.org/video/?313572-1/HolderonV',
27 'md5': '94b29a4f131ff03d23471dd6f60b6a1d',
30 'title': 'Attorney General Eric Holder on Voting Rights Act Decision',
32 'playlist_mincount': 2,
33 'skip': 'Regularly fails on travis, for unknown reasons',
35 'url': 'http://www.c-span.org/video/?c4486943/cspan-international-health-care-models',
40 'title': 'CSPAN - International Health Care Models',
41 'description': 'md5:7a985a2d595dba00af3d9c9f0783c967',
44 'url': 'http://www.c-span.org/video/?318608-1/gm-ignition-switch-recall',
47 'title': 'General Motors Ignition Switch Recall',
49 'playlist_mincount': 6,
51 # Video from senate.gov
52 'url': 'http://www.c-span.org/video/?104517-1/immigration-reforms-needed-protect-skilled-american-workers',
54 'id': 'judiciary031715',
56 'title': 'Immigration Reforms Needed to Protect Skilled American Workers',
59 'skip_download': True, # m3u8 downloads
62 # Ustream embedded video
63 'url': 'https://www.c-span.org/video/?114917-1/armed-services',
67 'title': 'USHR07 Armed Services Committee',
68 'description': 'hsas00-2118-20150204-1000et-07\n\n\nUSHR07 Armed Services Committee',
69 'timestamp': 1423060374,
70 'upload_date': '20150204',
71 'uploader': 'HouseCommittee',
72 'uploader_id': '12987475',
76 'url': 'https://www.c-span.org/video/?437336-1/judiciary-antitrust-competition-policy-consumer-rights',
77 'only_matching': True,
79 BRIGHTCOVE_URL_TEMPLATE
= 'http://players.brightcove.net/%s/%s_%s/index.html?videoId=%s'
81 def _real_extract(self
, url
):
82 video_id
= self
._match
_id
(url
)
84 webpage
= self
._download
_webpage
(url
, video_id
)
86 ustream_url
= UstreamIE
._extract
_url
(webpage
)
88 return self
.url_result(ustream_url
, UstreamIE
.ie_key())
91 bc
= self
._search
_regex
(
92 r
"(<[^>]+id='brightcove-player-embed'[^>]+>)",
93 webpage
, 'brightcove embed', default
=None)
95 bc_attr
= extract_attributes(bc
)
96 bc_url
= self
.BRIGHTCOVE_URL_TEMPLATE
% (
97 bc_attr
.get('data-bcaccountid', '3162030207001'),
98 bc_attr
.get('data-noprebcplayerid', 'SyGGpuJy3g'),
99 bc_attr
.get('data-newbcplayerid', 'default'),
100 bc_attr
['data-bcid'])
101 return self
.url_result(smuggle_url(bc_url
, {'source_url': url}
))
103 def add_referer(formats
):
105 f
.setdefault('http_headers', {})['Referer'] = url
107 # As of 01.12.2020 this path looks to cover all cases making the rest
108 # of the code unnecessary
109 jwsetup
= self
._parse
_json
(
111 r
'(?s)jwsetup\s*=\s*({.+?})\s*;', webpage
, 'jwsetup',
113 video_id
, transform_source
=js_to_json
, fatal
=False)
115 info
= self
._parse
_jwplayer
_data
(
116 jwsetup
, video_id
, require_title
=False, m3u8_id
='hls',
118 add_referer(info
['formats'])
119 ld_info
= self
._search
_json
_ld
(webpage
, video_id
, default
={})
120 return merge_dicts(info
, ld_info
)
123 # We first look for clipid, because clipprog always appears before
124 patterns
= [r
'id=\'clip(%s)\'\s
*value
=\'([0-9]+)\'' % t for t in ('id', 'prog
')]
125 results = list(filter(None, (re.search(p, webpage) for p in patterns)))
128 video_type, video_id = matches.groups()
129 video_type = 'clip
' if video_type == 'id' else 'program
'
131 m = re.search(r'data
-(?P
<type>clip|prog
)id=["\'](?P<id>\d+)', webpage)
133 video_id = m.group('id')
134 video_type = 'program' if m.group('type') == 'prog' else 'clip'
136 senate_isvp_url = SenateISVPIE._search_iframe_url(webpage)
138 title = self._og_search_title(webpage)
139 surl = smuggle_url(senate_isvp_url, {'force_title': title})
140 return self.url_result(surl, 'SenateISVP', video_id, title)
141 video_id = self._search_regex(
142 r'jwsetup\.clipprog\s*=\s*(\d+);',
143 webpage, 'jwsetup program id', default=None)
145 video_type = 'program'
146 if video_type is None or video_id is None:
147 error_message = get_element_by_class('VLplayer-error-message', webpage)
149 raise ExtractorError(error_message)
150 raise ExtractorError('unable to find video id and type')
152 def get_text_attr(d, attr):
153 return d.get(attr, {}).get('#text')
155 data = self._download_json(
156 'http://www.c-span.org/assets/player/ajax-player.php?os=android&html5=%s&id=%s' % (video_type, video_id),
158 if data['@status'] != 'Success':
159 raise ExtractorError('%s said: %s' % (self.IE_NAME, get_text_attr(data, 'error')), expected=True)
161 doc = self._download_xml(
162 'http://www.c-span.org/common/services/flashXml.php?%sid=%s' % (video_type, video_id),
165 description = self._html_search_meta('description', webpage)
167 title = find_xpath_attr(doc, './/string', 'name', 'title').text
168 thumbnail = find_xpath_attr(doc, './/string', 'name', 'poster').text
170 files = data['files']
171 capfile = get_text_attr(data, 'capfile')
174 for partnum, f in enumerate(files):
176 for quality in f.get('qualities', []):
178 'format_id': '%s-%sp' % (get_text_attr(quality, 'bitrate'), get_text_attr(quality, 'height')),
179 'url': unescapeHTML(get_text_attr(quality, 'file')),
180 'height': int_or_none(get_text_attr(quality, 'height')),
181 'tbr': int_or_none(get_text_attr(quality, 'bitrate')),
184 path = unescapeHTML(get_text_attr(f, 'path'))
187 formats = self._extract_m3u8_formats(
188 path, video_id, 'mp4', entry_protocol='m3u8_native',
189 m3u8_id='hls') if determine_ext(path) == 'm3u8' else [{'url': path, }]
191 self._sort_formats(formats)
193 'id': '%s_%d' % (video_id, partnum + 1),
195 title if len(files) == 1 else
196 '%s part %d' % (title, partnum + 1)),
198 'description': description,
199 'thumbnail': thumbnail,
200 'duration': int_or_none(get_text_attr(f, 'length')),
204 'ext': determine_ext(capfile, 'dfxp')
206 } if capfile else None,
209 if len(entries) == 1:
210 entry = dict(entries[0])
211 entry['id'] = 'c' + video_id if video_type == 'clip' else video_id
218 'id': 'c' + video_id if video_type == 'clip' else video_id,