]>
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, |
dcc2a706 | 14 | ) |
15 | ||
607dbbad | 16 | |
dcc2a706 | 17 | class XTubeIE(InfoExtractor): |
1b734adb S |
18 | _VALID_URL = r'''(?x) |
19 | (?: | |
20 | xtube:| | |
ac93c09a | 21 | https?://(?:www\.)?xtube\.com/(?:watch\.php\?.*\bv=|video-watch/(?:embedded/)?(?P<display_id>[^/]+)-) |
1b734adb S |
22 | ) |
23 | (?P<id>[^/?&#]+) | |
24 | ''' | |
86be3cdc S |
25 | |
26 | _TESTS = [{ | |
27 | # old URL schema | |
c5ba203e | 28 | 'url': 'http://www.xtube.com/watch.php?v=kVTUy_G222_', |
c5ba203e AS |
29 | 'md5': '092fbdd3cbe292c920ef6fc6a8a9cdab', |
30 | 'info_dict': { | |
607dbbad S |
31 | 'id': 'kVTUy_G222_', |
32 | 'ext': 'mp4', | |
33 | 'title': 'strange erotica', | |
9789d753 | 34 | 'description': 'contains:an ET kind of thing', |
607dbbad | 35 | 'uploader': 'greenshowers', |
8bdd16b4 | 36 | 'duration': 450, |
1b734adb S |
37 | 'view_count': int, |
38 | 'comment_count': int, | |
607dbbad | 39 | 'age_limit': 18, |
dcc2a706 | 40 | } |
86be3cdc S |
41 | }, { |
42 | # new URL schema | |
43 | 'url': 'http://www.xtube.com/video-watch/strange-erotica-625837', | |
44 | 'only_matching': True, | |
45 | }, { | |
46 | 'url': 'xtube:625837', | |
47 | 'only_matching': True, | |
085f169f S |
48 | }, { |
49 | 'url': 'xtube:kVTUy_G222_', | |
50 | 'only_matching': True, | |
ac93c09a S |
51 | }, { |
52 | 'url': 'https://www.xtube.com/video-watch/embedded/milf-tara-and-teen-shared-and-cum-covered-extreme-bukkake-32203482?embedsize=big', | |
53 | 'only_matching': True, | |
86be3cdc | 54 | }] |
dcc2a706 | 55 | |
56 | def _real_extract(self, url): | |
86be3cdc S |
57 | mobj = re.match(self._VALID_URL, url) |
58 | video_id = mobj.group('id') | |
59 | display_id = mobj.group('display_id') | |
60 | ||
61 | if not display_id: | |
62 | display_id = video_id | |
86be3cdc | 63 | |
085f169f S |
64 | if video_id.isdigit() and len(video_id) < 11: |
65 | url_pattern = 'http://www.xtube.com/video-watch/-%s' | |
66 | else: | |
67 | url_pattern = 'http://www.xtube.com/watch.php?v=%s' | |
68 | ||
69 | webpage = self._download_webpage( | |
70 | url_pattern % video_id, display_id, headers={ | |
71 | 'Cookie': 'age_verified=1; cookiesAccepted=1', | |
72 | }) | |
dcc2a706 | 73 | |
e88b4507 S |
74 | title, thumbnail, duration = [None] * 3 |
75 | ||
8bdd16b4 | 76 | config = self._parse_json(self._search_regex( |
77 | r'playerConf\s*=\s*({.+?})\s*,\s*(?:\n|loaderConf)', webpage, 'config', | |
78 | default='{}'), video_id, transform_source=js_to_json, fatal=False) | |
79 | if config: | |
80 | config = config.get('mainRoll') | |
81 | if isinstance(config, dict): | |
82 | title = config.get('title') | |
83 | thumbnail = config.get('poster') | |
84 | duration = int_or_none(config.get('duration')) | |
85 | sources = config.get('sources') or config.get('format') | |
e88b4507 | 86 | |
158bc5ac | 87 | if not isinstance(sources, dict): |
e88b4507 S |
88 | sources = self._parse_json(self._search_regex( |
89 | r'(["\'])?sources\1?\s*:\s*(?P<sources>{.+?}),', | |
90 | webpage, 'sources', group='sources'), video_id, | |
91 | transform_source=js_to_json) | |
1b734adb S |
92 | |
93 | formats = [] | |
94 | for format_id, format_url in sources.items(): | |
95 | formats.append({ | |
96 | 'url': format_url, | |
97 | 'format_id': format_id, | |
98 | 'height': int_or_none(format_id), | |
99 | }) | |
24eb7c25 | 100 | self._remove_duplicate_formats(formats) |
1b734adb S |
101 | self._sort_formats(formats) |
102 | ||
e88b4507 S |
103 | if not title: |
104 | title = self._search_regex( | |
105 | (r'<h1>\s*(?P<title>[^<]+?)\s*</h1>', r'videoTitle\s*:\s*(["\'])(?P<title>.+?)\1'), | |
106 | webpage, 'title', group='title') | |
107 | description = self._og_search_description( | |
108 | webpage, default=None) or self._html_search_meta( | |
109 | 'twitter:description', webpage, default=None) or self._search_regex( | |
86be3cdc | 110 | r'</h1>\s*<p>([^<]+)', webpage, 'description', fatal=False) |
1b734adb S |
111 | uploader = self._search_regex( |
112 | (r'<input[^>]+name="contentOwnerId"[^>]+value="([^"]+)"', | |
113 | r'<span[^>]+class="nickname"[^>]*>([^<]+)'), | |
114 | webpage, 'uploader', fatal=False) | |
e88b4507 S |
115 | if not duration: |
116 | duration = parse_duration(self._search_regex( | |
117 | r'<dt>Runtime:?</dt>\s*<dd>([^<]+)</dd>', | |
118 | webpage, 'duration', fatal=False)) | |
86be3cdc | 119 | view_count = str_to_int(self._search_regex( |
e88b4507 S |
120 | (r'["\']viewsCount["\'][^>]*>(\d+)\s+views', |
121 | r'<dt>Views:?</dt>\s*<dd>([\d,\.]+)</dd>'), | |
16ea8179 S |
122 | webpage, 'view count', fatal=False)) |
123 | comment_count = str_to_int(self._html_search_regex( | |
86be3cdc | 124 | r'>Comments? \(([\d,\.]+)\)<', |
16ea8179 | 125 | webpage, 'comment count', fatal=False)) |
aa488e13 | 126 | |
dcc2a706 | 127 | return { |
128 | 'id': video_id, | |
86be3cdc | 129 | 'display_id': display_id, |
86be3cdc S |
130 | 'title': title, |
131 | 'description': description, | |
e88b4507 | 132 | 'thumbnail': thumbnail, |
86be3cdc | 133 | 'uploader': uploader, |
607dbbad S |
134 | 'duration': duration, |
135 | 'view_count': view_count, | |
136 | 'comment_count': comment_count, | |
dcc2a706 | 137 | 'age_limit': 18, |
1b734adb | 138 | 'formats': formats, |
9f5809b3 | 139 | } |
140 | ||
22a6f150 | 141 | |
9f5809b3 | 142 | class XTubeUserIE(InfoExtractor): |
143 | IE_DESC = 'XTube user profile' | |
34dd81c0 | 144 | _VALID_URL = r'https?://(?:www\.)?xtube\.com/profile/(?P<id>[^/]+-\d+)' |
22a6f150 | 145 | _TEST = { |
34dd81c0 | 146 | 'url': 'http://www.xtube.com/profile/greenshowers-4056496', |
22a6f150 | 147 | 'info_dict': { |
34dd81c0 | 148 | 'id': 'greenshowers-4056496', |
05900629 | 149 | 'age_limit': 18, |
22a6f150 | 150 | }, |
838f051c | 151 | 'playlist_mincount': 154, |
22a6f150 | 152 | } |
9f5809b3 | 153 | |
154 | def _real_extract(self, url): | |
34dd81c0 S |
155 | user_id = self._match_id(url) |
156 | ||
157 | entries = [] | |
158 | for pagenum in itertools.count(1): | |
159 | request = sanitized_Request( | |
160 | 'http://www.xtube.com/profile/%s/videos/%d' % (user_id, pagenum), | |
161 | headers={ | |
162 | 'Cookie': 'popunder=4', | |
163 | 'X-Requested-With': 'XMLHttpRequest', | |
164 | 'Referer': url, | |
165 | }) | |
166 | ||
167 | page = self._download_json( | |
168 | request, user_id, 'Downloading videos JSON page %d' % pagenum) | |
169 | ||
170 | html = page.get('html') | |
171 | if not html: | |
172 | break | |
173 | ||
f4db0917 S |
174 | for video_id in orderedSet([video_id for _, video_id in re.findall( |
175 | r'data-plid=(["\'])(.+?)\1', html)]): | |
34dd81c0 S |
176 | entries.append(self.url_result('xtube:%s' % video_id, XTubeIE.ie_key())) |
177 | ||
178 | page_count = int_or_none(page.get('pageCount')) | |
179 | if not page_count or pagenum == page_count: | |
180 | break | |
181 | ||
182 | playlist = self.playlist_result(entries, user_id) | |
183 | playlist['age_limit'] = 18 | |
184 | return playlist |