1 from __future__ 
import unicode_literals
 
   6 from .common 
import InfoExtractor
 
   8     compat_urllib_parse_urlparse
, 
  17 class SpankwireIE(InfoExtractor
): 
  18     _VALID_URL 
= r
'^(?:https?://)?(?:www\.)?(?P<url>spankwire\.com/[^/]*/video(?P<videoid>[0-9]+)/?)' 
  20         'url': 'http://www.spankwire.com/Buckcherry-s-X-Rated-Music-Video-Crazy-Bitch/video103545/', 
  22         'md5': '1b3f55e345500552dbc252a3e9c1af43', 
  25             "title": "Buckcherry`s X Rated Music Video Crazy Bitch", 
  26             "description": "Crazy Bitch X rated music video.", 
  31     def _real_extract(self
, url
): 
  32         mobj 
= re
.match(self
._VALID
_URL
, url
) 
  33         video_id 
= mobj
.group('videoid') 
  34         url 
= 'http://www.' + mobj
.group('url') 
  36         req 
= compat_urllib_request
.Request(url
) 
  37         req
.add_header('Cookie', 'age_verified=1') 
  38         webpage 
= self
._download
_webpage
(req
, video_id
) 
  40         video_title 
= self
._html
_search
_regex
(r
'<h1>([^<]+)', webpage
, 'title') 
  41         video_uploader 
= self
._html
_search
_regex
( 
  42             r
'by:\s*<a [^>]*>(.+?)</a>', webpage
, 'uploader', fatal
=False) 
  43         thumbnail 
= self
._html
_search
_regex
( 
  44             r
'flashvars\.image_url = "([^"]+)', webpage
, 'thumbnail', fatal
=False) 
  45         description 
= self
._html
_search
_regex
( 
  46             r
'<div\s+id="descriptionContent">([^<]+)<', webpage
, 'description', fatal
=False) 
  48         video_urls 
= list(map(compat_urllib_parse
.unquote 
, re
.findall(r
'flashvars\.quality_[0-9]{3}p = "([^"]+)', webpage
))) 
  49         if webpage
.find('flashvars\.encrypted = "true"') != -1: 
  50             password 
= self
._html
_search
_regex
(r
'flashvars\.video_title = "([^"]+)', webpage
, 'password').replace('+', ' ') 
  51             video_urls 
= list(map(lambda s
: aes_decrypt_text(s
, password
, 32).decode('utf-8'), video_urls
)) 
  54         for video_url 
in video_urls
: 
  55             path 
= compat_urllib_parse_urlparse(video_url
).path
 
  56             extension 
= os
.path
.splitext(path
)[1][1:] 
  57             format 
= path
.split('/')[4].split('_')[:2] 
  58             resolution
, bitrate_str 
= format
 
  59             format 
= "-".join(format
) 
  60             height 
= int(resolution
.rstrip('P')) 
  61             tbr 
= int(bitrate_str
.rstrip('K')) 
  66                 'resolution': resolution
, 
  72         self
._sort
_formats
(formats
) 
  74         age_limit 
= self
._rta
_search
(webpage
) 
  78             'uploader': video_uploader
, 
  80             'thumbnail': thumbnail
, 
  81             'description': description
, 
  83             'age_limit': age_limit
,