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.

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