2014-01-05 12:30:00 +09:00
from __future__ import unicode_literals
2013-06-27 00:55:54 +09:00
import re
from . common import InfoExtractor
from . . utils import (
2014-01-05 12:30:00 +09:00
unescapeHTML ,
2014-02-03 02:24:20 +09:00
find_xpath_attr ,
2013-06-27 00:55:54 +09:00
)
2014-01-05 12:30:00 +09:00
2013-06-27 00:55:54 +09:00
class CSpanIE ( InfoExtractor ) :
2014-02-03 02:24:20 +09:00
_VALID_URL = r ' http://(?:www \ .)?c-span \ .org/video/ \ ?(?P<id> \ d+) '
2014-01-05 12:30:00 +09:00
IE_DESC = ' C-SPAN '
2013-06-28 03:46:46 +09:00
_TEST = {
2014-02-03 02:24:20 +09:00
' url ' : ' http://www.c-span.org/video/?313572-1/HolderonV ' ,
2014-01-05 12:30:00 +09:00
' md5 ' : ' 8e44ce11f0f725527daccc453f553eb0 ' ,
' info_dict ' : {
2014-02-03 02:24:20 +09:00
' id ' : ' 315139 ' ,
' ext ' : ' mp4 ' ,
2014-01-05 12:30:00 +09:00
' title ' : ' Attorney General Eric Holder on Voting Rights Act Decision ' ,
2014-02-03 02:24:20 +09:00
' 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. ' ,
2013-06-28 03:46:46 +09:00
} ,
2014-01-22 23:10:00 +09:00
' skip ' : ' Regularly fails on travis, for unknown reasons ' ,
2013-06-28 03:46:46 +09:00
}
2013-06-27 00:55:54 +09:00
def _real_extract ( self , url ) :
mobj = re . match ( self . _VALID_URL , url )
2014-02-03 02:24:20 +09:00
page_id = mobj . group ( ' id ' )
webpage = self . _download_webpage ( url , page_id )
video_id = self . _search_regex ( r ' data-progid= \' ( \ d+) \' > ' , webpage , ' video id ' )
description = self . _html_search_regex (
[
# The full description
r ' <div class= \' expandable \' >(.*?)<a href= \' # \' ' ,
# If the description is small enough the other div is not
# present, otherwise this is a stripped version
r ' <p class= \' initial \' >(.*?)</p> '
] ,
webpage , ' description ' , flags = re . DOTALL )
2014-01-05 12:30:00 +09:00
info_url = ' http://c-spanvideo.org/videoLibrary/assets/player/ajax-player.php?os=android&html5=program&id= ' + video_id
2014-02-03 02:24:20 +09:00
data = self . _download_json ( info_url , video_id )
2014-01-05 12:30:00 +09:00
url = unescapeHTML ( data [ ' video ' ] [ ' files ' ] [ 0 ] [ ' path ' ] [ ' #text ' ] )
2014-02-03 02:24:20 +09:00
doc = self . _download_xml ( ' http://www.c-span.org/common/services/flashXml.php?programid= ' + video_id ,
video_id )
def find_string ( s ) :
return find_xpath_attr ( doc , ' .//string ' , ' name ' , s ) . text
2014-01-05 12:30:00 +09:00
return {
' id ' : video_id ,
2014-02-03 02:24:20 +09:00
' title ' : find_string ( ' title ' ) ,
2014-01-05 12:30:00 +09:00
' url ' : url ,
' description ' : description ,
2014-02-03 02:24:20 +09:00
' thumbnail ' : find_string ( ' poster ' ) ,
2014-01-05 12:30:00 +09:00
}