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
= self
._match
_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
, sources
, media_definition
= [None] * 5
77 config
= self
._parse
_json
(self
._search
_regex
(
78 r
'playerConf\s*=\s*({.+?})\s*,\s*(?:\n|loaderConf|playerWrapper)', webpage
, 'config',
79 default
='{}'), video_id
, transform_source
=js_to_json
, fatal
=False)
81 config
= config
.get('mainRoll')
82 if isinstance(config
, dict):
83 title
= config
.get('title')
84 thumbnail
= config
.get('poster')
85 duration
= int_or_none(config
.get('duration'))
86 sources
= config
.get('sources') or config
.get('format')
87 media_definition
= config
.get('mediaDefinition')
89 if not isinstance(sources
, dict) and not media_definition
:
90 sources
= self
._parse
_json
(self
._search
_regex
(
91 r
'(["\'])?sources\
1?\s
*:\s
*(?P
<sources
>{.+?}
),',
92 webpage, 'sources
', group='sources
'), video_id,
93 transform_source=js_to_json)
98 if isinstance(sources, dict):
99 for format_id, format_url in sources.items():
100 format_url = url_or_none(format_url)
103 if format_url in format_urls:
105 format_urls.add(format_url)
108 'format_id
': format_id,
109 'height
': int_or_none(format_id),
112 if isinstance(media_definition, list):
113 for media in media_definition:
114 video_url = url_or_none(media.get('videoUrl
'))
117 if video_url in format_urls:
119 format_urls.add(video_url)
120 format_id = media.get('format
')
121 if format_id == 'hls
':
122 formats.extend(self._extract_m3u8_formats(
123 video_url, video_id, 'mp4
', entry_protocol='m3u8_native
',
124 m3u8_id='hls
', fatal=False))
125 elif format_id == 'mp4
':
126 height = int_or_none(media.get('quality
'))
129 'format_id
': '%s-%d' % (format_id, height) if height else format_id,
133 self._remove_duplicate_formats(formats)
134 self._sort_formats(formats)
137 title = self._search_regex(
138 (r'<h1
>\s
*(?P
<title
>[^
<]+?
)\s
*</h1
>', r'videoTitle\s
*:\s
*(["\'])(?P<title>.+?)\1'),
139 webpage, 'title', group='title')
140 description = self._og_search_description(
141 webpage, default=None) or self._html_search_meta(
142 'twitter:description', webpage, default=None) or self._search_regex(
143 r'</h1>\s*<p>([^<]+)', webpage, 'description', fatal=False)
144 uploader = self._search_regex(
145 (r'<input[^>]+name="contentOwnerId
"[^>]+value="([^
"]+)"',
146 r'<span
[^
>]+class="nickname"[^
>]*>([^
<]+)'),
147 webpage, 'uploader
', fatal=False)
149 duration = parse_duration(self._search_regex(
150 r'<dt
>Runtime
:?
</dt
>\s
*<dd
>([^
<]+)</dd
>',
151 webpage, 'duration
', fatal=False))
152 view_count = str_to_int(self._search_regex(
153 (r'["\']viewsCount["\'][^
>]*>(\d
+)\s
+views
',
154 r'<dt
>Views
:?
</dt
>\s
*<dd
>([\d
,\
.]+)</dd
>'),
155 webpage, 'view count
', fatal=False))
156 comment_count = str_to_int(self._html_search_regex(
157 r'>Comments? \
(([\d
,\
.]+)\
)<',
158 webpage, 'comment count
', fatal=False))
162 'display_id
': display_id,
164 'description
': description,
165 'thumbnail
': thumbnail,
166 'uploader
': uploader,
167 'duration
': duration,
168 'view_count
': view_count,
169 'comment_count
': comment_count,
175 class XTubeUserIE(InfoExtractor):
176 IE_DESC = 'XTube user profile
'
177 _VALID_URL = r'https?
://(?
:www\
.)?xtube\
.com
/profile
/(?P
<id>[^
/]+-\d
+)'
179 'url
': 'http
://www
.xtube
.com
/profile
/greenshowers
-4056496',
181 'id': 'greenshowers
-4056496',
184 'playlist_mincount
': 154,
187 def _real_extract(self, url):
188 user_id = self._match_id(url)
191 for pagenum in itertools.count(1):
192 request = sanitized_Request(
193 'http
://www
.xtube
.com
/profile
/%s/videos
/%d' % (user_id, pagenum),
195 'Cookie
': 'popunder
=4',
196 'X
-Requested
-With
': 'XMLHttpRequest
',
200 page = self._download_json(
201 request, user_id, 'Downloading videos JSON page
%d' % pagenum)
203 html = page.get('html
')
207 for video_id in orderedSet([video_id for _, video_id in re.findall(
208 r'data
-plid
=(["\'])(.+?)\1', html)]):
209 entries.append(self.url_result('xtube:%s' % video_id, XTubeIE.ie_key()))
211 page_count = int_or_none(page.get('pageCount'))
212 if not page_count or pagenum == page_count:
215 playlist = self.playlist_result(entries, user_id)
216 playlist['age_limit'] = 18