| 
									
										
										
										
											2014-09-01 23:47:14 +03:00
										 |  |  | # coding: utf-8 | 
					
						
							|  |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import re | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from .common import InfoExtractor | 
					
						
							|  |  |  | from ..utils import ( | 
					
						
							| 
									
										
										
										
											2014-09-10 18:10:21 +03:00
										 |  |  |     ExtractorError, | 
					
						
							| 
									
										
										
										
											2015-11-21 22:18:17 +06:00
										 |  |  |     sanitized_Request, | 
					
						
							| 
									
										
										
										
											2014-09-10 18:10:21 +03:00
										 |  |  |     urlencode_postdata, | 
					
						
							| 
									
										
										
										
											2014-09-15 16:59:03 +03:00
										 |  |  |     xpath_text, | 
					
						
							| 
									
										
										
										
											2014-09-01 23:47:14 +03:00
										 |  |  |     xpath_with_ns, | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | _x = lambda p: xpath_with_ns(p, {'xspf': 'http://xspf.org/ns/0/'}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class NosVideoIE(InfoExtractor): | 
					
						
							|  |  |  |     _VALID_URL = r'https?://(?:www\.)?nosvideo\.com/' + \ | 
					
						
							| 
									
										
										
										
											2017-01-02 20:08:07 +08:00
										 |  |  |                  r'(?:embed/|\?v=)(?P<id>[A-Za-z0-9]{12})/?' | 
					
						
							| 
									
										
										
										
											2014-09-01 23:47:14 +03:00
										 |  |  |     _PLAYLIST_URL = 'http://nosvideo.com/xml/{xml_id:s}.xml' | 
					
						
							| 
									
										
										
										
											2014-09-10 18:10:21 +03:00
										 |  |  |     _FILE_DELETED_REGEX = r'<b>File Not Found</b>' | 
					
						
							| 
									
										
										
										
											2014-09-01 23:47:14 +03:00
										 |  |  |     _TEST = { | 
					
						
							| 
									
										
										
										
											2014-09-10 18:19:59 +03:00
										 |  |  |         'url': 'http://nosvideo.com/?v=mu8fle7g7rpq', | 
					
						
							|  |  |  |         'md5': '6124ed47130d8be3eacae635b071e6b6', | 
					
						
							| 
									
										
										
										
											2014-09-01 23:47:14 +03:00
										 |  |  |         'info_dict': { | 
					
						
							| 
									
										
										
										
											2014-09-10 18:19:59 +03:00
										 |  |  |             'id': 'mu8fle7g7rpq', | 
					
						
							| 
									
										
										
										
											2014-09-01 23:47:14 +03:00
										 |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': 'big_buck_bunny_480p_surround-fix.avi.mp4', | 
					
						
							| 
									
										
										
										
											2017-01-02 20:08:07 +08:00
										 |  |  |             'thumbnail': r're:^https?://.*\.jpg$', | 
					
						
							| 
									
										
										
										
											2014-09-01 23:47:14 +03:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2014-12-13 12:24:42 +01:00
										 |  |  |         video_id = self._match_id(url) | 
					
						
							| 
									
										
										
										
											2014-09-01 23:47:14 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |         fields = { | 
					
						
							|  |  |  |             'id': video_id, | 
					
						
							|  |  |  |             'op': 'download1', | 
					
						
							|  |  |  |             'method_free': 'Continue to Video', | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-11-21 22:18:17 +06:00
										 |  |  |         req = sanitized_Request(url, urlencode_postdata(fields)) | 
					
						
							| 
									
										
										
										
											2014-09-01 23:47:14 +03:00
										 |  |  |         req.add_header('Content-type', 'application/x-www-form-urlencoded') | 
					
						
							|  |  |  |         webpage = self._download_webpage(req, video_id, | 
					
						
							|  |  |  |                                          'Downloading download page') | 
					
						
							| 
									
										
										
										
											2014-09-10 18:10:21 +03:00
										 |  |  |         if re.search(self._FILE_DELETED_REGEX, webpage) is not None: | 
					
						
							|  |  |  |             raise ExtractorError('Video %s does not exist' % video_id, | 
					
						
							|  |  |  |                                  expected=True) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-01 23:47:14 +03:00
										 |  |  |         xml_id = self._search_regex(r'php\|([^\|]+)\|', webpage, 'XML ID') | 
					
						
							|  |  |  |         playlist_url = self._PLAYLIST_URL.format(xml_id=xml_id) | 
					
						
							|  |  |  |         playlist = self._download_xml(playlist_url, video_id) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         track = playlist.find(_x('.//xspf:track')) | 
					
						
							| 
									
										
										
										
											2014-09-15 16:59:03 +03:00
										 |  |  |         if track is None: | 
					
						
							|  |  |  |             raise ExtractorError( | 
					
						
							|  |  |  |                 'XML playlist is missing the \'track\' element', | 
					
						
							|  |  |  |                 expected=True) | 
					
						
							|  |  |  |         title = xpath_text(track, _x('./xspf:title'), 'title') | 
					
						
							|  |  |  |         url = xpath_text(track, _x('./xspf:file'), 'URL', fatal=True) | 
					
						
							|  |  |  |         thumbnail = xpath_text(track, _x('./xspf:image'), 'thumbnail') | 
					
						
							|  |  |  |         if title is not None: | 
					
						
							|  |  |  |             title = title.strip() | 
					
						
							| 
									
										
										
										
											2014-09-01 23:47:14 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |         formats = [{ | 
					
						
							|  |  |  |             'format_id': 'sd', | 
					
						
							|  |  |  |             'url': url, | 
					
						
							|  |  |  |         }] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |             'id': video_id, | 
					
						
							|  |  |  |             'title': title, | 
					
						
							|  |  |  |             'thumbnail': thumbnail, | 
					
						
							|  |  |  |             'formats': formats, | 
					
						
							|  |  |  |         } |