| 
									
										
										
										
											2014-04-28 20:32:13 +02:00
										 |  |  | # coding: utf-8 | 
					
						
							|  |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from .common import InfoExtractor | 
					
						
							| 
									
										
										
										
											2015-05-24 21:09:08 +06:00
										 |  |  | from ..utils import ( | 
					
						
							|  |  |  |     int_or_none, | 
					
						
							| 
									
										
										
										
											2016-04-21 22:52:49 +01:00
										 |  |  |     ExtractorError, | 
					
						
							| 
									
										
										
										
											2015-05-24 21:09:08 +06:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2014-04-28 20:32:13 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-29 19:41:58 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | class RTBFIE(InfoExtractor): | 
					
						
							| 
									
										
										
										
											2016-04-21 22:52:49 +01:00
										 |  |  |     _VALID_URL = r'''(?x)
 | 
					
						
							|  |  |  |         https?://(?:www\.)?rtbf\.be/ | 
					
						
							|  |  |  |         (?: | 
					
						
							|  |  |  |             video/[^?]+\?.*\bid=| | 
					
						
							|  |  |  |             ouftivi/(?:[^/]+/)*[^?]+\?.*\bvideoId=| | 
					
						
							|  |  |  |             auvio/[^/]+\?.*id= | 
					
						
							|  |  |  |         )(?P<id>\d+)'''
 | 
					
						
							| 
									
										
										
										
											2015-11-08 17:01:45 +06:00
										 |  |  |     _TESTS = [{ | 
					
						
							|  |  |  |         'url': 'https://www.rtbf.be/video/detail_les-diables-au-coeur-episode-2?id=1921274', | 
					
						
							|  |  |  |         'md5': '799f334ddf2c0a582ba80c44655be570', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': '1921274', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': 'Les Diables au coeur (épisode 2)', | 
					
						
							| 
									
										
										
										
											2016-04-21 22:52:49 +01:00
										 |  |  |             'description': 'Football - Diables Rouges', | 
					
						
							| 
									
										
										
										
											2015-11-08 17:01:45 +06:00
										 |  |  |             'duration': 3099, | 
					
						
							| 
									
										
										
										
											2016-04-21 22:52:49 +01:00
										 |  |  |             'upload_date': '20140425', | 
					
						
							|  |  |  |             'timestamp': 1398456336, | 
					
						
							|  |  |  |             'uploader': 'rtbfsport', | 
					
						
							| 
									
										
										
										
											2015-11-08 17:01:45 +06:00
										 |  |  |         } | 
					
						
							|  |  |  |     }, { | 
					
						
							|  |  |  |         # geo restricted | 
					
						
							|  |  |  |         'url': 'http://www.rtbf.be/ouftivi/heros/detail_scooby-doo-mysteres-associes?id=1097&videoId=2057442', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							|  |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'http://www.rtbf.be/ouftivi/niouzz?videoId=2055858', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							| 
									
										
										
										
											2016-04-21 22:52:49 +01:00
										 |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'http://www.rtbf.be/auvio/detail_jeudi-en-prime-siegfried-bracke?id=2102996', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							| 
									
										
										
										
											2015-11-08 17:01:45 +06:00
										 |  |  |     }] | 
					
						
							| 
									
										
										
										
											2016-04-21 22:52:49 +01:00
										 |  |  |     _IMAGE_HOST = 'http://ds1.ds.static.rtbf.be' | 
					
						
							|  |  |  |     _PROVIDERS = { | 
					
						
							|  |  |  |         'YOUTUBE': 'Youtube', | 
					
						
							|  |  |  |         'DAILYMOTION': 'Dailymotion', | 
					
						
							|  |  |  |         'VIMEO': 'Vimeo', | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-06-10 14:12:43 +02:00
										 |  |  |     _QUALITIES = [ | 
					
						
							| 
									
										
										
										
											2016-04-21 22:52:49 +01:00
										 |  |  |         ('mobile', 'SD'), | 
					
						
							|  |  |  |         ('web', 'MD'), | 
					
						
							| 
									
										
										
										
											2015-06-10 14:12:43 +02:00
										 |  |  |         ('high', 'HD'), | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-28 20:32:13 +02:00
										 |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2015-05-24 21:09:08 +06:00
										 |  |  |         video_id = self._match_id(url) | 
					
						
							| 
									
										
										
										
											2016-04-21 22:52:49 +01:00
										 |  |  |         data = self._download_json( | 
					
						
							|  |  |  |             'http://www.rtbf.be/api/media/video?method=getVideoDetail&args[]=%s' % video_id, video_id) | 
					
						
							| 
									
										
										
										
											2014-04-28 20:32:13 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-21 22:52:49 +01:00
										 |  |  |         error = data.get('error') | 
					
						
							|  |  |  |         if error: | 
					
						
							|  |  |  |             raise ExtractorError('%s said: %s' % (self.IE_NAME, error), expected=True) | 
					
						
							| 
									
										
										
										
											2014-04-29 19:41:58 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-21 22:52:49 +01:00
										 |  |  |         data = data['data'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         provider = data.get('provider') | 
					
						
							|  |  |  |         if provider in self._PROVIDERS: | 
					
						
							|  |  |  |             return self.url_result(data['url'], self._PROVIDERS[provider]) | 
					
						
							| 
									
										
										
										
											2014-04-28 20:32:13 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-10 14:12:43 +02:00
										 |  |  |         formats = [] | 
					
						
							|  |  |  |         for key, format_id in self._QUALITIES: | 
					
						
							| 
									
										
										
										
											2016-04-21 22:52:49 +01:00
										 |  |  |             format_url = data.get(key + 'Url') | 
					
						
							| 
									
										
										
										
											2015-06-10 14:12:43 +02:00
										 |  |  |             if format_url: | 
					
						
							|  |  |  |                 formats.append({ | 
					
						
							|  |  |  |                     'format_id': format_id, | 
					
						
							|  |  |  |                     'url': format_url, | 
					
						
							|  |  |  |                 }) | 
					
						
							| 
									
										
										
										
											2014-04-28 20:32:13 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-21 22:52:49 +01:00
										 |  |  |         thumbnails = [] | 
					
						
							|  |  |  |         for thumbnail_id, thumbnail_url in data.get('thumbnail', {}).items(): | 
					
						
							|  |  |  |             if thumbnail_id != 'default': | 
					
						
							|  |  |  |                 thumbnails.append({ | 
					
						
							|  |  |  |                     'url': self._IMAGE_HOST + thumbnail_url, | 
					
						
							|  |  |  |                     'id': thumbnail_id, | 
					
						
							|  |  |  |                 }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-28 20:32:13 +02:00
										 |  |  |         return { | 
					
						
							|  |  |  |             'id': video_id, | 
					
						
							| 
									
										
										
										
											2015-06-10 14:12:43 +02:00
										 |  |  |             'formats': formats, | 
					
						
							| 
									
										
										
										
											2014-04-29 19:41:58 +07:00
										 |  |  |             'title': data['title'], | 
					
						
							|  |  |  |             'description': data.get('description') or data.get('subtitle'), | 
					
						
							| 
									
										
										
										
											2016-04-21 22:52:49 +01:00
										 |  |  |             'thumbnails': thumbnails, | 
					
						
							| 
									
										
										
										
											2014-04-29 19:41:58 +07:00
										 |  |  |             'duration': data.get('duration') or data.get('realDuration'), | 
					
						
							| 
									
										
										
										
											2015-05-24 21:09:08 +06:00
										 |  |  |             'timestamp': int_or_none(data.get('created')), | 
					
						
							|  |  |  |             'view_count': int_or_none(data.get('viewCount')), | 
					
						
							| 
									
										
										
										
											2016-04-21 22:52:49 +01:00
										 |  |  |             'uploader': data.get('channel'), | 
					
						
							|  |  |  |             'tags': data.get('tags'), | 
					
						
							| 
									
										
										
										
											2014-04-28 20:32:13 +02:00
										 |  |  |         } |