senategov.py 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import re
  2. from .common import InfoExtractor
  3. from ..compat import (
  4. compat_parse_qs,
  5. compat_urlparse,
  6. )
  7. from ..utils import (
  8. ExtractorError,
  9. parse_qs,
  10. unsmuggle_url,
  11. )
  12. _COMMITTEES = {
  13. 'ag': ('76440', 'http://ag-f.akamaihd.net'),
  14. 'aging': ('76442', 'http://aging-f.akamaihd.net'),
  15. 'approps': ('76441', 'http://approps-f.akamaihd.net'),
  16. 'arch': ('', 'http://ussenate-f.akamaihd.net'),
  17. 'armed': ('76445', 'http://armed-f.akamaihd.net'),
  18. 'banking': ('76446', 'http://banking-f.akamaihd.net'),
  19. 'budget': ('76447', 'http://budget-f.akamaihd.net'),
  20. 'cecc': ('76486', 'http://srs-f.akamaihd.net'),
  21. 'commerce': ('80177', 'http://commerce1-f.akamaihd.net'),
  22. 'csce': ('75229', 'http://srs-f.akamaihd.net'),
  23. 'dpc': ('76590', 'http://dpc-f.akamaihd.net'),
  24. 'energy': ('76448', 'http://energy-f.akamaihd.net'),
  25. 'epw': ('76478', 'http://epw-f.akamaihd.net'),
  26. 'ethics': ('76449', 'http://ethics-f.akamaihd.net'),
  27. 'finance': ('76450', 'http://finance-f.akamaihd.net'),
  28. 'foreign': ('76451', 'http://foreign-f.akamaihd.net'),
  29. 'govtaff': ('76453', 'http://govtaff-f.akamaihd.net'),
  30. 'help': ('76452', 'http://help-f.akamaihd.net'),
  31. 'indian': ('76455', 'http://indian-f.akamaihd.net'),
  32. 'intel': ('76456', 'http://intel-f.akamaihd.net'),
  33. 'intlnarc': ('76457', 'http://intlnarc-f.akamaihd.net'),
  34. 'jccic': ('85180', 'http://jccic-f.akamaihd.net'),
  35. 'jec': ('76458', 'http://jec-f.akamaihd.net'),
  36. 'judiciary': ('76459', 'http://judiciary-f.akamaihd.net'),
  37. 'rpc': ('76591', 'http://rpc-f.akamaihd.net'),
  38. 'rules': ('76460', 'http://rules-f.akamaihd.net'),
  39. 'saa': ('76489', 'http://srs-f.akamaihd.net'),
  40. 'smbiz': ('76461', 'http://smbiz-f.akamaihd.net'),
  41. 'srs': ('75229', 'http://srs-f.akamaihd.net'),
  42. 'uscc': ('76487', 'http://srs-f.akamaihd.net'),
  43. 'vetaff': ('76462', 'http://vetaff-f.akamaihd.net'),
  44. }
  45. class SenateISVPIE(InfoExtractor):
  46. _IE_NAME = 'senate.gov:isvp'
  47. _VALID_URL = r'https?://(?:www\.)?senate\.gov/isvp/?\?(?P<qs>.+)'
  48. _EMBED_REGEX = [r"<iframe[^>]+src=['\"](?P<url>https?://www\.senate\.gov/isvp/?\?[^'\"]+)['\"]"]
  49. _TESTS = [{
  50. 'url': 'http://www.senate.gov/isvp/?comm=judiciary&type=live&stt=&filename=judiciary031715&auto_play=false&wmode=transparent&poster=http%3A%2F%2Fwww.judiciary.senate.gov%2Fthemes%2Fjudiciary%2Fimages%2Fvideo-poster-flash-fit.png',
  51. 'info_dict': {
  52. 'id': 'judiciary031715',
  53. 'ext': 'mp4',
  54. 'title': 'Integrated Senate Video Player',
  55. 'thumbnail': r're:^https?://.*\.(?:jpg|png)$',
  56. },
  57. 'params': {
  58. # m3u8 download
  59. 'skip_download': True,
  60. },
  61. }, {
  62. 'url': 'http://www.senate.gov/isvp/?type=live&comm=commerce&filename=commerce011514.mp4&auto_play=false',
  63. 'info_dict': {
  64. 'id': 'commerce011514',
  65. 'ext': 'mp4',
  66. 'title': 'Integrated Senate Video Player'
  67. },
  68. 'params': {
  69. # m3u8 download
  70. 'skip_download': True,
  71. },
  72. }, {
  73. 'url': 'http://www.senate.gov/isvp/?type=arch&comm=intel&filename=intel090613&hc_location=ufi',
  74. # checksum differs each time
  75. 'info_dict': {
  76. 'id': 'intel090613',
  77. 'ext': 'mp4',
  78. 'title': 'Integrated Senate Video Player'
  79. }
  80. }, {
  81. # From http://www.c-span.org/video/?96791-1
  82. 'url': 'http://www.senate.gov/isvp?type=live&comm=banking&filename=banking012715',
  83. 'only_matching': True,
  84. }]
  85. def _real_extract(self, url):
  86. url, smuggled_data = unsmuggle_url(url, {})
  87. qs = compat_parse_qs(self._match_valid_url(url).group('qs'))
  88. if not qs.get('filename') or not qs.get('type') or not qs.get('comm'):
  89. raise ExtractorError('Invalid URL', expected=True)
  90. video_id = re.sub(r'.mp4$', '', qs['filename'][0])
  91. webpage = self._download_webpage(url, video_id)
  92. if smuggled_data.get('force_title'):
  93. title = smuggled_data['force_title']
  94. else:
  95. title = self._html_extract_title(webpage)
  96. poster = qs.get('poster')
  97. thumbnail = poster[0] if poster else None
  98. video_type = qs['type'][0]
  99. committee = video_type if video_type == 'arch' else qs['comm'][0]
  100. stream_num, domain = _COMMITTEES[committee]
  101. formats = []
  102. if video_type == 'arch':
  103. filename = video_id if '.' in video_id else video_id + '.mp4'
  104. m3u8_url = compat_urlparse.urljoin(domain, 'i/' + filename + '/master.m3u8')
  105. formats = self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4', m3u8_id='m3u8')
  106. else:
  107. hdcore_sign = 'hdcore=3.1.0'
  108. url_params = (domain, video_id, stream_num)
  109. f4m_url = f'%s/z/%s_1@%s/manifest.f4m?{hdcore_sign}' % url_params
  110. m3u8_url = '%s/i/%s_1@%s/master.m3u8' % url_params
  111. for entry in self._extract_f4m_formats(f4m_url, video_id, f4m_id='f4m'):
  112. # URLs without the extra param induce an 404 error
  113. entry.update({'extra_param_to_segment_url': hdcore_sign})
  114. formats.append(entry)
  115. for entry in self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4', m3u8_id='m3u8'):
  116. mobj = re.search(r'(?P<tag>(?:-p|-b)).m3u8', entry['url'])
  117. if mobj:
  118. entry['format_id'] += mobj.group('tag')
  119. formats.append(entry)
  120. return {
  121. 'id': video_id,
  122. 'title': title,
  123. 'formats': formats,
  124. 'thumbnail': thumbnail,
  125. }
  126. class SenateGovIE(InfoExtractor):
  127. _IE_NAME = 'senate.gov'
  128. _VALID_URL = r'https?:\/\/(?:www\.)?(help|appropriations|judiciary|banking|armed-services|finance)\.senate\.gov'
  129. _TESTS = [{
  130. 'url': 'https://www.help.senate.gov/hearings/vaccines-saving-lives-ensuring-confidence-and-protecting-public-health',
  131. 'info_dict': {
  132. 'id': 'help090920',
  133. 'display_id': 'vaccines-saving-lives-ensuring-confidence-and-protecting-public-health',
  134. 'title': 'Vaccines: Saving Lives, Ensuring Confidence, and Protecting Public Health',
  135. 'description': 'The U.S. Senate Committee on Health, Education, Labor & Pensions',
  136. 'ext': 'mp4',
  137. },
  138. 'params': {'skip_download': 'm3u8'},
  139. }, {
  140. 'url': 'https://www.appropriations.senate.gov/hearings/watch?hearingid=B8A25434-5056-A066-6020-1F68CB75F0CD',
  141. 'info_dict': {
  142. 'id': 'appropsA051518',
  143. 'display_id': 'watch?hearingid=B8A25434-5056-A066-6020-1F68CB75F0CD',
  144. 'title': 'Review of the FY2019 Budget Request for the U.S. Army',
  145. 'ext': 'mp4',
  146. },
  147. 'params': {'skip_download': 'm3u8'},
  148. }, {
  149. 'url': 'https://www.banking.senate.gov/hearings/21st-century-communities-public-transportation-infrastructure-investment-and-fast-act-reauthorization',
  150. 'info_dict': {
  151. 'id': 'banking041521',
  152. 'display_id': '21st-century-communities-public-transportation-infrastructure-investment-and-fast-act-reauthorization',
  153. 'title': '21st Century Communities: Public Transportation Infrastructure Investment and FAST Act Reauthorization',
  154. 'description': 'The Official website of The United States Committee on Banking, Housing, and Urban Affairs',
  155. 'ext': 'mp4',
  156. },
  157. 'params': {'skip_download': 'm3u8'},
  158. }]
  159. def _real_extract(self, url):
  160. display_id = self._generic_id(url)
  161. webpage = self._download_webpage(url, display_id)
  162. parse_info = parse_qs(self._search_regex(
  163. r'<iframe class="[^>"]*streaminghearing[^>"]*"\s[^>]*\bsrc="([^">]*)', webpage, 'hearing URL'))
  164. stream_num, stream_domain = _COMMITTEES[parse_info['comm'][-1]]
  165. filename = parse_info['filename'][-1]
  166. formats = self._extract_m3u8_formats(
  167. f'{stream_domain}/i/{filename}_1@{stream_num}/master.m3u8',
  168. display_id, ext='mp4')
  169. title = self._html_search_regex(
  170. (*self._og_regexes('title'), r'(?s)<title>([^<]*?)</title>'), webpage, 'video title')
  171. return {
  172. 'id': re.sub(r'.mp4$', '', filename),
  173. 'display_id': display_id,
  174. 'title': re.sub(r'\s+', ' ', title.split('|')[0]).strip(),
  175. 'description': self._og_search_description(webpage, default=None),
  176. 'thumbnail': self._og_search_thumbnail(webpage, default=None),
  177. 'age_limit': self._rta_search(webpage),
  178. 'formats': formats
  179. }