1 from __future__ 
import unicode_literals
 
   6 from .common 
import InfoExtractor
 
   7 from ..compat 
import compat_urllib_parse_unquote
 
  16 class XTubeIE(InfoExtractor
): 
  17     _VALID_URL 
= r
'(?:xtube:|https?://(?:www\.)?xtube\.com/(?:watch\.php\?.*\bv=|video-watch/(?P<display_id>[^/]+)-))(?P<id>[^/?&#]+)' 
  21         'url': 'http://www.xtube.com/watch.php?v=kVTUy_G222_', 
  22         'md5': '092fbdd3cbe292c920ef6fc6a8a9cdab', 
  26             'title': 'strange erotica', 
  27             'description': 'contains:an ET kind of thing', 
  28             'uploader': 'greenshowers', 
  34         'url': 'http://www.xtube.com/video-watch/strange-erotica-625837', 
  35         'only_matching': True, 
  37         'url': 'xtube:625837', 
  38         'only_matching': True, 
  41     def _real_extract(self
, url
): 
  42         mobj 
= re
.match(self
._VALID
_URL
, url
) 
  43         video_id 
= mobj
.group('id') 
  44         display_id 
= mobj
.group('display_id') 
  48             url 
= 'http://www.xtube.com/watch.php?v=%s' % video_id
 
  50         req 
= sanitized_Request(url
) 
  51         req
.add_header('Cookie', 'age_verified=1; cookiesAccepted=1') 
  52         webpage 
= self
._download
_webpage
(req
, display_id
) 
  54         flashvars 
= self
._parse
_json
( 
  56                 r
'xt\.playerOps\s*=\s*({.+?});', webpage
, 'player ops'), 
  57             video_id
)['flashvars'] 
  59         title 
= flashvars
.get('title') or self
._search
_regex
( 
  60             r
'<h1>([^<]+)</h1>', webpage
, 'title') 
  61         video_url 
= compat_urllib_parse_unquote(flashvars
['video_url']) 
  62         duration 
= int_or_none(flashvars
.get('video_duration')) 
  64         uploader 
= self
._search
_regex
( 
  65             r
'<input[^>]+name="contentOwnerId"[^>]+value="([^"]+)"', 
  66             webpage
, 'uploader', fatal
=False) 
  67         description 
= self
._search
_regex
( 
  68             r
'</h1>\s*<p>([^<]+)', webpage
, 'description', fatal
=False) 
  69         view_count 
= str_to_int(self
._search
_regex
( 
  70             r
'<dt>Views:</dt>\s*<dd>([\d,\.]+)</dd>', 
  71             webpage
, 'view count', fatal
=False)) 
  72         comment_count 
= str_to_int(self
._html
_search
_regex
( 
  73             r
'>Comments? \(([\d,\.]+)\)<', 
  74             webpage
, 'comment count', fatal
=False)) 
  78             'display_id': display_id
, 
  81             'description': description
, 
  84             'view_count': view_count
, 
  85             'comment_count': comment_count
, 
  90 class XTubeUserIE(InfoExtractor
): 
  91     IE_DESC 
= 'XTube user profile' 
  92     _VALID_URL 
= r
'https?://(?:www\.)?xtube\.com/profile/(?P<id>[^/]+-\d+)' 
  94         'url': 'http://www.xtube.com/profile/greenshowers-4056496', 
  96             'id': 'greenshowers-4056496', 
  99         'playlist_mincount': 155, 
 102     def _real_extract(self
, url
): 
 103         user_id 
= self
._match
_id
(url
) 
 106         for pagenum 
in itertools
.count(1): 
 107             request 
= sanitized_Request( 
 108                 'http://www.xtube.com/profile/%s/videos/%d' % (user_id
, pagenum
), 
 110                     'Cookie': 'popunder=4', 
 111                     'X-Requested-With': 'XMLHttpRequest', 
 115             page 
= self
._download
_json
( 
 116                 request
, user_id
, 'Downloading videos JSON page %d' % pagenum
) 
 118             html 
= page
.get('html') 
 122             for video_id 
in orderedSet([video_id 
for _
, video_id 
in re
.findall( 
 123                     r
'data-plid=(["\'])(.+?
)\
1', html)]): 
 124                 entries.append(self.url_result('xtube
:%s' % video_id, XTubeIE.ie_key())) 
 126             page_count = int_or_none(page.get('pageCount
')) 
 127             if not page_count or pagenum == page_count: 
 130         playlist = self.playlist_result(entries, user_id) 
 131         playlist['age_limit
'] = 18