| 
									
										
										
										
											2014-09-17 22:57:01 +03:00
										 |  |  | # coding: utf-8 | 
					
						
							|  |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 18:35:53 +02:00
										 |  |  | import re | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-17 22:57:01 +03:00
										 |  |  | from .common import InfoExtractor | 
					
						
							| 
									
										
										
										
											2014-12-13 12:24:42 +01:00
										 |  |  | from ..compat import ( | 
					
						
							| 
									
										
										
										
											2014-09-17 22:57:01 +03:00
										 |  |  |     compat_urllib_parse, | 
					
						
							| 
									
										
										
										
											2015-01-15 19:57:36 +02:00
										 |  |  |     compat_urllib_request, | 
					
						
							| 
									
										
										
										
											2014-12-13 12:24:42 +01:00
										 |  |  | ) | 
					
						
							|  |  |  | from ..utils import ( | 
					
						
							| 
									
										
										
										
											2015-01-22 18:35:53 +02:00
										 |  |  |     ExtractorError, | 
					
						
							| 
									
										
										
										
											2014-09-17 22:57:01 +03:00
										 |  |  |     remove_start, | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class VideoMegaIE(InfoExtractor): | 
					
						
							|  |  |  |     _VALID_URL = r'''(?x)https?://
 | 
					
						
							|  |  |  |         (?:www\.)?videomega\.tv/ | 
					
						
							|  |  |  |         (?:iframe\.php)?\?ref=(?P<id>[A-Za-z0-9]+) | 
					
						
							|  |  |  |         '''
 | 
					
						
							|  |  |  |     _TEST = { | 
					
						
							| 
									
										
										
										
											2015-01-15 19:57:36 +02:00
										 |  |  |         'url': 'http://videomega.tv/?ref=QR0HCUHI1661IHUCH0RQ', | 
					
						
							|  |  |  |         'md5': 'bf5c2f95c4c917536e80936af7bc51e1', | 
					
						
							| 
									
										
										
										
											2014-09-17 22:57:01 +03:00
										 |  |  |         'info_dict': { | 
					
						
							| 
									
										
										
										
											2015-01-15 19:57:36 +02:00
										 |  |  |             'id': 'QR0HCUHI1661IHUCH0RQ', | 
					
						
							| 
									
										
										
										
											2014-09-17 22:57:01 +03:00
										 |  |  |             'ext': 'mp4', | 
					
						
							| 
									
										
										
										
											2015-01-15 19:57:36 +02:00
										 |  |  |             'title': 'Big Buck Bunny', | 
					
						
							| 
									
										
										
										
											2014-09-17 22:57:01 +03:00
										 |  |  |             'thumbnail': 're:^https?://.*\.jpg$', | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2014-12-13 12:24:42 +01:00
										 |  |  |         video_id = self._match_id(url) | 
					
						
							| 
									
										
										
										
											2015-01-15 19:57:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         iframe_url = 'http://videomega.tv/iframe.php?ref={0:}'.format(video_id) | 
					
						
							|  |  |  |         req = compat_urllib_request.Request(iframe_url) | 
					
						
							|  |  |  |         req.add_header('Referer', url) | 
					
						
							|  |  |  |         webpage = self._download_webpage(req, video_id) | 
					
						
							| 
									
										
										
										
											2014-09-17 22:57:01 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 18:35:53 +02:00
										 |  |  |         try: | 
					
						
							|  |  |  |             escaped_data = re.findall(r'unescape\("([^"]+)"\)', webpage)[-1] | 
					
						
							|  |  |  |         except IndexError: | 
					
						
							|  |  |  |             raise ExtractorError('Unable to extract escaped data') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-17 22:57:01 +03:00
										 |  |  |         playlist = compat_urllib_parse.unquote(escaped_data) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         thumbnail = self._search_regex( | 
					
						
							|  |  |  |             r'image:\s*"([^"]+)"', playlist, 'thumbnail', fatal=False) | 
					
						
							| 
									
										
										
										
											2015-01-15 19:57:36 +02:00
										 |  |  |         video_url = self._search_regex(r'file:\s*"([^"]+)"', playlist, 'URL') | 
					
						
							| 
									
										
										
										
											2014-09-18 00:18:27 +02:00
										 |  |  |         title = remove_start(self._html_search_regex( | 
					
						
							|  |  |  |             r'<title>(.*?)</title>', webpage, 'title'), 'VideoMega.tv - ') | 
					
						
							| 
									
										
										
										
											2014-09-17 22:57:01 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-18 00:18:27 +02:00
										 |  |  |         formats = [{ | 
					
						
							| 
									
										
										
										
											2014-09-17 22:57:01 +03:00
										 |  |  |             'format_id': 'sd', | 
					
						
							| 
									
										
										
										
											2015-01-15 19:57:36 +02:00
										 |  |  |             'url': video_url, | 
					
						
							| 
									
										
										
										
											2014-09-18 00:18:27 +02:00
										 |  |  |         }] | 
					
						
							|  |  |  |         self._sort_formats(formats) | 
					
						
							| 
									
										
										
										
											2014-09-17 22:57:01 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |             'id': video_id, | 
					
						
							|  |  |  |             'title': title, | 
					
						
							|  |  |  |             'formats': formats, | 
					
						
							|  |  |  |             'thumbnail': thumbnail, | 
					
						
							| 
									
										
										
										
											2015-01-24 18:19:58 +01:00
										 |  |  |             'http_headers': { | 
					
						
							|  |  |  |                 'Referer': iframe_url, | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2014-09-17 22:57:01 +03:00
										 |  |  |         } |