senateisvp.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import ExtractorError
  6. from ..compat import (
  7. compat_parse_qs,
  8. compat_urlparse,
  9. )
  10. class SenateISVPIE(InfoExtractor):
  11. _COMM_MAP = [
  12. ["ag", "76440", "http://ag-f.akamaihd.net"],
  13. ["aging", "76442", "http://aging-f.akamaihd.net"],
  14. ["approps", "76441", "http://approps-f.akamaihd.net"],
  15. ["armed", "76445", "http://armed-f.akamaihd.net"],
  16. ["banking", "76446", "http://banking-f.akamaihd.net"],
  17. ["budget", "76447", "http://budget-f.akamaihd.net"],
  18. ["cecc", "76486", "http://srs-f.akamaihd.net"],
  19. ["commerce", "80177", "http://commerce1-f.akamaihd.net"],
  20. ["csce", "75229", "http://srs-f.akamaihd.net"],
  21. ["dpc", "76590", "http://dpc-f.akamaihd.net"],
  22. ["energy", "76448", "http://energy-f.akamaihd.net"],
  23. ["epw", "76478", "http://epw-f.akamaihd.net"],
  24. ["ethics", "76449", "http://ethics-f.akamaihd.net"],
  25. ["finance", "76450", "http://finance-f.akamaihd.net"],
  26. ["foreign", "76451", "http://foreign-f.akamaihd.net"],
  27. ["govtaff", "76453", "http://govtaff-f.akamaihd.net"],
  28. ["help", "76452", "http://help-f.akamaihd.net"],
  29. ["indian", "76455", "http://indian-f.akamaihd.net"],
  30. ["intel", "76456", "http://intel-f.akamaihd.net"],
  31. ["intlnarc", "76457", "http://intlnarc-f.akamaihd.net"],
  32. ["jccic", "85180", "http://jccic-f.akamaihd.net"],
  33. ["jec", "76458", "http://jec-f.akamaihd.net"],
  34. ["judiciary", "76459", "http://judiciary-f.akamaihd.net"],
  35. ["rpc", "76591", "http://rpc-f.akamaihd.net"],
  36. ["rules", "76460", "http://rules-f.akamaihd.net"],
  37. ["saa", "76489", "http://srs-f.akamaihd.net"],
  38. ["smbiz", "76461", "http://smbiz-f.akamaihd.net"],
  39. ["srs", "75229", "http://srs-f.akamaihd.net"],
  40. ["uscc", "76487", "http://srs-f.akamaihd.net"],
  41. ["vetaff", "76462", "http://vetaff-f.akamaihd.net"],
  42. ["arch", "", "http://ussenate-f.akamaihd.net/"]
  43. ]
  44. _IE_NAME = 'senate.gov'
  45. _VALID_URL = r'http://www\.senate\.gov/isvp/\?(?P<qs>.+)'
  46. _TESTS = [{
  47. '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',
  48. 'md5': '7314c4b96dad66dd8e63dc3518ceaa6f',
  49. 'info_dict': {
  50. 'id': 'judiciary031715',
  51. 'ext': 'flv',
  52. 'title': 'Integrated Senate Video Player',
  53. 'thumbnail': 're:^https?://.*\.(?:jpg|png)$',
  54. }
  55. }, {
  56. 'url': 'http://www.senate.gov/isvp/?type=live&comm=commerce&filename=commerce011514.mp4&auto_play=false',
  57. 'md5': '2917c827513700aa9b70eaebf25116da',
  58. 'info_dict': {
  59. 'id': 'commerce011514',
  60. 'ext': 'flv',
  61. 'title': 'Integrated Senate Video Player'
  62. }
  63. }, {
  64. 'url': 'http://www.senate.gov/isvp/?type=arch&comm=intel&filename=intel090613&hc_location=ufi',
  65. # checksum differs each time
  66. 'info_dict': {
  67. 'id': 'intel090613',
  68. 'ext': 'mp4',
  69. 'title': 'Integrated Senate Video Player'
  70. }
  71. }]
  72. def _get_info_for_comm(self, committee):
  73. for entry in self._COMM_MAP:
  74. if entry[0] == committee:
  75. return entry[1:]
  76. def _real_extract(self, url):
  77. qs = compat_parse_qs(re.match(self._VALID_URL, url).group('qs'))
  78. if not qs.get('filename') or not qs.get('type') or not qs.get('comm'):
  79. raise ExtractorError('Invalid URL', expected=True)
  80. video_id = re.sub(r'.mp4$', '', qs['filename'][0])
  81. webpage = self._download_webpage(url, video_id)
  82. title = self._html_search_regex(r'<title>([^<]+)</title>', webpage, video_id)
  83. poster = qs.get('poster')
  84. if poster:
  85. thumbnail = poster[0]
  86. video_type = qs['type'][0]
  87. committee = video_type if video_type == 'arch' else qs['comm'][0]
  88. stream_num, domain = self._get_info_for_comm(committee)
  89. formats = []
  90. if video_type == 'arch':
  91. filename = video_id if '.' in video_id else video_id + '.mp4'
  92. formats = [{
  93. # All parameters in the query string are necessary to prevent a 403 error
  94. 'url': compat_urlparse.urljoin(domain, filename) + '?v=3.1.0&fp=&r=&g=',
  95. }]
  96. else:
  97. hdcore_sign = '?hdcore=3.1.0'
  98. url_params = (domain, video_id, stream_num)
  99. f4m_url = '%s/z/%s_1@%s/manifest.f4m' % url_params + hdcore_sign
  100. m3u8_url = '%s/i/%s_1@%s/master.m3u8' % url_params
  101. for entry in self._extract_f4m_formats(f4m_url, video_id, f4m_id='f4m'):
  102. # URLs without the extra param induce an 404 error
  103. entry.update({'extra_param_to_segment_url': hdcore_sign})
  104. formats.append(entry)
  105. for entry in self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4', m3u8_id='m3u8'):
  106. mobj = re.search(r'(?P<tag>(?:-p|-b)).m3u8', entry['url'])
  107. if mobj:
  108. entry['format_id'] += mobj.group('tag')
  109. formats.append(entry)
  110. self._sort_formats(formats)
  111. info_dict = {
  112. 'id': video_id,
  113. 'title': title,
  114. 'thumbnail': thumbnail,
  115. }
  116. if len(formats) >= 1:
  117. info_dict.update({'formats': formats})
  118. else:
  119. info_dict.update(formats[0])
  120. return info_dict