1 from __future__ 
import unicode_literals
 
   6 from .common 
import InfoExtractor
 
   8     compat_urllib_parse_urlparse
, 
  13 from ..aes 
import aes_decrypt_text
 
  16 class Tube8IE(InfoExtractor
): 
  17     _VALID_URL 
= r
'https?://(?:www\.)?tube8\.com/(?:[^/]+/){2}(?P<id>\d+)' 
  19         'url': 'http://www.tube8.com/teen/kasia-music-video/229795/', 
  21         'md5': 'e9e0b0c86734e5e3766e653509475db0', 
  23             'description': 'hot teen Kasia grinding', 
  24             'uploader': 'unknown', 
  25             'title': 'Kasia music video', 
  30     def _real_extract(self
, url
): 
  31         mobj 
= re
.match(self
._VALID
_URL
, url
) 
  32         video_id 
= mobj
.group('id') 
  34         req 
= compat_urllib_request
.Request(url
) 
  35         req
.add_header('Cookie', 'age_verified=1') 
  36         webpage 
= self
._download
_webpage
(req
, video_id
) 
  38         flashvars 
= json
.loads(self
._html
_search
_regex
( 
  39             r
'var flashvars\s*=\s*({.+?})', webpage
, 'flashvars')) 
  41         video_url 
= flashvars
['video_url'] 
  42         if flashvars
.get('encrypted') is True: 
  43             video_url 
= aes_decrypt_text(video_url
, flashvars
['video_title'], 32).decode('utf-8') 
  44         path 
= compat_urllib_parse_urlparse(video_url
).path
 
  45         format_id 
= '-'.join(path
.split('/')[4].split('_')[:2]) 
  47         thumbnail 
= flashvars
.get('image_url') 
  49         title 
= self
._html
_search
_regex
( 
  50             r
'videotitle\s*=\s*"([^"]+)', webpage
, 'title') 
  51         description 
= self
._html
_search
_regex
( 
  52             r
'>Description:</strong>(.+?)<', webpage
, 'description', fatal
=False) 
  53         uploader 
= self
._html
_search
_regex
( 
  54             r
'<strong class="video-username">(?:<a href="[^"]+">)?([^<]+)(?:</a>)?</strong>', 
  55             webpage
, 'uploader', fatal
=False) 
  57         like_count 
= int_or_none(self
._html
_search
_regex
( 
  58             r
"rupVar\s*=\s*'(\d+)'", webpage
, 'like count', fatal
=False)) 
  59         dislike_count 
= int_or_none(self
._html
_search
_regex
( 
  60             r
"rdownVar\s*=\s*'(\d+)'", webpage
, 'dislike count', fatal
=False)) 
  61         view_count 
= self
._html
_search
_regex
( 
  62             r
'<strong>Views: </strong>([\d,\.]+)</li>', webpage
, 'view count', fatal
=False) 
  64             view_count 
= str_to_int(view_count
) 
  65         comment_count 
= self
._html
_search
_regex
( 
  66             r
'<span id="allCommentsCount">(\d+)</span>', webpage
, 'comment count', fatal
=False) 
  68             comment_count 
= str_to_int(comment_count
) 
  74             'description': description
, 
  75             'thumbnail': thumbnail
, 
  77             'format_id': format_id
, 
  78             'view_count': view_count
, 
  79             'like_count': like_count
, 
  80             'dislike_count': dislike_count
, 
  81             'comment_count': comment_count
,