| 
									
										
										
										
											2014-01-07 09:45:40 +01:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-16 13:56:13 +01:00
										 |  |  | import datetime | 
					
						
							|  |  |  | import json | 
					
						
							|  |  |  | import re | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from .common import InfoExtractor | 
					
						
							|  |  |  | from ..utils import ( | 
					
						
							|  |  |  |     remove_start, | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class BlinkxIE(InfoExtractor): | 
					
						
							| 
									
										
										
										
											2013-12-22 07:43:54 +01:00
										 |  |  |     _VALID_URL = r'^(?:https?://(?:www\.)blinkx\.com/#?ce/|blinkx:)(?P<id>[^?]+)' | 
					
						
							| 
									
										
										
										
											2014-01-07 09:45:58 +01:00
										 |  |  |     IE_NAME = 'blinkx' | 
					
						
							| 
									
										
										
										
											2013-12-16 13:56:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     _TEST = { | 
					
						
							| 
									
										
										
										
											2014-01-07 09:45:40 +01:00
										 |  |  |         'url': 'http://www.blinkx.com/ce/8aQUy7GVFYgFzpKhT0oqsilwOGFRVXk3R1ZGWWdGenBLaFQwb3FzaWx3OGFRVXk3R1ZGWWdGenB', | 
					
						
							|  |  |  |         'file': '8aQUy7GV.mp4', | 
					
						
							|  |  |  |         'md5': '2e9a07364af40163a908edbf10bb2492', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             "title": "Police Car Rolls Away", | 
					
						
							|  |  |  |             "uploader": "stupidvideos.com", | 
					
						
							|  |  |  |             "upload_date": "20131215", | 
					
						
							|  |  |  |             "description": "A police car gently rolls away from a fight. Maybe it felt weird being around a confrontation and just had to get out of there!", | 
					
						
							|  |  |  |             "duration": 14.886, | 
					
						
							|  |  |  |             "thumbnails": [{ | 
					
						
							| 
									
										
										
										
											2013-12-16 13:56:13 +01:00
										 |  |  |                 "width": 100, | 
					
						
							|  |  |  |                 "height": 76, | 
					
						
							|  |  |  |                 "url": "http://cdn.blinkx.com/stream/b/41/StupidVideos/20131215/1873969261/1873969261_tn_0.jpg", | 
					
						
							|  |  |  |             }], | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-07 09:45:40 +01:00
										 |  |  |     def _real_extract(self, rl): | 
					
						
							|  |  |  |         m = re.match(self._VALID_URL, rl) | 
					
						
							| 
									
										
										
										
											2013-12-16 13:56:13 +01:00
										 |  |  |         video_id = m.group('id') | 
					
						
							|  |  |  |         display_id = video_id[:8] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         api_url = (u'https://apib4.blinkx.com/api.php?action=play_video&' + | 
					
						
							| 
									
										
										
										
											2014-01-07 09:45:40 +01:00
										 |  |  |                    'video=%s' % video_id) | 
					
						
							| 
									
										
										
										
											2013-12-16 13:56:13 +01:00
										 |  |  |         data_json = self._download_webpage(api_url, display_id) | 
					
						
							|  |  |  |         data = json.loads(data_json)['api']['results'][0] | 
					
						
							|  |  |  |         dt = datetime.datetime.fromtimestamp(data['pubdate_epoch']) | 
					
						
							| 
									
										
										
										
											2014-01-07 09:45:40 +01:00
										 |  |  |         pload_date = dt.strftime('%Y%m%d') | 
					
						
							| 
									
										
										
										
											2013-12-16 13:56:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         duration = None | 
					
						
							|  |  |  |         thumbnails = [] | 
					
						
							|  |  |  |         formats = [] | 
					
						
							|  |  |  |         for m in data['media']: | 
					
						
							|  |  |  |             if m['type'] == 'jpg': | 
					
						
							|  |  |  |                 thumbnails.append({ | 
					
						
							|  |  |  |                     'url': m['link'], | 
					
						
							|  |  |  |                     'width': int(m['w']), | 
					
						
							|  |  |  |                     'height': int(m['h']), | 
					
						
							|  |  |  |                 }) | 
					
						
							|  |  |  |             elif m['type'] == 'original': | 
					
						
							|  |  |  |                 duration = m['d'] | 
					
						
							| 
									
										
										
										
											2013-12-19 21:02:25 +01:00
										 |  |  |             elif m['type'] == 'youtube': | 
					
						
							|  |  |  |                 yt_id = m['link'] | 
					
						
							|  |  |  |                 self.to_screen(u'Youtube video detected: %s' % yt_id) | 
					
						
							|  |  |  |                 return self.url_result(yt_id, 'Youtube', video_id=yt_id) | 
					
						
							| 
									
										
										
										
											2013-12-16 13:56:13 +01:00
										 |  |  |             elif m['type'] in ('flv', 'mp4'): | 
					
						
							|  |  |  |                 vcodec = remove_start(m['vcodec'], 'ff') | 
					
						
							|  |  |  |                 acodec = remove_start(m['acodec'], 'ff') | 
					
						
							| 
									
										
										
										
											2013-12-26 21:05:30 +01:00
										 |  |  |                 tbr = (int(m['vbr']) + int(m['abr'])) // 1000 | 
					
						
							| 
									
										
										
										
											2013-12-16 13:56:13 +01:00
										 |  |  |                 format_id = (u'%s-%sk-%s' % | 
					
						
							|  |  |  |                              (vcodec, | 
					
						
							| 
									
										
										
										
											2013-12-26 21:05:30 +01:00
										 |  |  |                               tbr, | 
					
						
							| 
									
										
										
										
											2013-12-16 13:56:13 +01:00
										 |  |  |                               m['w'])) | 
					
						
							|  |  |  |                 formats.append({ | 
					
						
							|  |  |  |                     'format_id': format_id, | 
					
						
							|  |  |  |                     'url': m['link'], | 
					
						
							|  |  |  |                     'vcodec': vcodec, | 
					
						
							|  |  |  |                     'acodec': acodec, | 
					
						
							|  |  |  |                     'abr': int(m['abr']) // 1000, | 
					
						
							|  |  |  |                     'vbr': int(m['vbr']) // 1000, | 
					
						
							| 
									
										
										
										
											2013-12-26 21:05:30 +01:00
										 |  |  |                     'tbr': tbr, | 
					
						
							| 
									
										
										
										
											2013-12-16 13:56:13 +01:00
										 |  |  |                     'width': int(m['w']), | 
					
						
							|  |  |  |                     'height': int(m['h']), | 
					
						
							|  |  |  |                 }) | 
					
						
							| 
									
										
										
										
											2013-12-26 21:05:30 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         self._sort_formats(formats) | 
					
						
							| 
									
										
										
										
											2013-12-16 13:56:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |             'id': display_id, | 
					
						
							|  |  |  |             'fullid': video_id, | 
					
						
							|  |  |  |             'title': data['title'], | 
					
						
							|  |  |  |             'formats': formats, | 
					
						
							|  |  |  |             'uploader': data['channel_name'], | 
					
						
							| 
									
										
										
										
											2014-01-07 09:45:40 +01:00
										 |  |  |             'upload_date': pload_date, | 
					
						
							| 
									
										
										
										
											2013-12-16 13:56:13 +01:00
										 |  |  |             'description': data.get('description'), | 
					
						
							|  |  |  |             'thumbnails': thumbnails, | 
					
						
							|  |  |  |             'duration': duration, | 
					
						
							|  |  |  |         } |