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