1 from __future__
import unicode_literals
6 from .common
import InfoExtractor
18 class XTubeIE(InfoExtractor
):
22 https?://(?:www\.)?xtube\.com/(?:watch\.php\?.*\bv=|video-watch/(?:embedded/)?(?P<display_id>[^/]+)-)
29 'url': 'http://www.xtube.com/watch.php?v=kVTUy_G222_',
30 'md5': '092fbdd3cbe292c920ef6fc6a8a9cdab',
34 'title': 'strange erotica',
35 'description': 'contains:an ET kind of thing',
36 'uploader': 'greenshowers',
44 'url': 'http://www.xtube.com/video-watch/strange-erotica-625837',
45 'only_matching': True,
47 'url': 'xtube:625837',
48 'only_matching': True,
50 'url': 'xtube:kVTUy_G222_',
51 'only_matching': True,
53 'url': 'https://www.xtube.com/video-watch/embedded/milf-tara-and-teen-shared-and-cum-covered-extreme-bukkake-32203482?embedsize=big',
54 'only_matching': True,
57 def _real_extract(self
, url
):
58 mobj
= re
.match(self
._VALID
_URL
, url
)
59 video_id
= mobj
.group('id')
60 display_id
= mobj
.group('display_id')
65 if video_id
.isdigit() and len(video_id
) < 11:
66 url_pattern
= 'http://www.xtube.com/video-watch/-%s'
68 url_pattern
= 'http://www.xtube.com/watch.php?v=%s'
70 webpage
= self
._download
_webpage
(
71 url_pattern
% video_id
, display_id
, headers
={
72 'Cookie': 'age_verified=1; cookiesAccepted=1',
75 title
, thumbnail
, duration
= [None] * 3
77 json_config_string
= self
._search
_regex
(
78 r
'playerConf=({.+?}),loaderConf',
79 webpage
, 'config', default
=None)
80 if not json_config_string
:
81 raise ExtractorError("Could not extract video player data")
83 json_config_string
= json_config_string
.replace("!0", "true").replace("!1", "false")
85 config
= self
._parse
_json
(json_config_string
, video_id
, transform_source
=js_to_json
, fatal
=False)
87 raise ExtractorError("Could not extract video player data")
89 config
= config
.get('mainRoll')
90 if isinstance(config
, dict):
91 title
= config
.get('title')
92 thumbnail
= config
.get('poster')
93 duration
= int_or_none(config
.get('duration'))
94 sources
= config
.get('sources') or config
.get('format')
96 if not isinstance(sources
, dict):
97 sources
= self
._parse
_json
(self
._search
_regex
(
98 r
'(["\'])?sources\
1?\s
*:\s
*(?P
<sources
>{.+?}
),',
99 webpage, 'sources
', group='sources
'), video_id,
100 transform_source=js_to_json)
103 for format_id, format_url in sources.items():
106 'format_id
': format_id,
107 'height
': int_or_none(format_id),
109 self._remove_duplicate_formats(formats)
110 self._sort_formats(formats)
113 title = self._search_regex(
114 (r'<h1
>\s
*(?P
<title
>[^
<]+?
)\s
*</h1
>', r'videoTitle\s
*:\s
*(["\'])(?P<title>.+?)\1'),
115 webpage, 'title', group='title')
116 description = self._og_search_description(
117 webpage, default=None) or self._html_search_meta(
118 'twitter:description', webpage, default=None) or self._search_regex(
119 r'</h1>\s*<p>([^<]+)', webpage, 'description', fatal=False)
120 uploader = self._search_regex(
121 (r'<input[^>]+name="contentOwnerId
"[^>]+value="([^
"]+)"',
122 r'<span
[^
>]+class="nickname"[^
>]*>([^
<]+)'),
123 webpage, 'uploader
', fatal=False)
125 duration = parse_duration(self._search_regex(
126 r'<dt
>Runtime
:?
</dt
>\s
*<dd
>([^
<]+)</dd
>',
127 webpage, 'duration
', fatal=False))
128 view_count = str_to_int(self._search_regex(
129 (r'["\']viewsCount["\'][^
>]*>(\d
+)\s
+views
',
130 r'<dt
>Views
:?
</dt
>\s
*<dd
>([\d
,\
.]+)</dd
>'),
131 webpage, 'view count
', fatal=False))
132 comment_count = str_to_int(self._html_search_regex(
133 r'>Comments? \
(([\d
,\
.]+)\
)<',
134 webpage, 'comment count
', fatal=False))
138 'display_id
': display_id,
140 'description
': description,
141 'thumbnail
': thumbnail,
142 'uploader
': uploader,
143 'duration
': duration,
144 'view_count
': view_count,
145 'comment_count
': comment_count,
151 class XTubeUserIE(InfoExtractor):
152 IE_DESC = 'XTube user profile
'
153 _VALID_URL = r'https?
://(?
:www\
.)?xtube\
.com
/profile
/(?P
<id>[^
/]+-\d
+)'
155 'url
': 'http
://www
.xtube
.com
/profile
/greenshowers
-4056496',
157 'id': 'greenshowers
-4056496',
160 'playlist_mincount
': 154,
163 def _real_extract(self, url):
164 user_id = self._match_id(url)
167 for pagenum in itertools.count(1):
168 request = sanitized_Request(
169 'http
://www
.xtube
.com
/profile
/%s/videos
/%d' % (user_id, pagenum),
171 'Cookie
': 'popunder
=4',
172 'X
-Requested
-With
': 'XMLHttpRequest
',
176 page = self._download_json(
177 request, user_id, 'Downloading videos JSON page
%d' % pagenum)
179 html = page.get('html
')
183 for video_id in orderedSet([video_id for _, video_id in re.findall(
184 r'data
-plid
=(["\'])(.+?)\1', html)]):
185 entries.append(self.url_result('xtube:%s' % video_id, XTubeIE.ie_key()))
187 page_count = int_or_none(page.get('pageCount'))
188 if not page_count or pagenum == page_count:
191 playlist = self.playlist_result(entries, user_id)
192 playlist['age_limit'] = 18