1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
17 class RedTubeIE(InfoExtractor
):
18 _VALID_URL
= r
'https?://(?:(?:\w+\.)?redtube\.com/|embed\.redtube\.com/\?.*?\bid=)(?P<id>[0-9]+)'
20 'url': 'http://www.redtube.com/66418',
21 'md5': 'fc08071233725f26b8f014dba9590005',
25 'title': 'Sucked on a toilet',
26 'upload_date': '20110811',
32 'url': 'http://embed.redtube.com/?bgcolor=000000&id=1443286',
33 'only_matching': True,
35 'url': 'http://it.redtube.com/66418',
36 'only_matching': True,
40 def _extract_urls(webpage
):
42 r
'<iframe[^>]+?src=["\'](?P
<url
>(?
:https?
:)?
//embed\
.redtube\
.com
/\?.*?
\bid
=\d
+)',
45 def _real_extract(self, url):
46 video_id = self._match_id(url)
47 webpage = self._download_webpage(
48 'http
://www
.redtube
.com
/%s' % video_id, video_id)
51 (('video
-deleted
-info
', '>This video has been removed
'), 'has been removed
'),
52 (('private_video_text
', '>This video
is private
', '>Send a friend request to its owner to be able to view it
'), 'is private
'),
55 for patterns, message in ERRORS:
56 if any(p in webpage for p in patterns):
58 'Video
%s %s' % (video_id, message), expected=True)
60 info = self._search_json_ld(webpage, video_id, default={})
62 if not info.get('title
'):
63 info['title
'] = self._html_search_regex(
64 (r'<h(\d
)[^
>]+class="(?:video_title_text|videoTitle|video_title)[^"]*">(?P<title>(?:(?!\1).)+)</h\1>',
65 r'(?:videoTitle|title)\s*:\s*(["\'])(?P
<title
>(?
:(?
!\
1).)+)\
1',),
66 webpage, 'title
', group='title
',
67 default=None) or self._og_search_title(webpage)
70 sources = self._parse_json(
72 r'sources\s
*:\s
*({.+?}
)', webpage, 'source
', default='{}'),
73 video_id, fatal=False)
74 if sources and isinstance(sources, dict):
75 for format_id, format_url in sources.items():
79 'format_id
': format_id,
80 'height
': int_or_none(format_id),
82 medias = self._parse_json(
84 r'mediaDefinition
["\']?\s*:\s*(\[.+?}\s*\])', webpage,
85 'media definitions', default='{}'),
86 video_id, fatal=False)
87 if medias and isinstance(medias, list):
89 format_url = url_or_none(media.get('videoUrl'))
92 if media.get('format') == 'hls' or determine_ext(format_url) == 'm3u8':
93 formats.extend(self._extract_m3u8_formats(
94 format_url, video_id, 'mp4',
95 entry_protocol='m3u8_native', m3u8_id='hls',
98 format_id = media.get('quality')
102 'format_id': format_id,
103 'height': int_or_none(format_id),
106 video_url = self._html_search_regex(
107 r'<source src="(.+?
)" type="video
/mp4
">', webpage, 'video URL')
108 formats.append({'url': video_url, 'ext': 'mp4'})
109 self._sort_formats(formats)
111 thumbnail = self._og_search_thumbnail(webpage)
112 upload_date = unified_strdate(self._search_regex(
113 r'<span[^>]+>(?:ADDED|Published on) ([^<]+)<',
114 webpage, 'upload date', default=None))
115 duration = int_or_none(self._og_search_property(
116 'video:duration', webpage, default=None) or self._search_regex(
117 r'videoDuration\s*:\s*(\d+)', webpage, 'duration', default=None))
118 view_count = str_to_int(self._search_regex(
119 (r'<div[^>]*>Views</div>\s*<div[^>]*>\s*([\d,.]+)',
120 r'<span[^>]*>VIEWS</span>\s*</td>\s*<td>\s*([\d,.]+)',
121 r'<span[^>]+\bclass=["\']video_view_count
[^
>]*>\s
*([\d
,.]+)'),
122 webpage, 'view count
', default=None))
124 # No self-labeling, but they describe themselves as
125 # "Home of Videos Porno"
128 return merge_dicts(info, {
131 'thumbnail
': thumbnail,
132 'upload_date
': upload_date,
133 'duration
': duration,
134 'view_count
': view_count,
135 'age_limit
': age_limit,