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.

90 lines
3.4 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. )
  9. class CSpanIE(InfoExtractor):
  10. _VALID_URL = r'http://(?:www\.)?c-span\.org/video/\?(?P<id>[0-9a-f]+)'
  11. IE_DESC = 'C-SPAN'
  12. _TESTS = [{
  13. 'url': 'http://www.c-span.org/video/?313572-1/HolderonV',
  14. 'md5': '8e44ce11f0f725527daccc453f553eb0',
  15. 'info_dict': {
  16. 'id': '315139',
  17. 'ext': 'mp4',
  18. 'title': 'Attorney General Eric Holder on Voting Rights Act Decision',
  19. '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.',
  20. },
  21. 'skip': 'Regularly fails on travis, for unknown reasons',
  22. }, {
  23. 'url': 'http://www.c-span.org/video/?c4486943/cspan-international-health-care-models',
  24. # For whatever reason, the served video alternates between
  25. # two different ones
  26. #'md5': 'dbb0f047376d457f2ab8b3929cbb2d0c',
  27. 'info_dict': {
  28. 'id': '340723',
  29. 'ext': 'mp4',
  30. 'title': 'International Health Care Models',
  31. 'description': 'md5:7a985a2d595dba00af3d9c9f0783c967',
  32. }
  33. }, {
  34. 'url': 'http://www.c-span.org/video/?318608-1/gm-ignition-switch-recall',
  35. 'info_dict': {
  36. 'id': '342759',
  37. 'title': 'General Motors Ignition Switch Recall',
  38. },
  39. 'playlist_duration_sum': 14855,
  40. }]
  41. def _real_extract(self, url):
  42. mobj = re.match(self._VALID_URL, url)
  43. page_id = mobj.group('id')
  44. webpage = self._download_webpage(url, page_id)
  45. video_id = self._search_regex(r'progid=\'?([0-9]+)\'?>', webpage, 'video id')
  46. description = self._html_search_regex(
  47. [
  48. # The full description
  49. r'<div class=\'expandable\'>(.*?)<a href=\'#\'',
  50. # If the description is small enough the other div is not
  51. # present, otherwise this is a stripped version
  52. r'<p class=\'initial\'>(.*?)</p>'
  53. ],
  54. webpage, 'description', flags=re.DOTALL)
  55. info_url = 'http://c-spanvideo.org/videoLibrary/assets/player/ajax-player.php?os=android&html5=program&id=' + video_id
  56. data = self._download_json(info_url, video_id)
  57. doc = self._download_xml(
  58. 'http://www.c-span.org/common/services/flashXml.php?programid=' + video_id,
  59. video_id)
  60. title = find_xpath_attr(doc, './/string', 'name', 'title').text
  61. thumbnail = find_xpath_attr(doc, './/string', 'name', 'poster').text
  62. files = data['video']['files']
  63. entries = [{
  64. 'id': '%s_%d' % (video_id, partnum + 1),
  65. 'title': (
  66. title if len(files) == 1 else
  67. '%s part %d' % (title, partnum + 1)),
  68. 'url': unescapeHTML(f['path']['#text']),
  69. 'description': description,
  70. 'thumbnail': thumbnail,
  71. 'duration': int_or_none(f.get('length', {}).get('#text')),
  72. } for partnum, f in enumerate(files)]
  73. return {
  74. '_type': 'playlist',
  75. 'entries': entries,
  76. 'title': title,
  77. 'id': video_id,
  78. }