| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2015-03-19 19:37:39 +02:00
										 |  |  | from ..compat import compat_urllib_request | 
					
						
							| 
									
										
										
										
											2014-09-17 22:57:01 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class VideoMegaIE(InfoExtractor): | 
					
						
							| 
									
										
										
										
											2015-07-18 04:27:09 +06:00
										 |  |  |     _VALID_URL = r'(?:videomega:|https?://(?:www\.)?videomega\.tv/(?:(?:view|iframe|cdn)\.php)?\?ref=)(?P<id>[A-Za-z0-9]+)' | 
					
						
							| 
									
										
										
										
											2015-07-18 04:25:30 +06:00
										 |  |  |     _TESTS = [{ | 
					
						
							| 
									
										
										
										
											2015-07-18 04:25:10 +06:00
										 |  |  |         'url': 'http://videomega.tv/cdn.php?ref=AOSQBJYKIDDIKYJBQSOA', | 
					
						
							| 
									
										
										
										
											2015-07-18 04:13:45 +06:00
										 |  |  |         'md5': 'cc1920a58add3f05c6a93285b84fb3aa', | 
					
						
							| 
									
										
										
										
											2014-09-17 22:57:01 +03:00
										 |  |  |         'info_dict': { | 
					
						
							| 
									
										
										
										
											2015-07-18 04:13:45 +06:00
										 |  |  |             'id': 'AOSQBJYKIDDIKYJBQSOA', | 
					
						
							| 
									
										
										
										
											2014-09-17 22:57:01 +03:00
										 |  |  |             'ext': 'mp4', | 
					
						
							| 
									
										
										
										
											2015-07-18 04:13:45 +06:00
										 |  |  |             'title': '1254207', | 
					
						
							| 
									
										
										
										
											2014-09-17 22:57:01 +03:00
										 |  |  |             'thumbnail': 're:^https?://.*\.jpg$', | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-07-18 04:25:30 +06:00
										 |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'http://videomega.tv/cdn.php?ref=AOSQBJYKIDDIKYJBQSOA&width=1070&height=600', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							|  |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'http://videomega.tv/view.php?ref=090051111052065112106089103052052103089106112065052111051090', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							|  |  |  |     }] | 
					
						
							| 
									
										
										
										
											2014-09-17 22:57:01 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-18 04:25:10 +06:00
										 |  |  |         iframe_url = 'http://videomega.tv/cdn.php?ref=%s' % video_id | 
					
						
							|  |  |  |         req = compat_urllib_request.Request(iframe_url) | 
					
						
							| 
									
										
										
										
											2015-01-15 19:57:36 +02:00
										 |  |  |         req.add_header('Referer', url) | 
					
						
							| 
									
										
										
										
											2015-07-18 04:13:45 +06:00
										 |  |  |         req.add_header('Cookie', 'noadvtday=0') | 
					
						
							| 
									
										
										
										
											2015-01-15 19:57:36 +02:00
										 |  |  |         webpage = self._download_webpage(req, video_id) | 
					
						
							| 
									
										
										
										
											2014-09-17 22:57:01 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-19 19:37:39 +02:00
										 |  |  |         title = self._html_search_regex( | 
					
						
							| 
									
										
										
										
											2015-07-18 04:13:45 +06:00
										 |  |  |             r'<title>(.+?)</title>', webpage, 'title') | 
					
						
							| 
									
										
										
										
											2015-03-19 19:37:39 +02:00
										 |  |  |         title = re.sub( | 
					
						
							| 
									
										
										
										
											2015-07-18 04:13:45 +06:00
										 |  |  |             r'(?:^[Vv]ideo[Mm]ega\.tv\s-\s*|\s*-\svideomega\.tv$)', '', title) | 
					
						
							| 
									
										
										
										
											2014-09-17 22:57:01 +03:00
										 |  |  |         thumbnail = self._search_regex( | 
					
						
							| 
									
										
										
										
											2015-03-19 19:37:39 +02:00
										 |  |  |             r'<video[^>]+?poster="([^"]+)"', webpage, 'thumbnail', fatal=False) | 
					
						
							|  |  |  |         video_url = self._search_regex( | 
					
						
							|  |  |  |             r'<source[^>]+?src="([^"]+)"', webpage, 'video URL') | 
					
						
							| 
									
										
										
										
											2014-09-17 22:57:01 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |             'id': video_id, | 
					
						
							|  |  |  |             'title': title, | 
					
						
							| 
									
										
										
										
											2015-03-19 19:37:39 +02:00
										 |  |  |             'url': video_url, | 
					
						
							| 
									
										
										
										
											2014-09-17 22:57:01 +03:00
										 |  |  |             'thumbnail': thumbnail, | 
					
						
							| 
									
										
										
										
											2015-01-24 18:19:58 +01:00
										 |  |  |             'http_headers': { | 
					
						
							| 
									
										
										
										
											2015-07-18 04:25:10 +06:00
										 |  |  |                 'Referer': iframe_url, | 
					
						
							| 
									
										
										
										
											2015-01-24 18:19:58 +01:00
										 |  |  |             }, | 
					
						
							| 
									
										
										
										
											2014-09-17 22:57:01 +03:00
										 |  |  |         } |