[closertotruth] Add extractor
[youtube-dl] / youtube_dl / extractor / closertotruth.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5
6
7 class CloserToTruthIE(InfoExtractor):
8     _VALID_URL = r'https?://(?:www\.)?closertotruth\.com/(episodes/|(series|interviews)/(?:[^#]+#video-)?(?P<id>\d+))'
9     _TESTS = [
10         {
11             'url': 'http://closertotruth.com/series/solutions-the-mind-body-problem#video-3688',
12             'md5': '5c548bde260a9247ddfdc07c7458ed29',
13             'info_dict': {
14                 'id': '0_zof1ktre',
15                 'ext': 'mov',
16                 'title': 'Solutions to the Mind-Body Problem?',
17                 'upload_date': '20140221',
18                 'timestamp': 1392956007,
19                 'uploader_id': 'CTTXML'
20             }
21         },
22         {
23             'url': 'http://closertotruth.com/interviews/1725',
24             'md5': 'b00598fd6a38372edb976408f72c5792',
25             'info_dict': {
26                 'id': '0_19qv5rn1',
27                 'ext': 'mov',
28                 'title': 'AyaFr-002 - Francisco J. Ayala',
29                 'upload_date': '20140307',
30                 'timestamp': 1394236431,
31                 'uploader_id': 'CTTXML'
32             }
33         },
34         {
35             'url': 'http://closertotruth.com/episodes/how-do-brains-work',
36             'md5': '4dd96aa0a5c296afa5c0bd24895c2f16',
37             'info_dict': {
38                 'id': '0_iuxai6g6',
39                 'ext': 'mov',
40                 'title': 'How do Brains Work?',
41                 'upload_date': '20140221',
42                 'timestamp': 1392956024,
43                 'uploader_id': 'CTTXML'
44             }
45         },
46     ]
47
48     def _real_extract(self, url):
49         video_id = self._match_id(url)
50         webpage = self._download_webpage(url, video_id)
51
52         video_title = self._search_regex(r'<title>(.+) \|.+</title>', webpage, 'video title')
53
54         entry_id = self._search_regex(r'<a[^>]+id="(?:video-%s|embed-kaltura)"[^>]+data-kaltura="([^"]+)' % video_id, webpage, "video entry_id")
55
56         interviewee_name = self._search_regex(r'<div id="(?:node_interview_full_group_white_wrapper|node_interview_series_full_group_ajax_content)"(?:.|\n)*<h3>(.*)</h3>.+', webpage, "video interviewee_name", False)
57
58         if interviewee_name:
59             video_title = video_title + ' - ' + interviewee_name
60
61         p_id = self._search_regex(r'<script[^>]+src=["\'].+?partner_id/(\d+)', webpage, "kaltura partner_id")
62
63         return {
64             '_type': 'url_transparent',
65             'id': entry_id,
66             'url': 'kaltura:%s:%s' % (p_id, entry_id),
67             'ie_key': 'Kaltura',
68             'title': video_title
69         }