You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
4.6 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. unescapeHTML,
  7. find_xpath_attr,
  8. smuggle_url,
  9. determine_ext,
  10. )
  11. from .senateisvp import SenateISVPIE
  12. class CSpanIE(InfoExtractor):
  13. _VALID_URL = r'http://(?:www\.)?c-span\.org/video/\?(?P<id>[0-9a-f]+)'
  14. IE_DESC = 'C-SPAN'
  15. _TESTS = [{
  16. 'url': 'http://www.c-span.org/video/?313572-1/HolderonV',
  17. 'md5': '8e44ce11f0f725527daccc453f553eb0',
  18. 'info_dict': {
  19. 'id': '315139',
  20. 'ext': 'mp4',
  21. 'title': 'Attorney General Eric Holder on Voting Rights Act Decision',
  22. 'description': 'Attorney General Eric Holder spoke 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 until Congress established new guidelines for review.',
  23. },
  24. 'skip': 'Regularly fails on travis, for unknown reasons',
  25. }, {
  26. 'url': 'http://www.c-span.org/video/?c4486943/cspan-international-health-care-models',
  27. # For whatever reason, the served video alternates between
  28. # two different ones
  29. 'info_dict': {
  30. 'id': '340723',
  31. 'ext': 'mp4',
  32. 'title': 'International Health Care Models',
  33. 'description': 'md5:7a985a2d595dba00af3d9c9f0783c967',
  34. }
  35. }, {
  36. 'url': 'http://www.c-span.org/video/?318608-1/gm-ignition-switch-recall',
  37. 'md5': '446562a736c6bf97118e389433ed88d4',
  38. 'info_dict': {
  39. 'id': '342759',
  40. 'ext': 'mp4',
  41. 'title': 'General Motors Ignition Switch Recall',
  42. 'duration': 14848,
  43. 'description': 'md5:70c7c3b8fa63fa60d42772440596034c'
  44. },
  45. }, {
  46. # Video from senate.gov
  47. 'url': 'http://www.c-span.org/video/?104517-1/immigration-reforms-needed-protect-skilled-american-workers',
  48. 'info_dict': {
  49. 'id': 'judiciary031715',
  50. 'ext': 'flv',
  51. 'title': 'Immigration Reforms Needed to Protect Skilled American Workers',
  52. }
  53. }]
  54. def _real_extract(self, url):
  55. mobj = re.match(self._VALID_URL, url)
  56. page_id = mobj.group('id')
  57. webpage = self._download_webpage(url, page_id)
  58. video_id = self._search_regex(r'progid=\'?([0-9]+)\'?>', webpage, 'video id')
  59. description = self._html_search_regex(
  60. [
  61. # The full description
  62. r'<div class=\'expandable\'>(.*?)<a href=\'#\'',
  63. # If the description is small enough the other div is not
  64. # present, otherwise this is a stripped version
  65. r'<p class=\'initial\'>(.*?)</p>'
  66. ],
  67. webpage, 'description', flags=re.DOTALL, default=None)
  68. info_url = 'http://c-spanvideo.org/videoLibrary/assets/player/ajax-player.php?os=android&html5=program&id=' + video_id
  69. data = self._download_json(info_url, video_id)
  70. doc = self._download_xml(
  71. 'http://www.c-span.org/common/services/flashXml.php?programid=' + video_id,
  72. video_id)
  73. title = find_xpath_attr(doc, './/string', 'name', 'title').text
  74. thumbnail = find_xpath_attr(doc, './/string', 'name', 'poster').text
  75. senate_isvp_url = SenateISVPIE._search_iframe_url(webpage)
  76. if senate_isvp_url:
  77. surl = smuggle_url(senate_isvp_url, {'force_title': title})
  78. return self.url_result(surl, 'SenateISVP', video_id, title)
  79. files = data['video']['files']
  80. try:
  81. capfile = data['video']['capfile']['#text']
  82. except KeyError:
  83. capfile = None
  84. entries = [{
  85. 'id': '%s_%d' % (video_id, partnum + 1),
  86. 'title': (
  87. title if len(files) == 1 else
  88. '%s part %d' % (title, partnum + 1)),
  89. 'url': unescapeHTML(f['path']['#text']),
  90. 'description': description,
  91. 'thumbnail': thumbnail,
  92. 'duration': int_or_none(f.get('length', {}).get('#text')),
  93. 'subtitles': {
  94. 'en': [{
  95. 'url': capfile,
  96. 'ext': determine_ext(capfile, 'dfxp')
  97. }],
  98. } if capfile else None,
  99. } for partnum, f in enumerate(files)]
  100. if len(entries) == 1:
  101. entry = dict(entries[0])
  102. entry['id'] = video_id
  103. return entry
  104. else:
  105. return {
  106. '_type': 'playlist',
  107. 'entries': entries,
  108. 'title': title,
  109. 'id': video_id,
  110. }