| 
									
										
										
										
											2016-02-26 13:31:52 +01:00
										 |  |  | # coding: utf-8 | 
					
						
							|  |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-19 00:35:29 +07:00
										 |  |  | import re | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-26 13:31:52 +01:00
										 |  |  | from .common import InfoExtractor | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class CloserToTruthIE(InfoExtractor): | 
					
						
							| 
									
										
										
										
											2016-06-19 00:35:29 +07:00
										 |  |  |     _VALID_URL = r'https?://(?:www\.)?closertotruth\.com/(?:[^/]+/)*(?P<id>[^/?#&]+)' | 
					
						
							|  |  |  |     _TESTS = [{ | 
					
						
							|  |  |  |         'url': 'http://closertotruth.com/series/solutions-the-mind-body-problem#video-3688', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': '0_zof1ktre', | 
					
						
							|  |  |  |             'display_id': 'solutions-the-mind-body-problem', | 
					
						
							|  |  |  |             'ext': 'mov', | 
					
						
							|  |  |  |             'title': 'Solutions to the Mind-Body Problem?', | 
					
						
							|  |  |  |             'upload_date': '20140221', | 
					
						
							|  |  |  |             'timestamp': 1392956007, | 
					
						
							|  |  |  |             'uploader_id': 'CTTXML' | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         'params': { | 
					
						
							|  |  |  |             'skip_download': True, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'http://closertotruth.com/episodes/how-do-brains-work', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': '0_iuxai6g6', | 
					
						
							|  |  |  |             'display_id': 'how-do-brains-work', | 
					
						
							|  |  |  |             'ext': 'mov', | 
					
						
							|  |  |  |             'title': 'How do Brains Work?', | 
					
						
							|  |  |  |             'upload_date': '20140221', | 
					
						
							|  |  |  |             'timestamp': 1392956024, | 
					
						
							|  |  |  |             'uploader_id': 'CTTXML' | 
					
						
							| 
									
										
										
										
											2016-02-26 13:31:52 +01:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2016-06-19 00:35:29 +07:00
										 |  |  |         'params': { | 
					
						
							|  |  |  |             'skip_download': True, | 
					
						
							| 
									
										
										
										
											2016-02-26 13:31:52 +01:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2016-06-19 00:35:29 +07:00
										 |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'http://closertotruth.com/interviews/1725', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': '1725', | 
					
						
							|  |  |  |             'title': 'AyaFr-002', | 
					
						
							| 
									
										
										
										
											2016-02-26 13:31:52 +01:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2016-06-19 00:35:29 +07:00
										 |  |  |         'playlist_mincount': 2, | 
					
						
							|  |  |  |     }] | 
					
						
							| 
									
										
										
										
											2016-02-26 13:31:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2016-06-19 00:35:29 +07:00
										 |  |  |         display_id = self._match_id(url) | 
					
						
							| 
									
										
										
										
											2016-02-26 13:31:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-19 00:35:29 +07:00
										 |  |  |         webpage = self._download_webpage(url, display_id) | 
					
						
							| 
									
										
										
										
											2016-02-26 13:31:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-19 00:35:29 +07:00
										 |  |  |         partner_id = self._search_regex( | 
					
						
							|  |  |  |             r'<script[^>]+src=["\'].*?\b(?:partner_id|p)/(\d+)', | 
					
						
							|  |  |  |             webpage, 'kaltura partner_id') | 
					
						
							| 
									
										
										
										
											2016-02-26 13:31:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-19 00:35:29 +07:00
										 |  |  |         title = self._search_regex( | 
					
						
							|  |  |  |             r'<title>(.+?)\s*\|\s*.+?</title>', webpage, 'video title') | 
					
						
							| 
									
										
										
										
											2016-02-26 13:31:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-19 00:35:29 +07:00
										 |  |  |         select = self._search_regex( | 
					
						
							|  |  |  |             r'(?s)<select[^>]+id="select-version"[^>]*>(.+?)</select>', | 
					
						
							|  |  |  |             webpage, 'select version', default=None) | 
					
						
							|  |  |  |         if select: | 
					
						
							|  |  |  |             entry_ids = set() | 
					
						
							|  |  |  |             entries = [] | 
					
						
							|  |  |  |             for mobj in re.finditer( | 
					
						
							|  |  |  |                     r'<option[^>]+value=(["\'])(?P<id>[0-9a-z_]+)(?:#.+?)?\1[^>]*>(?P<title>[^<]+)', | 
					
						
							|  |  |  |                     webpage): | 
					
						
							|  |  |  |                 entry_id = mobj.group('id') | 
					
						
							|  |  |  |                 if entry_id in entry_ids: | 
					
						
							|  |  |  |                     continue | 
					
						
							|  |  |  |                 entry_ids.add(entry_id) | 
					
						
							|  |  |  |                 entries.append({ | 
					
						
							|  |  |  |                     '_type': 'url_transparent', | 
					
						
							|  |  |  |                     'url': 'kaltura:%s:%s' % (partner_id, entry_id), | 
					
						
							|  |  |  |                     'ie_key': 'Kaltura', | 
					
						
							|  |  |  |                     'title': mobj.group('title'), | 
					
						
							|  |  |  |                 }) | 
					
						
							|  |  |  |             if entries: | 
					
						
							|  |  |  |                 return self.playlist_result(entries, display_id, title) | 
					
						
							| 
									
										
										
										
											2016-02-26 13:31:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-19 00:35:29 +07:00
										 |  |  |         entry_id = self._search_regex( | 
					
						
							|  |  |  |             r'<a[^>]+id=(["\'])embed-kaltura\1[^>]+data-kaltura=(["\'])(?P<id>[0-9a-z_]+)\2', | 
					
						
							|  |  |  |             webpage, 'kaltura entry_id', group='id') | 
					
						
							| 
									
										
										
										
											2016-02-26 13:31:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |             '_type': 'url_transparent', | 
					
						
							| 
									
										
										
										
											2016-06-19 00:35:29 +07:00
										 |  |  |             'display_id': display_id, | 
					
						
							|  |  |  |             'url': 'kaltura:%s:%s' % (partner_id, entry_id), | 
					
						
							| 
									
										
										
										
											2016-02-26 13:31:52 +01:00
										 |  |  |             'ie_key': 'Kaltura', | 
					
						
							| 
									
										
										
										
											2016-06-19 00:35:29 +07:00
										 |  |  |             'title': title | 
					
						
							| 
									
										
										
										
											2016-02-26 13:31:52 +01:00
										 |  |  |         } |