]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/cspan.py
   1 from __future__ 
import unicode_literals
 
   5 from .common 
import InfoExtractor
 
  16 from .senateisvp 
import SenateISVPIE
 
  17 from .ustream 
import UstreamIE
 
  20 class CSpanIE(InfoExtractor
): 
  21     _VALID_URL 
= r
'https?://(?:www\.)?c-span\.org/video/\?(?P<id>[0-9a-f]+)' 
  24         'url': 'http://www.c-span.org/video/?313572-1/HolderonV', 
  25         'md5': '94b29a4f131ff03d23471dd6f60b6a1d', 
  28             'title': 'Attorney General Eric Holder on Voting Rights Act Decision', 
  30         'playlist_mincount': 2, 
  31         'skip': 'Regularly fails on travis, for unknown reasons', 
  33         'url': 'http://www.c-span.org/video/?c4486943/cspan-international-health-care-models', 
  38             'title': 'CSPAN - International Health Care Models', 
  39             'description': 'md5:7a985a2d595dba00af3d9c9f0783c967', 
  42         'url': 'http://www.c-span.org/video/?318608-1/gm-ignition-switch-recall', 
  45             'title': 'General Motors Ignition Switch Recall', 
  47         'playlist_mincount': 6, 
  49         # Video from senate.gov 
  50         'url': 'http://www.c-span.org/video/?104517-1/immigration-reforms-needed-protect-skilled-american-workers', 
  52             'id': 'judiciary031715', 
  54             'title': 'Immigration Reforms Needed to Protect Skilled American Workers', 
  57             'skip_download': True,  # m3u8 downloads 
  60         # Ustream embedded video 
  61         'url': 'https://www.c-span.org/video/?114917-1/armed-services', 
  65             'title': 'USHR07 Armed Services Committee', 
  66             'description': 'hsas00-2118-20150204-1000et-07\n\n\nUSHR07 Armed Services Committee', 
  67             'timestamp': 1423060374, 
  68             'upload_date': '20150204', 
  69             'uploader': 'HouseCommittee', 
  70             'uploader_id': '12987475', 
  74         'url': 'https://www.c-span.org/video/?437336-1/judiciary-antitrust-competition-policy-consumer-rights', 
  75         'only_matching': True, 
  77     BRIGHTCOVE_URL_TEMPLATE 
= 'http://players.brightcove.net/%s/%s_%s/index.html?videoId=%s' 
  79     def _real_extract(self
, url
): 
  80         video_id 
= self
._match
_id
(url
) 
  82         webpage 
= self
._download
_webpage
(url
, video_id
) 
  84         ustream_url 
= UstreamIE
._extract
_url
(webpage
) 
  86             return self
.url_result(ustream_url
, UstreamIE
.ie_key()) 
  89             bc 
= self
._search
_regex
( 
  90                 r
"(<[^>]+id='brightcove-player-embed'[^>]+>)", 
  91                 webpage
, 'brightcove embed', default
=None) 
  93                 bc_attr 
= extract_attributes(bc
) 
  94                 bc_url 
= self
.BRIGHTCOVE_URL_TEMPLATE 
% ( 
  95                     bc_attr
.get('data-bcaccountid', '3162030207001'), 
  96                     bc_attr
.get('data-noprebcplayerid', 'SyGGpuJy3g'), 
  97                     bc_attr
.get('data-newbcplayerid', 'default'), 
  99                 return self
.url_result(smuggle_url(bc_url
, {'source_url': url
})) 
 101         # We first look for clipid, because clipprog always appears before 
 102         patterns 
= [r
'id=\'clip(%s)\'\s
*value
=\'([0-9]+)\'' % t for t in ('id', 'prog
')] 
 103         results = list(filter(None, (re.search(p, webpage) for p in patterns))) 
 106             video_type, video_id = matches.groups() 
 107             video_type = 'clip
' if video_type == 'id' else 'program
' 
 109             m = re.search(r'data
-(?P
<type>clip|prog
)id=["\'](?P<id>\d+)', webpage) 
 111                 video_id = m.group('id') 
 112                 video_type = 'program' if m.group('type') == 'prog' else 'clip' 
 114                 senate_isvp_url = SenateISVPIE._search_iframe_url(webpage) 
 116                     title = self._og_search_title(webpage) 
 117                     surl = smuggle_url(senate_isvp_url, {'force_title': title}) 
 118                     return self.url_result(surl, 'SenateISVP', video_id, title) 
 119                 video_id = self._search_regex( 
 120                     r'jwsetup\.clipprog\s*=\s*(\d+);', 
 121                     webpage, 'jwsetup program id', default=None) 
 123                     video_type = 'program' 
 124         if video_type is None or video_id is None: 
 125             error_message = get_element_by_class('VLplayer-error-message', webpage) 
 127                 raise ExtractorError(error_message) 
 128             raise ExtractorError('unable to find video id and type') 
 130         def get_text_attr(d, attr): 
 131             return d.get(attr, {}).get('#text') 
 133         data = self._download_json( 
 134             'http://www.c-span.org/assets/player/ajax-player.php?os=android&html5=%s&id=%s' % (video_type, video_id), 
 136         if data['@status'] != 'Success': 
 137             raise ExtractorError('%s said: %s' % (self.IE_NAME, get_text_attr(data, 'error')), expected=True) 
 139         doc = self._download_xml( 
 140             'http://www.c-span.org/common/services/flashXml.php?%sid=%s' % (video_type, video_id), 
 143         description = self._html_search_meta('description', webpage) 
 145         title = find_xpath_attr(doc, './/string', 'name', 'title').text 
 146         thumbnail = find_xpath_attr(doc, './/string', 'name', 'poster').text 
 148         files = data['files'] 
 149         capfile = get_text_attr(data, 'capfile') 
 152         for partnum, f in enumerate(files): 
 154             for quality in f.get('qualities', []): 
 156                     'format_id': '%s-%sp' % (get_text_attr(quality, 'bitrate'), get_text_attr(quality, 'height')), 
 157                     'url': unescapeHTML(get_text_attr(quality, 'file')), 
 158                     'height': int_or_none(get_text_attr(quality, 'height')), 
 159                     'tbr': int_or_none(get_text_attr(quality, 'bitrate')), 
 162                 path = unescapeHTML(get_text_attr(f, 'path')) 
 165                 formats = self._extract_m3u8_formats( 
 166                     path, video_id, 'mp4', entry_protocol='m3u8_native', 
 167                     m3u8_id='hls') if determine_ext(path) == 'm3u8' else [{'url': path, }] 
 168             self._sort_formats(formats) 
 170                 'id': '%s_%d' % (video_id, partnum + 1), 
 172                     title if len(files) == 1 else 
 173                     '%s part %d' % (title, partnum + 1)), 
 175                 'description': description, 
 176                 'thumbnail': thumbnail, 
 177                 'duration': int_or_none(get_text_attr(f, 'length')), 
 181                         'ext': determine_ext(capfile, 'dfxp') 
 183                 } if capfile else None, 
 186         if len(entries) == 1: 
 187             entry = dict(entries[0]) 
 188             entry['id'] = 'c' + video_id if video_type == 'clip' else video_id 
 195                 'id': 'c' + video_id if video_type == 'clip' else video_id,