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.

83 lines
3.2 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. def _real_extract(self, url):
  35. mobj = re.match(self._VALID_URL, url)
  36. page_id = mobj.group('id')
  37. webpage = self._download_webpage(url, page_id)
  38. video_id = self._search_regex(r'progid=\'?([0-9]+)\'?>', webpage, 'video id')
  39. description = self._html_search_regex(
  40. [
  41. # The full description
  42. r'<div class=\'expandable\'>(.*?)<a href=\'#\'',
  43. # If the description is small enough the other div is not
  44. # present, otherwise this is a stripped version
  45. r'<p class=\'initial\'>(.*?)</p>'
  46. ],
  47. webpage, 'description', flags=re.DOTALL)
  48. info_url = 'http://c-spanvideo.org/videoLibrary/assets/player/ajax-player.php?os=android&html5=program&id=' + video_id
  49. data = self._download_json(info_url, video_id)
  50. doc = self._download_xml(
  51. 'http://www.c-span.org/common/services/flashXml.php?programid=' + video_id,
  52. video_id)
  53. title = find_xpath_attr(doc, './/string', 'name', 'title').text
  54. thumbnail = find_xpath_attr(doc, './/string', 'name', 'poster').text
  55. files = data['video']['files']
  56. entries = [{
  57. 'id': '%s_%d' % (video_id, partnum + 1),
  58. 'title': (
  59. title if len(files) == 1 else
  60. '%s part %d' % (title, partnum + 1)),
  61. 'url': unescapeHTML(f['path']['#text']),
  62. 'description': description,
  63. 'thumbnail': thumbnail,
  64. 'duration': int_or_none(f.get('length', {}).get('#text')),
  65. } for partnum, f in enumerate(files)]
  66. return {
  67. '_type': 'playlist',
  68. 'entries': entries,
  69. 'title': title,
  70. 'id': video_id,
  71. }