| 
									
										
										
										
											2014-08-29 00:20:10 +03:00
										 |  |  | # coding: utf-8 | 
					
						
							|  |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import re | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from .common import InfoExtractor | 
					
						
							| 
									
										
										
										
											2014-12-13 12:24:42 +01:00
										 |  |  | from ..utils import ( | 
					
						
							|  |  |  |     determine_ext, | 
					
						
							|  |  |  |     ExtractorError, | 
					
						
							| 
									
										
										
										
											2016-03-26 02:19:24 +06:00
										 |  |  |     urlencode_postdata, | 
					
						
							| 
									
										
										
										
											2014-12-13 12:24:42 +01:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2014-08-29 00:20:10 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class PromptFileIE(InfoExtractor): | 
					
						
							|  |  |  |     _VALID_URL = r'https?://(?:www\.)?promptfile\.com/l/(?P<id>[0-9A-Z\-]+)' | 
					
						
							|  |  |  |     _TEST = { | 
					
						
							| 
									
										
										
										
											2016-09-25 12:44:46 +02:00
										 |  |  |         'url': 'http://www.promptfile.com/l/86D1CE8462-576CAAE416', | 
					
						
							|  |  |  |         'md5': '5a7e285a26e0d66d9a263fae91bc92ce', | 
					
						
							| 
									
										
										
										
											2014-08-29 00:20:10 +03:00
										 |  |  |         'info_dict': { | 
					
						
							| 
									
										
										
										
											2016-09-25 12:44:46 +02:00
										 |  |  |             'id': '86D1CE8462-576CAAE416', | 
					
						
							| 
									
										
										
										
											2014-08-29 00:20:10 +03:00
										 |  |  |             'ext': 'mp4', | 
					
						
							| 
									
										
										
										
											2016-09-25 12:44:46 +02:00
										 |  |  |             'title': 'oceans.mp4', | 
					
						
							| 
									
										
										
										
											2014-08-29 00:20:10 +03:00
										 |  |  |             'thumbnail': 're:^https?://.*\.jpg$', | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2014-10-27 00:50:22 +01:00
										 |  |  |         video_id = self._match_id(url) | 
					
						
							| 
									
										
										
										
											2014-08-29 00:20:10 +03:00
										 |  |  |         webpage = self._download_webpage(url, video_id) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-27 00:50:22 +01:00
										 |  |  |         if re.search(r'<div.+id="not_found_msg".+>(?!We are).+</div>[^-]', webpage) is not None: | 
					
						
							| 
									
										
										
										
											2014-08-29 00:20:10 +03:00
										 |  |  |             raise ExtractorError('Video %s does not exist' % video_id, | 
					
						
							|  |  |  |                                  expected=True) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-26 23:39:54 +07:00
										 |  |  |         chash = self._search_regex( | 
					
						
							|  |  |  |             r'val\("([^"]*)"\s*\+\s*\$\("#chash"\)', webpage, 'chash') | 
					
						
							| 
									
										
										
										
											2015-07-14 22:36:30 +06:00
										 |  |  |         fields = self._hidden_inputs(webpage) | 
					
						
							| 
									
										
										
										
											2016-09-26 23:39:54 +07:00
										 |  |  |         keys = list(fields.keys()) | 
					
						
							|  |  |  |         chash_key = keys[0] if len(keys) == 1 else next( | 
					
						
							|  |  |  |             key for key in keys if key.startswith('cha')) | 
					
						
							|  |  |  |         fields[chash_key] = chash + fields[chash_key] | 
					
						
							| 
									
										
										
										
											2016-09-25 12:44:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-29 00:20:10 +03:00
										 |  |  |         webpage = self._download_webpage( | 
					
						
							| 
									
										
										
										
											2016-09-26 23:39:54 +07:00
										 |  |  |             url, video_id, 'Downloading video page', | 
					
						
							|  |  |  |             data=urlencode_postdata(fields), | 
					
						
							|  |  |  |             headers={'Content-type': 'application/x-www-form-urlencoded'}) | 
					
						
							| 
									
										
										
										
											2014-08-29 00:20:10 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-26 23:39:54 +07:00
										 |  |  |         video_url = self._search_regex( | 
					
						
							|  |  |  |             (r'<a[^>]+href=(["\'])(?P<url>(?:(?!\1).)+)\1[^>]*>\s*Download File', | 
					
						
							|  |  |  |              r'<a[^>]+href=(["\'])(?P<url>https?://(?:www\.)?promptfile\.com/file/(?:(?!\1).)+)\1'), | 
					
						
							|  |  |  |             webpage, 'video url', group='url') | 
					
						
							| 
									
										
										
										
											2014-08-29 00:20:10 +03:00
										 |  |  |         title = self._html_search_regex( | 
					
						
							|  |  |  |             r'<span.+title="([^"]+)">', webpage, 'title') | 
					
						
							|  |  |  |         thumbnail = self._html_search_regex( | 
					
						
							|  |  |  |             r'<div id="player_overlay">.*button>.*?<img src="([^"]+)"', | 
					
						
							|  |  |  |             webpage, 'thumbnail', fatal=False, flags=re.DOTALL) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         formats = [{ | 
					
						
							|  |  |  |             'format_id': 'sd', | 
					
						
							| 
									
										
										
										
											2016-09-26 23:39:54 +07:00
										 |  |  |             'url': video_url, | 
					
						
							| 
									
										
										
										
											2014-08-29 00:20:10 +03:00
										 |  |  |             'ext': determine_ext(title), | 
					
						
							|  |  |  |         }] | 
					
						
							| 
									
										
										
										
											2014-08-29 01:07:18 +02:00
										 |  |  |         self._sort_formats(formats) | 
					
						
							| 
									
										
										
										
											2014-08-29 00:20:10 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |             'id': video_id, | 
					
						
							|  |  |  |             'title': title, | 
					
						
							|  |  |  |             'thumbnail': thumbnail, | 
					
						
							|  |  |  |             'formats': formats, | 
					
						
							|  |  |  |         } |