]>
Commit | Line | Data |
---|---|---|
2fb3deec S |
1 | from __future__ import unicode_literals |
2 | ||
1d45a23b | 3 | import re |
4 | ||
5 | from .common import InfoExtractor | |
27b83249 | 6 | from ..compat import compat_str |
1cc79574 | 7 | from ..utils import ( |
2fb3deec | 8 | int_or_none, |
5c2266df | 9 | sanitized_Request, |
2fb3deec | 10 | str_to_int, |
1d45a23b | 11 | ) |
2fb3deec S |
12 | from ..aes import aes_decrypt_text |
13 | ||
1d45a23b | 14 | |
15 | class Tube8IE(InfoExtractor): | |
58e7071a S |
16 | _VALID_URL = r'https?://(?:www\.)?tube8\.com/(?:[^/]+/)+(?P<display_id>[^/]+)/(?P<id>\d+)' |
17 | _TESTS = [ | |
18 | { | |
19 | 'url': 'http://www.tube8.com/teen/kasia-music-video/229795/', | |
20 | 'md5': '44bf12b98313827dd52d35b8706a4ea0', | |
21 | 'info_dict': { | |
22 | 'id': '229795', | |
23 | 'display_id': 'kasia-music-video', | |
24 | 'ext': 'mp4', | |
25 | 'description': 'hot teen Kasia grinding', | |
26 | 'uploader': 'unknown', | |
27 | 'title': 'Kasia music video', | |
28 | 'age_limit': 18, | |
29 | } | |
30 | }, | |
31 | { | |
32 | 'url': 'http://www.tube8.com/shemale/teen/blonde-cd-gets-kidnapped-by-two-blacks-and-punished-for-being-a-slutty-girl/19569151/', | |
33 | 'only_matching': True, | |
34 | }, | |
35 | ] | |
1d45a23b | 36 | |
37 | def _real_extract(self, url): | |
38 | mobj = re.match(self._VALID_URL, url) | |
2fb3deec | 39 | video_id = mobj.group('id') |
58e7071a | 40 | display_id = mobj.group('display_id') |
1d45a23b | 41 | |
5c2266df | 42 | req = sanitized_Request(url) |
1d45a23b | 43 | req.add_header('Cookie', 'age_verified=1') |
58e7071a | 44 | webpage = self._download_webpage(req, display_id) |
1d45a23b | 45 | |
27b83249 S |
46 | flashvars = self._parse_json( |
47 | self._search_regex( | |
48 | r'flashvars\s*=\s*({.+?});\r?\n', webpage, 'flashvars'), | |
49 | video_id) | |
2fb3deec | 50 | |
27b83249 S |
51 | formats = [] |
52 | for key, video_url in flashvars.items(): | |
53 | if not isinstance(video_url, compat_str) or not video_url.startswith('http'): | |
54 | continue | |
55 | height = self._search_regex( | |
56 | r'quality_(\d+)[pP]', key, 'height', default=None) | |
57 | if not height: | |
58 | continue | |
59 | if flashvars.get('encrypted') is True: | |
60 | video_url = aes_decrypt_text( | |
61 | video_url, flashvars['video_title'], 32).decode('utf-8') | |
62 | formats.append({ | |
63 | 'url': video_url, | |
64 | 'format_id': '%sp' % height, | |
65 | 'height': int(height), | |
66 | }) | |
67 | self._sort_formats(formats) | |
2fb3deec S |
68 | |
69 | thumbnail = flashvars.get('image_url') | |
70 | ||
71 | title = self._html_search_regex( | |
6ebdfe43 | 72 | r'videoTitle\s*=\s*"([^"]+)', webpage, 'title') |
2fb3deec | 73 | description = self._html_search_regex( |
6ebdfe43 | 74 | r'>Description:</strong>\s*(.+?)\s*<', webpage, 'description', fatal=False) |
2fb3deec | 75 | uploader = self._html_search_regex( |
6ebdfe43 | 76 | r'<span class="username">\s*(.+?)\s*<', |
2fb3deec S |
77 | webpage, 'uploader', fatal=False) |
78 | ||
79 | like_count = int_or_none(self._html_search_regex( | |
6ebdfe43 | 80 | r'rupVar\s*=\s*"(\d+)"', webpage, 'like count', fatal=False)) |
2fb3deec | 81 | dislike_count = int_or_none(self._html_search_regex( |
6ebdfe43 | 82 | r'rdownVar\s*=\s*"(\d+)"', webpage, 'dislike count', fatal=False)) |
2fb3deec | 83 | view_count = self._html_search_regex( |
6ebdfe43 | 84 | r'<strong>Views: </strong>([\d,\.]+)\s*</li>', webpage, 'view count', fatal=False) |
2fb3deec S |
85 | if view_count: |
86 | view_count = str_to_int(view_count) | |
87 | comment_count = self._html_search_regex( | |
88 | r'<span id="allCommentsCount">(\d+)</span>', webpage, 'comment count', fatal=False) | |
89 | if comment_count: | |
90 | comment_count = str_to_int(comment_count) | |
1d45a23b | 91 | |
92 | return { | |
93 | 'id': video_id, | |
58e7071a | 94 | 'display_id': display_id, |
2fb3deec S |
95 | 'title': title, |
96 | 'description': description, | |
97 | 'thumbnail': thumbnail, | |
98 | 'uploader': uploader, | |
2fb3deec S |
99 | 'view_count': view_count, |
100 | 'like_count': like_count, | |
101 | 'dislike_count': dislike_count, | |
102 | 'comment_count': comment_count, | |
750e9833 | 103 | 'age_limit': 18, |
27b83249 | 104 | 'formats': formats, |
1d45a23b | 105 | } |