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.

71 lines
2.7 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. unescapeHTML,
  6. find_xpath_attr,
  7. )
  8. class CSpanIE(InfoExtractor):
  9. _VALID_URL = r'http://(?:www\.)?c-span\.org/video/\?(?P<id>[0-9a-f]+)'
  10. IE_DESC = 'C-SPAN'
  11. _TESTS = [{
  12. 'url': 'http://www.c-span.org/video/?313572-1/HolderonV',
  13. 'md5': '8e44ce11f0f725527daccc453f553eb0',
  14. 'info_dict': {
  15. 'id': '315139',
  16. 'ext': 'mp4',
  17. 'title': 'Attorney General Eric Holder on Voting Rights Act Decision',
  18. '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.',
  19. },
  20. 'skip': 'Regularly fails on travis, for unknown reasons',
  21. }, {
  22. 'url': 'http://www.c-span.org/video/?c4486943/cspan-international-health-care-models',
  23. # For whatever reason, the served video alternates between
  24. # two different ones
  25. #'md5': 'dbb0f047376d457f2ab8b3929cbb2d0c',
  26. 'info_dict': {
  27. 'id': '340723',
  28. 'ext': 'mp4',
  29. 'title': 'International Health Care Models',
  30. 'description': 'md5:7a985a2d595dba00af3d9c9f0783c967',
  31. }
  32. }]
  33. def _real_extract(self, url):
  34. mobj = re.match(self._VALID_URL, url)
  35. page_id = mobj.group('id')
  36. webpage = self._download_webpage(url, page_id)
  37. video_id = self._search_regex(r'progid=\'?([0-9]+)\'?>', webpage, 'video id')
  38. description = self._html_search_regex(
  39. [
  40. # The full description
  41. r'<div class=\'expandable\'>(.*?)<a href=\'#\'',
  42. # If the description is small enough the other div is not
  43. # present, otherwise this is a stripped version
  44. r'<p class=\'initial\'>(.*?)</p>'
  45. ],
  46. webpage, 'description', flags=re.DOTALL)
  47. info_url = 'http://c-spanvideo.org/videoLibrary/assets/player/ajax-player.php?os=android&html5=program&id=' + video_id
  48. data = self._download_json(info_url, video_id)
  49. url = unescapeHTML(data['video']['files'][0]['path']['#text'])
  50. doc = self._download_xml('http://www.c-span.org/common/services/flashXml.php?programid=' + video_id,
  51. video_id)
  52. def find_string(s):
  53. return find_xpath_attr(doc, './/string', 'name', s).text
  54. return {
  55. 'id': video_id,
  56. 'title': find_string('title'),
  57. 'url': url,
  58. 'description': description,
  59. 'thumbnail': find_string('poster'),
  60. }