]>
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, |
f4db0917 | 9 | orderedSet, |
1b734adb | 10 | parse_duration, |
5c2266df | 11 | sanitized_Request, |
607dbbad | 12 | str_to_int, |
dcc2a706 | 13 | ) |
14 | ||
607dbbad | 15 | |
dcc2a706 | 16 | class XTubeIE(InfoExtractor): |
1b734adb S |
17 | _VALID_URL = r'''(?x) |
18 | (?: | |
19 | xtube:| | |
20 | https?://(?:www\.)?xtube\.com/(?:watch\.php\?.*\bv=|video-watch/(?P<display_id>[^/]+)-) | |
21 | ) | |
22 | (?P<id>[^/?&#]+) | |
23 | ''' | |
86be3cdc S |
24 | |
25 | _TESTS = [{ | |
26 | # old URL schema | |
c5ba203e | 27 | 'url': 'http://www.xtube.com/watch.php?v=kVTUy_G222_', |
c5ba203e AS |
28 | 'md5': '092fbdd3cbe292c920ef6fc6a8a9cdab', |
29 | 'info_dict': { | |
607dbbad S |
30 | 'id': 'kVTUy_G222_', |
31 | 'ext': 'mp4', | |
32 | 'title': 'strange erotica', | |
9789d753 | 33 | 'description': 'contains:an ET kind of thing', |
607dbbad S |
34 | 'uploader': 'greenshowers', |
35 | 'duration': 450, | |
1b734adb S |
36 | 'view_count': int, |
37 | 'comment_count': int, | |
607dbbad | 38 | 'age_limit': 18, |
dcc2a706 | 39 | } |
86be3cdc S |
40 | }, { |
41 | # new URL schema | |
42 | 'url': 'http://www.xtube.com/video-watch/strange-erotica-625837', | |
43 | 'only_matching': True, | |
44 | }, { | |
45 | 'url': 'xtube:625837', | |
46 | 'only_matching': True, | |
47 | }] | |
dcc2a706 | 48 | |
49 | def _real_extract(self, url): | |
86be3cdc S |
50 | mobj = re.match(self._VALID_URL, url) |
51 | video_id = mobj.group('id') | |
52 | display_id = mobj.group('display_id') | |
53 | ||
54 | if not display_id: | |
55 | display_id = video_id | |
56 | url = 'http://www.xtube.com/watch.php?v=%s' % video_id | |
57 | ||
58 | req = sanitized_Request(url) | |
59 | req.add_header('Cookie', 'age_verified=1; cookiesAccepted=1') | |
60 | webpage = self._download_webpage(req, display_id) | |
dcc2a706 | 61 | |
1b734adb S |
62 | sources = self._parse_json(self._search_regex( |
63 | r'sources\s*:\s*({.+?}),', webpage, 'sources'), video_id) | |
64 | ||
65 | formats = [] | |
66 | for format_id, format_url in sources.items(): | |
67 | formats.append({ | |
68 | 'url': format_url, | |
69 | 'format_id': format_id, | |
70 | 'height': int_or_none(format_id), | |
71 | }) | |
72 | self._sort_formats(formats) | |
73 | ||
74 | title = self._search_regex( | |
75 | (r'<h1>(?P<title>[^<]+)</h1>', r'videoTitle\s*:\s*(["\'])(?P<title>.+?)\1'), | |
76 | webpage, 'title', group='title') | |
86be3cdc S |
77 | description = self._search_regex( |
78 | r'</h1>\s*<p>([^<]+)', webpage, 'description', fatal=False) | |
1b734adb S |
79 | uploader = self._search_regex( |
80 | (r'<input[^>]+name="contentOwnerId"[^>]+value="([^"]+)"', | |
81 | r'<span[^>]+class="nickname"[^>]*>([^<]+)'), | |
82 | webpage, 'uploader', fatal=False) | |
83 | duration = parse_duration(self._search_regex( | |
84 | r'<dt>Runtime:</dt>\s*<dd>([^<]+)</dd>', | |
85 | webpage, 'duration', fatal=False)) | |
86be3cdc S |
86 | view_count = str_to_int(self._search_regex( |
87 | r'<dt>Views:</dt>\s*<dd>([\d,\.]+)</dd>', | |
16ea8179 S |
88 | webpage, 'view count', fatal=False)) |
89 | comment_count = str_to_int(self._html_search_regex( | |
86be3cdc | 90 | r'>Comments? \(([\d,\.]+)\)<', |
16ea8179 | 91 | webpage, 'comment count', fatal=False)) |
aa488e13 | 92 | |
dcc2a706 | 93 | return { |
94 | 'id': video_id, | |
86be3cdc | 95 | 'display_id': display_id, |
86be3cdc S |
96 | 'title': title, |
97 | 'description': description, | |
98 | 'uploader': uploader, | |
607dbbad S |
99 | 'duration': duration, |
100 | 'view_count': view_count, | |
101 | 'comment_count': comment_count, | |
dcc2a706 | 102 | 'age_limit': 18, |
1b734adb | 103 | 'formats': formats, |
9f5809b3 | 104 | } |
105 | ||
22a6f150 | 106 | |
9f5809b3 | 107 | class XTubeUserIE(InfoExtractor): |
108 | IE_DESC = 'XTube user profile' | |
34dd81c0 | 109 | _VALID_URL = r'https?://(?:www\.)?xtube\.com/profile/(?P<id>[^/]+-\d+)' |
22a6f150 | 110 | _TEST = { |
34dd81c0 | 111 | 'url': 'http://www.xtube.com/profile/greenshowers-4056496', |
22a6f150 | 112 | 'info_dict': { |
34dd81c0 | 113 | 'id': 'greenshowers-4056496', |
05900629 | 114 | 'age_limit': 18, |
22a6f150 PH |
115 | }, |
116 | 'playlist_mincount': 155, | |
117 | } | |
9f5809b3 | 118 | |
119 | def _real_extract(self, url): | |
34dd81c0 S |
120 | user_id = self._match_id(url) |
121 | ||
122 | entries = [] | |
123 | for pagenum in itertools.count(1): | |
124 | request = sanitized_Request( | |
125 | 'http://www.xtube.com/profile/%s/videos/%d' % (user_id, pagenum), | |
126 | headers={ | |
127 | 'Cookie': 'popunder=4', | |
128 | 'X-Requested-With': 'XMLHttpRequest', | |
129 | 'Referer': url, | |
130 | }) | |
131 | ||
132 | page = self._download_json( | |
133 | request, user_id, 'Downloading videos JSON page %d' % pagenum) | |
134 | ||
135 | html = page.get('html') | |
136 | if not html: | |
137 | break | |
138 | ||
f4db0917 S |
139 | for video_id in orderedSet([video_id for _, video_id in re.findall( |
140 | r'data-plid=(["\'])(.+?)\1', html)]): | |
34dd81c0 S |
141 | entries.append(self.url_result('xtube:%s' % video_id, XTubeIE.ie_key())) |
142 | ||
143 | page_count = int_or_none(page.get('pageCount')) | |
144 | if not page_count or pagenum == page_count: | |
145 | break | |
146 | ||
147 | playlist = self.playlist_result(entries, user_id) | |
148 | playlist['age_limit'] = 18 | |
149 | return playlist |