| 
									
										
										
										
											2014-01-29 15:21:12 +01:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							| 
									
										
										
										
											2014-07-15 19:32:42 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-29 17:29:40 +02:00
										 |  |  | import base64 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from .common import InfoExtractor | 
					
						
							| 
									
										
										
										
											2014-12-13 12:24:42 +01:00
										 |  |  | from ..compat import compat_parse_qs | 
					
						
							| 
									
										
										
										
											2013-06-29 17:29:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-29 15:21:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-29 17:29:40 +02:00
										 |  |  | class TutvIE(InfoExtractor): | 
					
						
							| 
									
										
										
										
											2014-01-29 15:21:12 +01:00
										 |  |  |     _VALID_URL = r'https?://(?:www\.)?tu\.tv/videos/(?P<id>[^/?]+)' | 
					
						
							| 
									
										
										
										
											2013-06-29 17:29:40 +02:00
										 |  |  |     _TEST = { | 
					
						
							| 
									
										
										
										
											2014-07-15 19:32:42 +07:00
										 |  |  |         'url': 'http://tu.tv/videos/robots-futbolistas', | 
					
						
							|  |  |  |         'md5': '627c7c124ac2a9b5ab6addb94e0e65f7', | 
					
						
							| 
									
										
										
										
											2014-01-29 15:21:12 +01:00
										 |  |  |         'info_dict': { | 
					
						
							| 
									
										
										
										
											2014-07-15 19:32:42 +07:00
										 |  |  |             'id': '2973058', | 
					
						
							|  |  |  |             'ext': 'flv', | 
					
						
							|  |  |  |             'title': 'Robots futbolistas', | 
					
						
							| 
									
										
										
										
											2014-01-29 15:21:12 +01:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2013-06-29 17:29:40 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2014-12-13 12:24:42 +01:00
										 |  |  |         video_id = self._match_id(url) | 
					
						
							| 
									
										
										
										
											2013-06-29 17:29:40 +02:00
										 |  |  |         webpage = self._download_webpage(url, video_id) | 
					
						
							| 
									
										
										
										
											2014-12-13 12:24:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-29 15:21:12 +01:00
										 |  |  |         internal_id = self._search_regex(r'codVideo=([0-9]+)', webpage, 'internal video ID') | 
					
						
							| 
									
										
										
										
											2013-06-29 17:29:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-15 19:32:42 +07:00
										 |  |  |         data_content = self._download_webpage( | 
					
						
							|  |  |  |             'http://tu.tv/flvurl.php?codVideo=%s' % internal_id, video_id, 'Downloading video info') | 
					
						
							|  |  |  |         video_url = base64.b64decode(compat_parse_qs(data_content)['kpt'][0]).decode('utf-8') | 
					
						
							| 
									
										
										
										
											2013-06-29 17:29:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-29 15:21:12 +01:00
										 |  |  |         return { | 
					
						
							| 
									
										
										
										
											2013-06-29 17:29:40 +02:00
										 |  |  |             'id': internal_id, | 
					
						
							|  |  |  |             'url': video_url, | 
					
						
							| 
									
										
										
										
											2013-07-12 19:00:19 +02:00
										 |  |  |             'title': self._og_search_title(webpage), | 
					
						
							| 
									
										
										
										
											2013-06-29 17:29:40 +02:00
										 |  |  |         } |