Merge remote-tracking branch 'epitron/metadata-pp'
[youtube-dl] / youtube_dl / extractor / cspan.py
1 from __future__ import unicode_literals
2
3 import json
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8     unescapeHTML,
9 )
10
11
12 class CSpanIE(InfoExtractor):
13     _VALID_URL = r'http://www\.c-spanvideo\.org/program/(.*)'
14     IE_DESC = 'C-SPAN'
15     _TEST = {
16         'url': 'http://www.c-spanvideo.org/program/HolderonV',
17         'file': '315139.mp4',
18         'md5': '8e44ce11f0f725527daccc453f553eb0',
19         'info_dict': {
20             'title': 'Attorney General Eric Holder on Voting Rights Act Decision',
21             '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.',
22         },
23     }
24
25     def _real_extract(self, url):
26         mobj = re.match(self._VALID_URL, url)
27         prog_name = mobj.group(1)
28         webpage = self._download_webpage(url, prog_name)
29         video_id = self._search_regex(r'programid=(.*?)&', webpage, 'video id')
30
31         title = self._html_search_regex(
32             r'<!-- title -->\n\s*<h1[^>]*>(.*?)</h1>', webpage, 'title')
33         description = self._og_search_description(webpage)
34
35         info_url = 'http://c-spanvideo.org/videoLibrary/assets/player/ajax-player.php?os=android&html5=program&id=' + video_id
36         data_json = self._download_webpage(
37             info_url, video_id, 'Downloading video info')
38         data = json.loads(data_json)
39
40         url = unescapeHTML(data['video']['files'][0]['path']['#text'])
41
42         return {
43             'id': video_id,
44             'title': title,
45             'url': url,
46             'description': description,
47             'thumbnail': self._og_search_thumbnail(webpage),
48         }