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.

60 lines
2.3 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>\d+)'
  10. IE_DESC = 'C-SPAN'
  11. _TEST = {
  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. def _real_extract(self, url):
  23. mobj = re.match(self._VALID_URL, url)
  24. page_id = mobj.group('id')
  25. webpage = self._download_webpage(url, page_id)
  26. video_id = self._search_regex(r'data-progid=\'(\d+)\'>', webpage, 'video id')
  27. description = self._html_search_regex(
  28. [
  29. # The full description
  30. r'<div class=\'expandable\'>(.*?)<a href=\'#\'',
  31. # If the description is small enough the other div is not
  32. # present, otherwise this is a stripped version
  33. r'<p class=\'initial\'>(.*?)</p>'
  34. ],
  35. webpage, 'description', flags=re.DOTALL)
  36. info_url = 'http://c-spanvideo.org/videoLibrary/assets/player/ajax-player.php?os=android&html5=program&id=' + video_id
  37. data = self._download_json(info_url, video_id)
  38. url = unescapeHTML(data['video']['files'][0]['path']['#text'])
  39. doc = self._download_xml('http://www.c-span.org/common/services/flashXml.php?programid=' + video_id,
  40. video_id)
  41. def find_string(s):
  42. return find_xpath_attr(doc, './/string', 'name', s).text
  43. return {
  44. 'id': video_id,
  45. 'title': find_string('title'),
  46. 'url': url,
  47. 'description': description,
  48. 'thumbnail': find_string('poster'),
  49. }