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