1 from __future__ 
import unicode_literals
 
   6 from .common 
import InfoExtractor
 
   7 from ..compat 
import compat_urllib_parse_urlparse
 
  13 from ..aes 
import aes_decrypt_text
 
  16 class Tube8IE(InfoExtractor
): 
  17     _VALID_URL 
= r
'https?://(?:www\.)?tube8\.com/(?:[^/]+/)+(?P<display_id>[^/]+)/(?P<id>\d+)' 
  20             'url': 'http://www.tube8.com/teen/kasia-music-video/229795/', 
  21             'md5': '44bf12b98313827dd52d35b8706a4ea0', 
  24                 'display_id': 'kasia-music-video', 
  26                 'description': 'hot teen Kasia grinding', 
  27                 'uploader': 'unknown', 
  28                 'title': 'Kasia music video', 
  33             'url': 'http://www.tube8.com/shemale/teen/blonde-cd-gets-kidnapped-by-two-blacks-and-punished-for-being-a-slutty-girl/19569151/', 
  34             'only_matching': True, 
  38     def _real_extract(self
, url
): 
  39         mobj 
= re
.match(self
._VALID
_URL
, url
) 
  40         video_id 
= mobj
.group('id') 
  41         display_id 
= mobj
.group('display_id') 
  43         req 
= sanitized_Request(url
) 
  44         req
.add_header('Cookie', 'age_verified=1') 
  45         webpage 
= self
._download
_webpage
(req
, display_id
) 
  47         flashvars 
= json
.loads(self
._html
_search
_regex
( 
  48             r
'flashvars\s*=\s*({.+?});\r?\n', webpage
, 'flashvars')) 
  50         video_url 
= flashvars
['video_url'] 
  51         if flashvars
.get('encrypted') is True: 
  52             video_url 
= aes_decrypt_text(video_url
, flashvars
['video_title'], 32).decode('utf-8') 
  53         path 
= compat_urllib_parse_urlparse(video_url
).path
 
  54         format_id 
= '-'.join(path
.split('/')[4].split('_')[:2]) 
  56         thumbnail 
= flashvars
.get('image_url') 
  58         title 
= self
._html
_search
_regex
( 
  59             r
'videoTitle\s*=\s*"([^"]+)', webpage
, 'title') 
  60         description 
= self
._html
_search
_regex
( 
  61             r
'>Description:</strong>\s*(.+?)\s*<', webpage
, 'description', fatal
=False) 
  62         uploader 
= self
._html
_search
_regex
( 
  63             r
'<span class="username">\s*(.+?)\s*<', 
  64             webpage
, 'uploader', fatal
=False) 
  66         like_count 
= int_or_none(self
._html
_search
_regex
( 
  67             r
'rupVar\s*=\s*"(\d+)"', webpage
, 'like count', fatal
=False)) 
  68         dislike_count 
= int_or_none(self
._html
_search
_regex
( 
  69             r
'rdownVar\s*=\s*"(\d+)"', webpage
, 'dislike count', fatal
=False)) 
  70         view_count 
= self
._html
_search
_regex
( 
  71             r
'<strong>Views: </strong>([\d,\.]+)\s*</li>', webpage
, 'view count', fatal
=False) 
  73             view_count 
= str_to_int(view_count
) 
  74         comment_count 
= self
._html
_search
_regex
( 
  75             r
'<span id="allCommentsCount">(\d+)</span>', webpage
, 'comment count', fatal
=False) 
  77             comment_count 
= str_to_int(comment_count
) 
  81             'display_id': display_id
, 
  84             'description': description
, 
  85             'thumbnail': thumbnail
, 
  87             'format_id': format_id
, 
  88             'view_count': view_count
, 
  89             'like_count': like_count
, 
  90             'dislike_count': dislike_count
, 
  91             'comment_count': comment_count
,