| 
									
										
										
										
											2017-04-04 03:05:18 +07:00
										 |  |  | # coding: utf-8 | 
					
						
							|  |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-14 16:34:45 +01:00
										 |  |  | import re | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-04 03:05:18 +07:00
										 |  |  | from .common import InfoExtractor | 
					
						
							| 
									
										
										
										
											2017-11-14 16:34:45 +01:00
										 |  |  | from ..compat import compat_chr | 
					
						
							| 
									
										
										
										
											2017-11-14 22:39:54 +07:00
										 |  |  | from ..utils import ( | 
					
						
							|  |  |  |     decode_packed_codes, | 
					
						
							|  |  |  |     ExtractorError, | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2017-04-04 03:05:18 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class VShareIE(InfoExtractor): | 
					
						
							|  |  |  |     _VALID_URL = r'https?://(?:www\.)?vshare\.io/[dv]/(?P<id>[^/?#&]+)' | 
					
						
							|  |  |  |     _TESTS = [{ | 
					
						
							|  |  |  |         'url': 'https://vshare.io/d/0f64ce6', | 
					
						
							| 
									
										
										
										
											2017-11-14 16:34:45 +01:00
										 |  |  |         'md5': '17b39f55b5497ae8b59f5fbce8e35886', | 
					
						
							| 
									
										
										
										
											2017-04-04 03:05:18 +07:00
										 |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': '0f64ce6', | 
					
						
							|  |  |  |             'title': 'vl14062007715967', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'https://vshare.io/v/0f64ce6/width-650/height-430/1', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							|  |  |  |     }] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-14 22:49:25 +07:00
										 |  |  |     @staticmethod | 
					
						
							|  |  |  |     def _extract_urls(webpage): | 
					
						
							|  |  |  |         return re.findall( | 
					
						
							|  |  |  |             r'<iframe[^>]+?src=["\'](?P<url>(?:https?:)?//(?:www\.)?vshare\.io/v/[^/?#&]+)', | 
					
						
							|  |  |  |             webpage) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-14 16:34:45 +01:00
										 |  |  |     def _extract_packed(self, webpage): | 
					
						
							| 
									
										
										
										
											2017-11-14 22:49:25 +07:00
										 |  |  |         packed = self._search_regex( | 
					
						
							|  |  |  |             r'(eval\(function.+)', webpage, 'packed code') | 
					
						
							| 
									
										
										
										
											2017-11-14 16:34:45 +01:00
										 |  |  |         unpacked = decode_packed_codes(packed) | 
					
						
							|  |  |  |         digits = self._search_regex(r'\[((?:\d+,?)+)\]', unpacked, 'digits') | 
					
						
							| 
									
										
										
										
											2017-11-14 22:49:25 +07:00
										 |  |  |         digits = [int(digit) for digit in digits.split(',')] | 
					
						
							|  |  |  |         key_digit = self._search_regex( | 
					
						
							|  |  |  |             r'fromCharCode\(.+?(\d+)\)}', unpacked, 'key digit') | 
					
						
							| 
									
										
										
										
											2017-11-14 16:34:45 +01:00
										 |  |  |         chars = [compat_chr(d - int(key_digit)) for d in digits] | 
					
						
							|  |  |  |         return ''.join(chars) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-04 03:05:18 +07:00
										 |  |  |     def _real_extract(self, url): | 
					
						
							|  |  |  |         video_id = self._match_id(url) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         webpage = self._download_webpage( | 
					
						
							| 
									
										
										
										
											2017-11-14 22:49:25 +07:00
										 |  |  |             'https://vshare.io/v/%s/width-650/height-430/1' % video_id, | 
					
						
							|  |  |  |             video_id) | 
					
						
							| 
									
										
										
										
											2017-04-04 03:05:18 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-14 22:49:25 +07:00
										 |  |  |         title = self._html_search_regex( | 
					
						
							|  |  |  |             r'<title>([^<]+)</title>', webpage, 'title') | 
					
						
							| 
									
										
										
										
											2017-11-14 16:34:45 +01:00
										 |  |  |         title = title.split(' - ')[0] | 
					
						
							| 
									
										
										
										
											2017-04-04 03:05:18 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-14 22:39:54 +07:00
										 |  |  |         error = self._html_search_regex( | 
					
						
							|  |  |  |             r'(?s)<div[^>]+\bclass=["\']xxx-error[^>]+>(.+?)</div', webpage, | 
					
						
							|  |  |  |             'error', default=None) | 
					
						
							|  |  |  |         if error: | 
					
						
							|  |  |  |             raise ExtractorError(error, expected=True) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-14 22:49:25 +07:00
										 |  |  |         info = self._parse_html5_media_entries( | 
					
						
							|  |  |  |             url, '<video>%s</video>' % self._extract_packed(webpage), | 
					
						
							|  |  |  |             video_id)[0] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         self._sort_formats(info['formats']) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         info.update({ | 
					
						
							| 
									
										
										
										
											2017-04-04 03:05:18 +07:00
										 |  |  |             'id': video_id, | 
					
						
							|  |  |  |             'title': title, | 
					
						
							| 
									
										
										
										
											2017-11-14 22:49:25 +07:00
										 |  |  |         }) | 
					
						
							| 
									
										
										
										
											2017-11-14 16:34:45 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-14 22:49:25 +07:00
										 |  |  |         return info |