]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/cspan.py
171820e2722b1c8eb1f7fdcfb5991b3186c58f01
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
15 from .senateisvp
import SenateISVPIE
16 from .ustream
import UstreamIE
19 class CSpanIE(InfoExtractor
):
20 _VALID_URL
= r
'https?://(?:www\.)?c-span\.org/video/\?(?P<id>[0-9a-f]+)'
23 'url': 'http://www.c-span.org/video/?313572-1/HolderonV',
24 'md5': '94b29a4f131ff03d23471dd6f60b6a1d',
27 'title': 'Attorney General Eric Holder on Voting Rights Act Decision',
29 'playlist_mincount': 2,
30 'skip': 'Regularly fails on travis, for unknown reasons',
32 'url': 'http://www.c-span.org/video/?c4486943/cspan-international-health-care-models',
37 'title': 'CSPAN - International Health Care Models',
38 'description': 'md5:7a985a2d595dba00af3d9c9f0783c967',
41 'url': 'http://www.c-span.org/video/?318608-1/gm-ignition-switch-recall',
44 'title': 'General Motors Ignition Switch Recall',
46 'playlist_mincount': 6,
48 # Video from senate.gov
49 'url': 'http://www.c-span.org/video/?104517-1/immigration-reforms-needed-protect-skilled-american-workers',
51 'id': 'judiciary031715',
53 'title': 'Immigration Reforms Needed to Protect Skilled American Workers',
56 'skip_download': True, # m3u8 downloads
59 # Ustream embedded video
60 'url': 'https://www.c-span.org/video/?114917-1/armed-services',
64 'title': 'USHR07 Armed Services Committee',
65 'description': 'hsas00-2118-20150204-1000et-07\n\n\nUSHR07 Armed Services Committee',
66 'timestamp': 1423060374,
67 'upload_date': '20150204',
68 'uploader': 'HouseCommittee',
69 'uploader_id': '12987475',
72 BRIGHTCOVE_URL_TEMPLATE
= 'http://players.brightcove.net/%s/%s_%s/index.html?videoId=%s'
74 def _real_extract(self
, url
):
75 video_id
= self
._match
_id
(url
)
77 webpage
= self
._download
_webpage
(url
, video_id
)
79 ustream_url
= UstreamIE
._extract
_url
(webpage
)
81 return self
.url_result(ustream_url
, UstreamIE
.ie_key())
84 bc
= self
._search
_regex
(
85 r
"(<[^>]+id='brightcove-player-embed'[^>]+>)",
86 webpage
, 'brightcove embed', default
=None)
88 bc_attr
= extract_attributes(bc
)
89 bc_url
= self
.BRIGHTCOVE_URL_TEMPLATE
% (
90 bc_attr
.get('data-bcaccountid', '3162030207001'),
91 bc_attr
.get('data-noprebcplayerid', 'SyGGpuJy3g'),
92 bc_attr
.get('data-newbcplayerid', 'default'),
94 return self
.url_result(smuggle_url(bc_url
, {'source_url': url
}))
96 # We first look for clipid, because clipprog always appears before
97 patterns
= [r
'id=\'clip(%s)\'\s
*value
=\'([0-9]+)\'' % t for t in ('id', 'prog
')]
98 results = list(filter(None, (re.search(p, webpage) for p in patterns)))
101 video_type, video_id = matches.groups()
102 video_type = 'clip
' if video_type == 'id' else 'program
'
104 m = re.search(r'data
-(?P
<type>clip|prog
)id=["\'](?P<id>\d+)', webpage)
106 video_id = m.group('id')
107 video_type = 'program' if m.group('type') == 'prog' else 'clip'
109 senate_isvp_url = SenateISVPIE._search_iframe_url(webpage)
111 title = self._og_search_title(webpage)
112 surl = smuggle_url(senate_isvp_url, {'force_title': title})
113 return self.url_result(surl, 'SenateISVP', video_id, title)
114 if video_type is None or video_id is None:
115 raise ExtractorError('unable to find video id and type')
117 def get_text_attr(d, attr):
118 return d.get(attr, {}).get('#text')
120 data = self._download_json(
121 'http://www.c-span.org/assets/player/ajax-player.php?os=android&html5=%s&id=%s' % (video_type, video_id),
123 if data['@status'] != 'Success':
124 raise ExtractorError('%s said: %s' % (self.IE_NAME, get_text_attr(data, 'error')), expected=True)
126 doc = self._download_xml(
127 'http://www.c-span.org/common/services/flashXml.php?%sid=%s' % (video_type, video_id),
130 description = self._html_search_meta('description', webpage)
132 title = find_xpath_attr(doc, './/string', 'name', 'title').text
133 thumbnail = find_xpath_attr(doc, './/string', 'name', 'poster').text
135 files = data['files']
136 capfile = get_text_attr(data, 'capfile')
139 for partnum, f in enumerate(files):
141 for quality in f['qualities']:
143 'format_id': '%s-%sp' % (get_text_attr(quality, 'bitrate'), get_text_attr(quality, 'height')),
144 'url': unescapeHTML(get_text_attr(quality, 'file')),
145 'height': int_or_none(get_text_attr(quality, 'height')),
146 'tbr': int_or_none(get_text_attr(quality, 'bitrate')),
149 path = unescapeHTML(get_text_attr(f, 'path'))
152 formats = self._extract_m3u8_formats(
153 path, video_id, 'mp4', entry_protocol='m3u8_native',
154 m3u8_id='hls') if determine_ext(path) == 'm3u8' else [{'url': path, }]
155 self._sort_formats(formats)
157 'id': '%s_%d' % (video_id, partnum + 1),
159 title if len(files) == 1 else
160 '%s part %d' % (title, partnum + 1)),
162 'description': description,
163 'thumbnail': thumbnail,
164 'duration': int_or_none(get_text_attr(f, 'length')),
168 'ext': determine_ext(capfile, 'dfxp')
170 } if capfile else None,
173 if len(entries) == 1:
174 entry = dict(entries[0])
175 entry['id'] = 'c' + video_id if video_type == 'clip' else video_id
182 'id': 'c' + video_id if video_type == 'clip' else video_id,