]>
Commit | Line | Data |
---|---|---|
c5ba203e AS |
1 | from __future__ import unicode_literals |
2 | ||
34dd81c0 | 3 | import itertools |
dcc2a706 | 4 | import re |
5 | ||
6 | from .common import InfoExtractor | |
1cc79574 | 7 | from ..utils import ( |
34dd81c0 | 8 | int_or_none, |
24eb7c25 | 9 | js_to_json, |
f4db0917 | 10 | orderedSet, |
1b734adb | 11 | parse_duration, |
5c2266df | 12 | sanitized_Request, |
607dbbad | 13 | str_to_int, |
41d1cca3 | 14 | url_or_none, |
dcc2a706 | 15 | ) |
16 | ||
607dbbad | 17 | |
dcc2a706 | 18 | class XTubeIE(InfoExtractor): |
1b734adb S |
19 | _VALID_URL = r'''(?x) |
20 | (?: | |
21 | xtube:| | |
ac93c09a | 22 | https?://(?:www\.)?xtube\.com/(?:watch\.php\?.*\bv=|video-watch/(?:embedded/)?(?P<display_id>[^/]+)-) |
1b734adb S |
23 | ) |
24 | (?P<id>[^/?&#]+) | |
25 | ''' | |
86be3cdc S |
26 | |
27 | _TESTS = [{ | |
28 | # old URL schema | |
c5ba203e | 29 | 'url': 'http://www.xtube.com/watch.php?v=kVTUy_G222_', |
c5ba203e AS |
30 | 'md5': '092fbdd3cbe292c920ef6fc6a8a9cdab', |
31 | 'info_dict': { | |
607dbbad S |
32 | 'id': 'kVTUy_G222_', |
33 | 'ext': 'mp4', | |
34 | 'title': 'strange erotica', | |
9789d753 | 35 | 'description': 'contains:an ET kind of thing', |
607dbbad | 36 | 'uploader': 'greenshowers', |
8bdd16b4 | 37 | 'duration': 450, |
1b734adb S |
38 | 'view_count': int, |
39 | 'comment_count': int, | |
607dbbad | 40 | 'age_limit': 18, |
dcc2a706 | 41 | } |
86be3cdc S |
42 | }, { |
43 | # new URL schema | |
44 | 'url': 'http://www.xtube.com/video-watch/strange-erotica-625837', | |
45 | 'only_matching': True, | |
46 | }, { | |
47 | 'url': 'xtube:625837', | |
48 | 'only_matching': True, | |
085f169f S |
49 | }, { |
50 | 'url': 'xtube:kVTUy_G222_', | |
51 | 'only_matching': True, | |
ac93c09a S |
52 | }, { |
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, | |
86be3cdc | 55 | }] |
dcc2a706 | 56 | |
57 | def _real_extract(self, url): | |
5ad28e7f | 58 | mobj = self._match_valid_url(url) |
86be3cdc S |
59 | video_id = mobj.group('id') |
60 | display_id = mobj.group('display_id') | |
61 | ||
62 | if not display_id: | |
63 | display_id = video_id | |
86be3cdc | 64 | |
085f169f S |
65 | if video_id.isdigit() and len(video_id) < 11: |
66 | url_pattern = 'http://www.xtube.com/video-watch/-%s' | |
67 | else: | |
68 | url_pattern = 'http://www.xtube.com/watch.php?v=%s' | |
69 | ||
70 | webpage = self._download_webpage( | |
71 | url_pattern % video_id, display_id, headers={ | |
72 | 'Cookie': 'age_verified=1; cookiesAccepted=1', | |
73 | }) | |
dcc2a706 | 74 | |
41d1cca3 | 75 | title, thumbnail, duration, sources, media_definition = [None] * 5 |
e88b4507 | 76 | |
8bdd16b4 | 77 | config = self._parse_json(self._search_regex( |
41d1cca3 | 78 | r'playerConf\s*=\s*({.+?})\s*,\s*(?:\n|loaderConf|playerWrapper)', webpage, 'config', |
8bdd16b4 | 79 | default='{}'), video_id, transform_source=js_to_json, fatal=False) |
80 | if config: | |
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') | |
41d1cca3 | 87 | media_definition = config.get('mediaDefinition') |
e88b4507 | 88 | |
41d1cca3 | 89 | if not isinstance(sources, dict) and not media_definition: |
e88b4507 S |
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) | |
1b734adb S |
94 | |
95 | formats = [] | |
41d1cca3 | 96 | format_urls = set() |
97 | ||
98 | if isinstance(sources, dict): | |
99 | for format_id, format_url in sources.items(): | |
100 | format_url = url_or_none(format_url) | |
101 | if not format_url: | |
102 | continue | |
103 | if format_url in format_urls: | |
104 | continue | |
105 | format_urls.add(format_url) | |
106 | formats.append({ | |
107 | 'url': format_url, | |
108 | 'format_id': format_id, | |
109 | 'height': int_or_none(format_id), | |
110 | }) | |
111 | ||
112 | if isinstance(media_definition, list): | |
113 | for media in media_definition: | |
114 | video_url = url_or_none(media.get('videoUrl')) | |
115 | if not video_url: | |
116 | continue | |
117 | if video_url in format_urls: | |
118 | continue | |
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')) | |
127 | formats.append({ | |
128 | 'url': video_url, | |
129 | 'format_id': '%s-%d' % (format_id, height) if height else format_id, | |
130 | 'height': height, | |
131 | }) | |
132 | ||
24eb7c25 | 133 | self._remove_duplicate_formats(formats) |
1b734adb S |
134 | self._sort_formats(formats) |
135 | ||
e88b4507 S |
136 | if not title: |
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( | |
86be3cdc | 143 | r'</h1>\s*<p>([^<]+)', webpage, 'description', fatal=False) |
1b734adb S |
144 | uploader = self._search_regex( |
145 | (r'<input[^>]+name="contentOwnerId"[^>]+value="([^"]+)"', | |
146 | r'<span[^>]+class="nickname"[^>]*>([^<]+)'), | |
147 | webpage, 'uploader', fatal=False) | |
e88b4507 S |
148 | if not duration: |
149 | duration = parse_duration(self._search_regex( | |
150 | r'<dt>Runtime:?</dt>\s*<dd>([^<]+)</dd>', | |
151 | webpage, 'duration', fatal=False)) | |
86be3cdc | 152 | view_count = str_to_int(self._search_regex( |
e88b4507 S |
153 | (r'["\']viewsCount["\'][^>]*>(\d+)\s+views', |
154 | r'<dt>Views:?</dt>\s*<dd>([\d,\.]+)</dd>'), | |
16ea8179 S |
155 | webpage, 'view count', fatal=False)) |
156 | comment_count = str_to_int(self._html_search_regex( | |
86be3cdc | 157 | r'>Comments? \(([\d,\.]+)\)<', |
16ea8179 | 158 | webpage, 'comment count', fatal=False)) |
aa488e13 | 159 | |
dcc2a706 | 160 | return { |
161 | 'id': video_id, | |
86be3cdc | 162 | 'display_id': display_id, |
86be3cdc S |
163 | 'title': title, |
164 | 'description': description, | |
e88b4507 | 165 | 'thumbnail': thumbnail, |
86be3cdc | 166 | 'uploader': uploader, |
607dbbad S |
167 | 'duration': duration, |
168 | 'view_count': view_count, | |
169 | 'comment_count': comment_count, | |
dcc2a706 | 170 | 'age_limit': 18, |
1b734adb | 171 | 'formats': formats, |
9f5809b3 | 172 | } |
173 | ||
22a6f150 | 174 | |
9f5809b3 | 175 | class XTubeUserIE(InfoExtractor): |
176 | IE_DESC = 'XTube user profile' | |
34dd81c0 | 177 | _VALID_URL = r'https?://(?:www\.)?xtube\.com/profile/(?P<id>[^/]+-\d+)' |
22a6f150 | 178 | _TEST = { |
34dd81c0 | 179 | 'url': 'http://www.xtube.com/profile/greenshowers-4056496', |
22a6f150 | 180 | 'info_dict': { |
34dd81c0 | 181 | 'id': 'greenshowers-4056496', |
05900629 | 182 | 'age_limit': 18, |
22a6f150 | 183 | }, |
838f051c | 184 | 'playlist_mincount': 154, |
22a6f150 | 185 | } |
9f5809b3 | 186 | |
187 | def _real_extract(self, url): | |
34dd81c0 S |
188 | user_id = self._match_id(url) |
189 | ||
190 | entries = [] | |
191 | for pagenum in itertools.count(1): | |
192 | request = sanitized_Request( | |
193 | 'http://www.xtube.com/profile/%s/videos/%d' % (user_id, pagenum), | |
194 | headers={ | |
195 | 'Cookie': 'popunder=4', | |
196 | 'X-Requested-With': 'XMLHttpRequest', | |
197 | 'Referer': url, | |
198 | }) | |
199 | ||
200 | page = self._download_json( | |
201 | request, user_id, 'Downloading videos JSON page %d' % pagenum) | |
202 | ||
203 | html = page.get('html') | |
204 | if not html: | |
205 | break | |
206 | ||
f4db0917 S |
207 | for video_id in orderedSet([video_id for _, video_id in re.findall( |
208 | r'data-plid=(["\'])(.+?)\1', html)]): | |
34dd81c0 S |
209 | entries.append(self.url_result('xtube:%s' % video_id, XTubeIE.ie_key())) |
210 | ||
211 | page_count = int_or_none(page.get('pageCount')) | |
212 | if not page_count or pagenum == page_count: | |
213 | break | |
214 | ||
215 | playlist = self.playlist_result(entries, user_id) | |
216 | playlist['age_limit'] = 18 | |
217 | return playlist |