1 from __future__ 
import unicode_literals
 
   5 from .common 
import InfoExtractor
 
   7     compat_urllib_parse_urlparse
, 
  14 from ..aes 
import aes_decrypt_text
 
  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/', 
  21         'md5': '8bbfde12b101204b39e4b9fe7eb67095', 
  25             'title': 'Buckcherry`s X Rated Music Video Crazy Bitch', 
  26             'description': 'Crazy Bitch X rated music video.', 
  28             'uploader_id': '124697', 
  29             'upload_date': '20070508', 
  34     def _real_extract(self
, url
): 
  35         mobj 
= re
.match(self
._VALID
_URL
, url
) 
  36         video_id 
= mobj
.group('videoid') 
  37         url 
= 'http://www.' + mobj
.group('url') 
  39         req 
= compat_urllib_request
.Request(url
) 
  40         req
.add_header('Cookie', 'age_verified=1') 
  41         webpage 
= self
._download
_webpage
(req
, video_id
) 
  43         title 
= self
._html
_search
_regex
(r
'<h1>([^<]+)', webpage
, 'title') 
  44         description 
= self
._html
_search
_regex
( 
  45             r
'<div\s+id="descriptionContent">([^<]+)<', webpage
, 'description', fatal
=False) 
  46         thumbnail 
= self
._html
_search
_regex
( 
  47             r
'flashvars\.image_url = "([^"]+)', webpage
, 'thumbnail', fatal
=False) 
  49         uploader 
= self
._html
_search
_regex
( 
  50             r
'by:\s*<a [^>]*>(.+?)</a>', webpage
, 'uploader', fatal
=False) 
  51         uploader_id 
= self
._html
_search
_regex
( 
  52             r
'by:\s*<a href="/Profile\.aspx\?.*?UserId=(\d+).*?"', webpage
, 'uploader id', fatal
=False) 
  53         upload_date 
= self
._html
_search
_regex
(r
'</a> on (.+?) at \d+:\d+', webpage
, 'upload date', fatal
=False) 
  55             upload_date 
= unified_strdate(upload_date
) 
  57         view_count 
= self
._html
_search
_regex
( 
  58             r
'<div id="viewsCounter"><span>([^<]+)</span> views</div>', webpage
, 'view count', fatal
=False) 
  60             view_count 
= str_to_int(view_count
) 
  61         comment_count 
= int_or_none(self
._html
_search
_regex
( 
  62             r
'<span id="spCommentCount">\s*(\d+)</span> Comments</div>', webpage
, 'comment count', fatal
=False)) 
  64         video_urls 
= list(map(compat_urllib_parse
.unquote 
, re
.findall(r
'flashvars\.quality_[0-9]{3}p = "([^"]+)', webpage
))) 
  65         if webpage
.find('flashvars\.encrypted = "true"') != -1: 
  66             password 
= self
._html
_search
_regex
(r
'flashvars\.video_title = "([^"]+)', webpage
, 'password').replace('+', ' ') 
  67             video_urls 
= list(map(lambda s
: aes_decrypt_text(s
, password
, 32).decode('utf-8'), video_urls
)) 
  70         for video_url 
in video_urls
: 
  71             path 
= compat_urllib_parse_urlparse(video_url
).path
 
  72             format 
= path
.split('/')[4].split('_')[:2] 
  73             resolution
, bitrate_str 
= format
 
  74             format 
= "-".join(format
) 
  75             height 
= int(resolution
.rstrip('Pp')) 
  76             tbr 
= int(bitrate_str
.rstrip('Kk')) 
  79                 'resolution': resolution
, 
  85         self
._sort
_formats
(formats
) 
  87         age_limit 
= self
._rta
_search
(webpage
) 
  92             'description': description
, 
  93             'thumbnail': thumbnail
, 
  95             'uploader_id': uploader_id
, 
  96             'upload_date': upload_date
, 
  97             'view_count': view_count
, 
  98             'comment_count': comment_count
, 
 100             'age_limit': age_limit
,