| 
									
										
										
										
											2014-01-17 03:25:59 +01:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-27 01:59:26 +02:00
										 |  |  | import os | 
					
						
							|  |  |  | import re | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from .common import InfoExtractor | 
					
						
							|  |  |  | from ..utils import ( | 
					
						
							|  |  |  |     compat_urllib_parse_urlparse, | 
					
						
							|  |  |  |     compat_urllib_request, | 
					
						
							|  |  |  |     compat_urllib_parse, | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | from ..aes import ( | 
					
						
							|  |  |  |     aes_decrypt_text | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-17 03:25:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-27 01:59:26 +02:00
										 |  |  | class SpankwireIE(InfoExtractor): | 
					
						
							|  |  |  |     _VALID_URL = r'^(?:https?://)?(?:www\.)?(?P<url>spankwire\.com/[^/]*/video(?P<videoid>[0-9]+)/?)' | 
					
						
							|  |  |  |     _TEST = { | 
					
						
							| 
									
										
										
										
											2014-01-17 03:25:59 +01:00
										 |  |  |         'url': 'http://www.spankwire.com/Buckcherry-s-X-Rated-Music-Video-Crazy-Bitch/video103545/', | 
					
						
							|  |  |  |         'file': '103545.mp4', | 
					
						
							|  |  |  |         'md5': '1b3f55e345500552dbc252a3e9c1af43', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             "uploader": "oreusz", | 
					
						
							|  |  |  |             "title": "Buckcherry`s X Rated Music Video Crazy Bitch", | 
					
						
							|  |  |  |             "description": "Crazy Bitch X rated music video.", | 
					
						
							|  |  |  |             "age_limit": 18, | 
					
						
							| 
									
										
										
										
											2013-10-27 01:59:26 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							|  |  |  |         mobj = re.match(self._VALID_URL, url) | 
					
						
							|  |  |  |         video_id = mobj.group('videoid') | 
					
						
							|  |  |  |         url = 'http://www.' + mobj.group('url') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         req = compat_urllib_request.Request(url) | 
					
						
							|  |  |  |         req.add_header('Cookie', 'age_verified=1') | 
					
						
							|  |  |  |         webpage = self._download_webpage(req, video_id) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-17 03:25:59 +01:00
										 |  |  |         video_title = self._html_search_regex(r'<h1>([^<]+)', webpage, 'title') | 
					
						
							| 
									
										
										
										
											2013-11-20 07:45:32 +01:00
										 |  |  |         video_uploader = self._html_search_regex( | 
					
						
							| 
									
										
										
										
											2014-01-17 03:25:59 +01:00
										 |  |  |             r'by:\s*<a [^>]*>(.+?)</a>', webpage, 'uploader', fatal=False) | 
					
						
							| 
									
										
										
										
											2013-11-20 07:45:32 +01:00
										 |  |  |         thumbnail = self._html_search_regex( | 
					
						
							| 
									
										
										
										
											2014-01-17 03:25:59 +01:00
										 |  |  |             r'flashvars\.image_url = "([^"]+)', webpage, 'thumbnail', fatal=False) | 
					
						
							| 
									
										
										
										
											2013-11-20 07:45:32 +01:00
										 |  |  |         description = self._html_search_regex( | 
					
						
							| 
									
										
										
										
											2014-01-17 03:25:59 +01:00
										 |  |  |             r'<div\s+id="descriptionContent">([^<]+)<', webpage, 'description', fatal=False) | 
					
						
							| 
									
										
										
										
											2013-10-27 01:59:26 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         video_urls = list(map(compat_urllib_parse.unquote , re.findall(r'flashvars\.quality_[0-9]{3}p = "([^"]+)', webpage))) | 
					
						
							|  |  |  |         if webpage.find('flashvars\.encrypted = "true"') != -1: | 
					
						
							| 
									
										
										
										
											2014-01-17 03:25:59 +01:00
										 |  |  |             password = self._html_search_regex(r'flashvars\.video_title = "([^"]+)', webpage, 'password').replace('+', ' ') | 
					
						
							| 
									
										
										
										
											2013-10-27 01:59:26 +02:00
										 |  |  |             video_urls = list(map(lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'), video_urls)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         formats = [] | 
					
						
							|  |  |  |         for video_url in video_urls: | 
					
						
							| 
									
										
										
										
											2013-11-03 14:03:17 +01:00
										 |  |  |             path = compat_urllib_parse_urlparse(video_url).path | 
					
						
							|  |  |  |             extension = os.path.splitext(path)[1][1:] | 
					
						
							| 
									
										
										
										
											2013-10-27 01:59:26 +02:00
										 |  |  |             format = path.split('/')[4].split('_')[:2] | 
					
						
							| 
									
										
										
										
											2014-01-17 03:25:59 +01:00
										 |  |  |             resolution, bitrate_str = format | 
					
						
							| 
									
										
										
										
											2013-11-03 14:03:17 +01:00
										 |  |  |             format = "-".join(format) | 
					
						
							| 
									
										
										
										
											2014-01-17 03:25:59 +01:00
										 |  |  |             height = int(resolution.rstrip('P')) | 
					
						
							|  |  |  |             tbr = int(bitrate_str.rstrip('K')) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-27 01:59:26 +02:00
										 |  |  |             formats.append({ | 
					
						
							|  |  |  |                 'url': video_url, | 
					
						
							|  |  |  |                 'ext': extension, | 
					
						
							| 
									
										
										
										
											2014-01-17 03:25:59 +01:00
										 |  |  |                 'resolution': resolution, | 
					
						
							| 
									
										
										
										
											2013-10-27 01:59:26 +02:00
										 |  |  |                 'format': format, | 
					
						
							| 
									
										
										
										
											2014-01-17 03:25:59 +01:00
										 |  |  |                 'tbr': tbr, | 
					
						
							|  |  |  |                 'height': height, | 
					
						
							| 
									
										
										
										
											2013-10-27 01:59:26 +02:00
										 |  |  |                 'format_id': format, | 
					
						
							|  |  |  |             }) | 
					
						
							| 
									
										
										
										
											2014-01-17 03:25:59 +01:00
										 |  |  |         self._sort_formats(formats) | 
					
						
							| 
									
										
										
										
											2013-10-27 01:59:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-28 01:50:17 -04:00
										 |  |  |         age_limit = self._rta_search(webpage) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-27 01:59:26 +02:00
										 |  |  |         return { | 
					
						
							|  |  |  |             'id': video_id, | 
					
						
							|  |  |  |             'uploader': video_uploader, | 
					
						
							|  |  |  |             'title': video_title, | 
					
						
							|  |  |  |             'thumbnail': thumbnail, | 
					
						
							|  |  |  |             'description': description, | 
					
						
							|  |  |  |             'formats': formats, | 
					
						
							| 
									
										
										
										
											2013-10-28 01:50:17 -04:00
										 |  |  |             'age_limit': age_limit, | 
					
						
							| 
									
										
										
										
											2013-10-27 01:59:26 +02:00
										 |  |  |         } |