]>
Commit | Line | Data |
---|---|---|
9f5daf00 | 1 | from .common import InfoExtractor |
ac12e888 | 2 | from ..utils import ( |
cd13343a | 3 | determine_ext, |
ac12e888 S |
4 | ExtractorError, |
5 | int_or_none, | |
560d3b7d | 6 | merge_dicts, |
ac12e888 S |
7 | str_to_int, |
8 | unified_strdate, | |
3052a30d | 9 | url_or_none, |
c91d8b18 | 10 | urljoin, |
ac12e888 | 11 | ) |
9f5daf00 PH |
12 | |
13 | ||
14 | class RedTubeIE(InfoExtractor): | |
4a6ff0b4 | 15 | _VALID_URL = r'https?://(?:(?:\w+\.)?redtube\.com(?:\.br)?/|embed\.redtube\.com/\?.*?\bid=)(?P<id>[0-9]+)' |
bfd973ec | 16 | _EMBED_REGEX = [r'<iframe[^>]+?src=["\'](?P<url>(?:https?:)?//embed\.redtube\.com/\?.*?\bid=\d+)'] |
5021ca6c | 17 | _TESTS = [{ |
93864403 | 18 | 'url': 'https://www.redtube.com/38864951', |
19 | 'md5': '4fba70cbca3aefd25767ab4b523c9878', | |
032b3df5 | 20 | 'info_dict': { |
93864403 | 21 | 'id': '38864951', |
faf34948 | 22 | 'ext': 'mp4', |
93864403 | 23 | 'title': 'Public Sex on the Balcony in Freezing Paris! Amateur Couple LeoLulu', |
24 | 'description': 'Watch video Public Sex on the Balcony in Freezing Paris! Amateur Couple LeoLulu on Redtube, home of free Blowjob porn videos and Blonde sex movies online. Video length: (10:46) - Uploaded by leolulu - Verified User - Starring Pornstar: Leolulu', | |
25 | 'upload_date': '20210111', | |
26 | 'timestamp': 1610343109, | |
27 | 'duration': 646, | |
ac12e888 | 28 | 'view_count': int, |
838b9340 | 29 | 'age_limit': 18, |
93864403 | 30 | 'thumbnail': r're:https://\wi-ph\.rdtcdn\.com/videos/.+/.+\.jpg', |
31 | }, | |
5021ca6c S |
32 | }, { |
33 | 'url': 'http://embed.redtube.com/?bgcolor=000000&id=1443286', | |
34 | 'only_matching': True, | |
1ca5f821 | 35 | }, { |
36 | 'url': 'http://it.redtube.com/66418', | |
37 | 'only_matching': True, | |
4a6ff0b4 | 38 | }, { |
39 | 'url': 'https://www.redtube.com.br/103224331', | |
40 | 'only_matching': True, | |
5021ca6c | 41 | }] |
9f5daf00 | 42 | |
cd214418 | 43 | def _real_extract(self, url): |
faf34948 | 44 | video_id = self._match_id(url) |
5021ca6c | 45 | webpage = self._download_webpage( |
b012271d | 46 | f'https://www.redtube.com/{video_id}', video_id) |
9f5daf00 | 47 | |
484637a9 S |
48 | ERRORS = ( |
49 | (('video-deleted-info', '>This video has been removed'), 'has been removed'), | |
50 | (('private_video_text', '>This video is private', '>Send a friend request to its owner to be able to view it'), 'is private'), | |
51 | ) | |
52 | ||
53 | for patterns, message in ERRORS: | |
54 | if any(p in webpage for p in patterns): | |
55 | raise ExtractorError( | |
56 | 'Video %s %s' % (video_id, message), expected=True) | |
2676caf3 | 57 | |
560d3b7d S |
58 | info = self._search_json_ld(webpage, video_id, default={}) |
59 | ||
60 | if not info.get('title'): | |
61 | info['title'] = self._html_search_regex( | |
bf097a50 | 62 | (r'<h(\d)[^>]+class="(?:video_title_text|videoTitle|video_title)[^"]*">(?P<title>(?:(?!\1).)+)</h\1>', |
560d3b7d S |
63 | r'(?:videoTitle|title)\s*:\s*(["\'])(?P<title>(?:(?!\1).)+)\1',), |
64 | webpage, 'title', group='title', | |
65 | default=None) or self._og_search_title(webpage) | |
ac12e888 S |
66 | |
67 | formats = [] | |
68 | sources = self._parse_json( | |
69 | self._search_regex( | |
70 | r'sources\s*:\s*({.+?})', webpage, 'source', default='{}'), | |
71 | video_id, fatal=False) | |
72 | if sources and isinstance(sources, dict): | |
73 | for format_id, format_url in sources.items(): | |
74 | if format_url: | |
75 | formats.append({ | |
76 | 'url': format_url, | |
77 | 'format_id': format_id, | |
78 | 'height': int_or_none(format_id), | |
79 | }) | |
880fa66f S |
80 | medias = self._parse_json( |
81 | self._search_regex( | |
cd13343a | 82 | r'mediaDefinition["\']?\s*:\s*(\[.+?}\s*\])', webpage, |
880fa66f S |
83 | 'media definitions', default='{}'), |
84 | video_id, fatal=False) | |
93864403 | 85 | for media in medias if isinstance(medias, list) else []: |
c91d8b18 | 86 | format_url = urljoin('https://www.redtube.com', media.get('videoUrl')) |
93864403 | 87 | if not format_url: |
88 | continue | |
89 | format_id = media.get('format') | |
90 | quality = media.get('quality') | |
91 | if format_id == 'hls' or (format_id == 'mp4' and not quality): | |
92 | more_media = self._download_json(format_url, video_id, fatal=False) | |
93 | else: | |
94 | more_media = [media] | |
95 | for media in more_media if isinstance(more_media, list) else []: | |
3052a30d S |
96 | format_url = url_or_none(media.get('videoUrl')) |
97 | if not format_url: | |
880fa66f | 98 | continue |
93864403 | 99 | format_id = media.get('format') |
100 | if format_id == 'hls' or determine_ext(format_url) == 'm3u8': | |
cd13343a S |
101 | formats.extend(self._extract_m3u8_formats( |
102 | format_url, video_id, 'mp4', | |
93864403 | 103 | entry_protocol='m3u8_native', m3u8_id=format_id or 'hls', |
cd13343a S |
104 | fatal=False)) |
105 | continue | |
880fa66f S |
106 | format_id = media.get('quality') |
107 | formats.append({ | |
108 | 'url': format_url, | |
265a7a8e | 109 | 'ext': 'mp4', |
880fa66f S |
110 | 'format_id': format_id, |
111 | 'height': int_or_none(format_id), | |
112 | }) | |
113 | if not formats: | |
ac12e888 S |
114 | video_url = self._html_search_regex( |
115 | r'<source src="(.+?)" type="video/mp4">', webpage, 'video URL') | |
265a7a8e | 116 | formats.append({'url': video_url, 'ext': 'mp4'}) |
ac12e888 S |
117 | |
118 | thumbnail = self._og_search_thumbnail(webpage) | |
119 | upload_date = unified_strdate(self._search_regex( | |
560d3b7d S |
120 | r'<span[^>]+>(?:ADDED|Published on) ([^<]+)<', |
121 | webpage, 'upload date', default=None)) | |
18ebd1a8 W |
122 | duration = int_or_none(self._og_search_property( |
123 | 'video:duration', webpage, default=None) or self._search_regex( | |
124 | r'videoDuration\s*:\s*(\d+)', webpage, 'duration', default=None)) | |
ac12e888 | 125 | view_count = str_to_int(self._search_regex( |
1367c798 | 126 | (r'<div[^>]*>Views</div>\s*<div[^>]*>\s*([\d,.]+)', |
560d3b7d S |
127 | r'<span[^>]*>VIEWS</span>\s*</td>\s*<td>\s*([\d,.]+)', |
128 | r'<span[^>]+\bclass=["\']video_view_count[^>]*>\s*([\d,.]+)'), | |
129 | webpage, 'view count', default=None)) | |
ac12e888 | 130 | |
1310bf24 PH |
131 | # No self-labeling, but they describe themselves as |
132 | # "Home of Videos Porno" | |
133 | age_limit = 18 | |
134 | ||
560d3b7d | 135 | return merge_dicts(info, { |
032b3df5 | 136 | 'id': video_id, |
faf34948 | 137 | 'ext': 'mp4', |
ac12e888 S |
138 | 'thumbnail': thumbnail, |
139 | 'upload_date': upload_date, | |
140 | 'duration': duration, | |
141 | 'view_count': view_count, | |
1310bf24 | 142 | 'age_limit': age_limit, |
ac12e888 | 143 | 'formats': formats, |
560d3b7d | 144 | }) |