| 
									
										
										
										
											2014-02-11 13:27:49 +05:30
										 |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-15 21:35:20 +06:00
										 |  |  | import itertools | 
					
						
							| 
									
										
										
										
											2013-10-28 19:23:48 +01:00
										 |  |  | import re | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from .common import InfoExtractor | 
					
						
							| 
									
										
										
										
											2014-12-13 12:24:42 +01:00
										 |  |  | from ..utils import ( | 
					
						
							| 
									
										
										
										
											2016-01-15 21:35:20 +06:00
										 |  |  |     int_or_none, | 
					
						
							| 
									
										
										
										
											2017-04-29 15:55:08 +08:00
										 |  |  |     js_to_json, | 
					
						
							| 
									
										
										
										
											2016-02-16 22:06:26 +06:00
										 |  |  |     orderedSet, | 
					
						
							| 
									
										
										
										
											2016-07-03 03:12:15 +07:00
										 |  |  |     parse_duration, | 
					
						
							| 
									
										
										
										
											2015-11-21 22:18:17 +06:00
										 |  |  |     sanitized_Request, | 
					
						
							| 
									
										
										
										
											2014-03-04 16:12:11 +07:00
										 |  |  |     str_to_int, | 
					
						
							| 
									
										
										
										
											2013-10-28 19:23:48 +01:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-04 16:12:11 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-28 19:23:48 +01:00
										 |  |  | class XTubeIE(InfoExtractor): | 
					
						
							| 
									
										
										
										
											2016-07-03 03:12:15 +07:00
										 |  |  |     _VALID_URL = r'''(?x)
 | 
					
						
							|  |  |  |                         (?: | 
					
						
							|  |  |  |                             xtube:| | 
					
						
							| 
									
										
										
										
											2017-10-06 23:53:32 +07:00
										 |  |  |                             https?://(?:www\.)?xtube\.com/(?:watch\.php\?.*\bv=|video-watch/(?:embedded/)?(?P<display_id>[^/]+)-) | 
					
						
							| 
									
										
										
										
											2016-07-03 03:12:15 +07:00
										 |  |  |                         ) | 
					
						
							|  |  |  |                         (?P<id>[^/?&#]+) | 
					
						
							|  |  |  |                     '''
 | 
					
						
							| 
									
										
										
										
											2016-02-16 22:05:23 +06:00
										 |  |  | 
 | 
					
						
							|  |  |  |     _TESTS = [{ | 
					
						
							|  |  |  |         # old URL schema | 
					
						
							| 
									
										
										
										
											2014-02-11 13:27:49 +05:30
										 |  |  |         'url': 'http://www.xtube.com/watch.php?v=kVTUy_G222_', | 
					
						
							|  |  |  |         'md5': '092fbdd3cbe292c920ef6fc6a8a9cdab', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							| 
									
										
										
										
											2014-03-04 16:12:11 +07:00
										 |  |  |             'id': 'kVTUy_G222_', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': 'strange erotica', | 
					
						
							| 
									
										
										
										
											2015-02-18 19:58:41 +01:00
										 |  |  |             'description': 'contains:an ET kind of thing', | 
					
						
							| 
									
										
										
										
											2014-03-04 16:12:11 +07:00
										 |  |  |             'uploader': 'greenshowers', | 
					
						
							|  |  |  |             'duration': 450, | 
					
						
							| 
									
										
										
										
											2016-07-03 03:12:15 +07:00
										 |  |  |             'view_count': int, | 
					
						
							|  |  |  |             'comment_count': int, | 
					
						
							| 
									
										
										
										
											2014-03-04 16:12:11 +07:00
										 |  |  |             'age_limit': 18, | 
					
						
							| 
									
										
										
										
											2013-10-28 19:23:48 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-04-29 15:55:08 +08:00
										 |  |  |     }, { | 
					
						
							|  |  |  |         # FLV videos with duplicated formats | 
					
						
							|  |  |  |         'url': 'http://www.xtube.com/video-watch/A-Super-Run-Part-1-YT-9299752', | 
					
						
							|  |  |  |         'md5': 'a406963eb349dd43692ec54631efd88b', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': '9299752', | 
					
						
							|  |  |  |             'display_id': 'A-Super-Run-Part-1-YT', | 
					
						
							|  |  |  |             'ext': 'flv', | 
					
						
							|  |  |  |             'title': 'A Super Run - Part 1 (YT)', | 
					
						
							|  |  |  |             'description': 'md5:ca0d47afff4a9b2942e4b41aa970fd93', | 
					
						
							|  |  |  |             'uploader': 'tshirtguy59', | 
					
						
							|  |  |  |             'duration': 579, | 
					
						
							|  |  |  |             'view_count': int, | 
					
						
							|  |  |  |             'comment_count': int, | 
					
						
							|  |  |  |             'age_limit': 18, | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2016-02-16 22:05:23 +06:00
										 |  |  |     }, { | 
					
						
							|  |  |  |         # new URL schema | 
					
						
							|  |  |  |         'url': 'http://www.xtube.com/video-watch/strange-erotica-625837', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							|  |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'xtube:625837', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							| 
									
										
										
										
											2017-02-13 23:44:43 +07:00
										 |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'xtube:kVTUy_G222_', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							| 
									
										
										
										
											2017-10-06 23:53:32 +07:00
										 |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'https://www.xtube.com/video-watch/embedded/milf-tara-and-teen-shared-and-cum-covered-extreme-bukkake-32203482?embedsize=big', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							| 
									
										
										
										
											2016-02-16 22:05:23 +06:00
										 |  |  |     }] | 
					
						
							| 
									
										
										
										
											2013-10-28 19:23:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2016-02-16 22:05:23 +06:00
										 |  |  |         mobj = re.match(self._VALID_URL, url) | 
					
						
							|  |  |  |         video_id = mobj.group('id') | 
					
						
							|  |  |  |         display_id = mobj.group('display_id') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if not display_id: | 
					
						
							|  |  |  |             display_id = video_id | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-13 23:44:43 +07:00
										 |  |  |         if video_id.isdigit() and len(video_id) < 11: | 
					
						
							|  |  |  |             url_pattern = 'http://www.xtube.com/video-watch/-%s' | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             url_pattern = 'http://www.xtube.com/watch.php?v=%s' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         webpage = self._download_webpage( | 
					
						
							|  |  |  |             url_pattern % video_id, display_id, headers={ | 
					
						
							|  |  |  |                 'Cookie': 'age_verified=1; cookiesAccepted=1', | 
					
						
							|  |  |  |             }) | 
					
						
							| 
									
										
										
										
											2013-10-28 19:23:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-03 03:12:15 +07:00
										 |  |  |         sources = self._parse_json(self._search_regex( | 
					
						
							| 
									
										
										
										
											2017-04-29 15:55:08 +08:00
										 |  |  |             r'(["\'])?sources\1?\s*:\s*(?P<sources>{.+?}),', | 
					
						
							|  |  |  |             webpage, 'sources', group='sources'), video_id, | 
					
						
							|  |  |  |             transform_source=js_to_json) | 
					
						
							| 
									
										
										
										
											2016-07-03 03:12:15 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         formats = [] | 
					
						
							|  |  |  |         for format_id, format_url in sources.items(): | 
					
						
							|  |  |  |             formats.append({ | 
					
						
							|  |  |  |                 'url': format_url, | 
					
						
							|  |  |  |                 'format_id': format_id, | 
					
						
							|  |  |  |                 'height': int_or_none(format_id), | 
					
						
							|  |  |  |             }) | 
					
						
							| 
									
										
										
										
											2017-04-29 15:55:08 +08:00
										 |  |  |         self._remove_duplicate_formats(formats) | 
					
						
							| 
									
										
										
										
											2016-07-03 03:12:15 +07:00
										 |  |  |         self._sort_formats(formats) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         title = self._search_regex( | 
					
						
							| 
									
										
										
										
											2017-02-11 21:11:55 +01:00
										 |  |  |             (r'<h1>\s*(?P<title>[^<]+?)\s*</h1>', r'videoTitle\s*:\s*(["\'])(?P<title>.+?)\1'), | 
					
						
							| 
									
										
										
										
											2016-07-03 03:12:15 +07:00
										 |  |  |             webpage, 'title', group='title') | 
					
						
							| 
									
										
										
										
											2016-02-16 22:05:23 +06:00
										 |  |  |         description = self._search_regex( | 
					
						
							|  |  |  |             r'</h1>\s*<p>([^<]+)', webpage, 'description', fatal=False) | 
					
						
							| 
									
										
										
										
											2016-07-03 03:12:15 +07:00
										 |  |  |         uploader = self._search_regex( | 
					
						
							|  |  |  |             (r'<input[^>]+name="contentOwnerId"[^>]+value="([^"]+)"', | 
					
						
							|  |  |  |              r'<span[^>]+class="nickname"[^>]*>([^<]+)'), | 
					
						
							|  |  |  |             webpage, 'uploader', fatal=False) | 
					
						
							|  |  |  |         duration = parse_duration(self._search_regex( | 
					
						
							| 
									
										
										
										
											2017-02-10 01:03:35 +07:00
										 |  |  |             r'<dt>Runtime:?</dt>\s*<dd>([^<]+)</dd>', | 
					
						
							| 
									
										
										
										
											2016-07-03 03:12:15 +07:00
										 |  |  |             webpage, 'duration', fatal=False)) | 
					
						
							| 
									
										
										
										
											2016-02-16 22:05:23 +06:00
										 |  |  |         view_count = str_to_int(self._search_regex( | 
					
						
							| 
									
										
										
										
											2017-02-10 01:03:35 +07:00
										 |  |  |             r'<dt>Views:?</dt>\s*<dd>([\d,\.]+)</dd>', | 
					
						
							| 
									
										
										
										
											2014-12-19 21:56:44 +06:00
										 |  |  |             webpage, 'view count', fatal=False)) | 
					
						
							|  |  |  |         comment_count = str_to_int(self._html_search_regex( | 
					
						
							| 
									
										
										
										
											2016-02-16 22:05:23 +06:00
										 |  |  |             r'>Comments? \(([\d,\.]+)\)<', | 
					
						
							| 
									
										
										
										
											2014-12-19 21:56:44 +06:00
										 |  |  |             webpage, 'comment count', fatal=False)) | 
					
						
							| 
									
										
										
										
											2014-03-21 23:58:40 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-28 19:23:48 +01:00
										 |  |  |         return { | 
					
						
							|  |  |  |             'id': video_id, | 
					
						
							| 
									
										
										
										
											2016-02-16 22:05:23 +06:00
										 |  |  |             'display_id': display_id, | 
					
						
							|  |  |  |             'title': title, | 
					
						
							|  |  |  |             'description': description, | 
					
						
							|  |  |  |             'uploader': uploader, | 
					
						
							| 
									
										
										
										
											2014-03-04 16:12:11 +07:00
										 |  |  |             'duration': duration, | 
					
						
							|  |  |  |             'view_count': view_count, | 
					
						
							|  |  |  |             'comment_count': comment_count, | 
					
						
							| 
									
										
										
										
											2013-10-28 19:23:48 +01:00
										 |  |  |             'age_limit': 18, | 
					
						
							| 
									
										
										
										
											2016-07-03 03:12:15 +07:00
										 |  |  |             'formats': formats, | 
					
						
							| 
									
										
										
										
											2014-03-23 00:16:35 +06:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-28 00:58:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-23 00:16:35 +06:00
										 |  |  | class XTubeUserIE(InfoExtractor): | 
					
						
							|  |  |  |     IE_DESC = 'XTube user profile' | 
					
						
							| 
									
										
										
										
											2016-01-15 21:35:20 +06:00
										 |  |  |     _VALID_URL = r'https?://(?:www\.)?xtube\.com/profile/(?P<id>[^/]+-\d+)' | 
					
						
							| 
									
										
										
										
											2014-08-28 00:58:24 +02:00
										 |  |  |     _TEST = { | 
					
						
							| 
									
										
										
										
											2016-01-15 21:35:20 +06:00
										 |  |  |         'url': 'http://www.xtube.com/profile/greenshowers-4056496', | 
					
						
							| 
									
										
										
										
											2014-08-28 00:58:24 +02:00
										 |  |  |         'info_dict': { | 
					
						
							| 
									
										
										
										
											2016-01-15 21:35:20 +06:00
										 |  |  |             'id': 'greenshowers-4056496', | 
					
						
							| 
									
										
										
										
											2015-01-07 07:20:20 +01:00
										 |  |  |             'age_limit': 18, | 
					
						
							| 
									
										
										
										
											2014-08-28 00:58:24 +02:00
										 |  |  |         }, | 
					
						
							|  |  |  |         'playlist_mincount': 155, | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-03-23 00:16:35 +06:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2016-01-15 21:35:20 +06:00
										 |  |  |         user_id = self._match_id(url) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         entries = [] | 
					
						
							|  |  |  |         for pagenum in itertools.count(1): | 
					
						
							|  |  |  |             request = sanitized_Request( | 
					
						
							|  |  |  |                 'http://www.xtube.com/profile/%s/videos/%d' % (user_id, pagenum), | 
					
						
							|  |  |  |                 headers={ | 
					
						
							|  |  |  |                     'Cookie': 'popunder=4', | 
					
						
							|  |  |  |                     'X-Requested-With': 'XMLHttpRequest', | 
					
						
							|  |  |  |                     'Referer': url, | 
					
						
							|  |  |  |                 }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             page = self._download_json( | 
					
						
							|  |  |  |                 request, user_id, 'Downloading videos JSON page %d' % pagenum) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             html = page.get('html') | 
					
						
							|  |  |  |             if not html: | 
					
						
							|  |  |  |                 break | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-16 22:06:26 +06:00
										 |  |  |             for video_id in orderedSet([video_id for _, video_id in re.findall( | 
					
						
							|  |  |  |                     r'data-plid=(["\'])(.+?)\1', html)]): | 
					
						
							| 
									
										
										
										
											2016-01-15 21:35:20 +06:00
										 |  |  |                 entries.append(self.url_result('xtube:%s' % video_id, XTubeIE.ie_key())) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             page_count = int_or_none(page.get('pageCount')) | 
					
						
							|  |  |  |             if not page_count or pagenum == page_count: | 
					
						
							|  |  |  |                 break | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         playlist = self.playlist_result(entries, user_id) | 
					
						
							|  |  |  |         playlist['age_limit'] = 18 | 
					
						
							|  |  |  |         return playlist |