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