]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/cspan.py
1 from __future__
import unicode_literals
5 from . common
import InfoExtractor
14 from . senateisvp
import SenateISVPIE
17 class CSpanIE ( InfoExtractor
):
18 _VALID_URL
= r
'https?://(?:www\.)?c-span\.org/video/\?(?P<id>[0-9a-f]+)'
21 'url' : 'http://www.c-span.org/video/?313572-1/HolderonV' ,
22 'md5' : '94b29a4f131ff03d23471dd6f60b6a1d' ,
26 'title' : 'Attorney General Eric Holder on Voting Rights Act Decision' ,
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.' ,
29 'skip' : 'Regularly fails on travis, for unknown reasons' ,
31 'url' : 'http://www.c-span.org/video/?c4486943/cspan-international-health-care-models' ,
32 'md5' : '8e5fbfabe6ad0f89f3012a7943c1287b' ,
36 'title' : 'CSPAN - International Health Care Models' ,
37 'description' : 'md5:7a985a2d595dba00af3d9c9f0783c967' ,
40 'url' : 'http://www.c-span.org/video/?318608-1/gm-ignition-switch-recall' ,
41 'md5' : '2ae5051559169baadba13fc35345ae74' ,
45 'title' : 'General Motors Ignition Switch Recall' ,
47 'description' : 'md5:118081aedd24bf1d3b68b3803344e7f3'
50 # Video from senate.gov
51 'url' : 'http://www.c-span.org/video/?104517-1/immigration-reforms-needed-protect-skilled-american-workers' ,
53 'id' : 'judiciary031715' ,
55 'title' : 'Immigration Reforms Needed to Protect Skilled American Workers' ,
58 'skip_download' : True , # m3u8 downloads
62 def _real_extract ( self
, url
):
63 video_id
= self
._ match
_ id
( url
)
65 webpage
= self
._ download
_ webpage
( url
, video_id
)
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)))
71 video_type, video_id = matches.groups()
72 video_type = ' clip
' if video_type == ' id ' else ' program
'
74 m = re.search(r' data
-( ?P
< type > clip|prog
) id =[ " \' ](?P<id>\d+)', webpage)
76 video_id = m.group('id')
77 video_type = 'program' if m.group('type') == 'prog' else 'clip'
79 senate_isvp_url = SenateISVPIE._search_iframe_url(webpage)
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)
84 if video_type is None or video_id is None:
85 raise ExtractorError('unable to find video id and type')
87 def get_text_attr(d, attr):
88 return d.get(attr, {}).get('#text')
90 data = self._download_json(
91 'http://www.c-span.org/assets/player/ajax-player.php?os=android&html5= %s &id= %s ' % (video_type, video_id),
93 if data['@status'] != 'Success':
94 raise ExtractorError(' %s said: %s ' % (self.IE_NAME, get_text_attr(data, 'error')), expected=True)
96 doc = self._download_xml(
97 'http://www.c-span.org/common/services/flashXml.php? %sid = %s ' % (video_type, video_id),
100 description = self._html_search_meta('description', webpage)
102 title = find_xpath_attr(doc, './/string', 'name', 'title').text
103 thumbnail = find_xpath_attr(doc, './/string', 'name', 'poster').text
105 files = data['files']
106 capfile = get_text_attr(data, 'capfile')
109 for partnum, f in enumerate(files):
111 for quality in f['qualities']:
113 'format_id': ' %s-%s p' % (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')),
119 path = unescapeHTML(get_text_attr(f, 'path'))
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, }]
125 self._sort_formats(formats)
127 'id': ' %s _ %d ' % (video_id, partnum + 1),
129 title if len(files) == 1 else
130 ' %s part %d ' % (title, partnum + 1)),
132 'description': description,
133 'thumbnail': thumbnail,
134 'duration': int_or_none(get_text_attr(f, 'length')),
138 'ext': determine_ext(capfile, 'dfxp')
140 } if capfile else None,
143 if len(entries) == 1:
144 entry = dict(entries[0])
145 entry['id'] = 'c' + video_id if video_type == 'clip' else video_id
152 'id': 'c' + video_id if video_type == 'clip' else video_id,