1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
17 class RedTubeIE(InfoExtractor
):
18 _VALID_URL
= r
'https?://(?:(?:www\.)?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,
37 def _extract_urls(webpage
):
39 r
'<iframe[^>]+?src=["\'](?P
<url
>(?
:https?
:)?
//embed\
.redtube\
.com
/\?.*?
\bid
=\d
+)',
42 def _real_extract(self, url):
43 video_id = self._match_id(url)
44 webpage = self._download_webpage(
45 'http
://www
.redtube
.com
/%s' % video_id, video_id)
48 (('video
-deleted
-info
', '>This video has been removed
'), 'has been removed
'),
49 (('private_video_text
', '>This video
is private
', '>Send a friend request to its owner to be able to view it
'), 'is private
'),
52 for patterns, message in ERRORS:
53 if any(p in webpage for p in patterns):
55 'Video
%s %s' % (video_id, message), expected=True)
57 info = self._search_json_ld(webpage, video_id, default={})
59 if not info.get('title
'):
60 info['title
'] = self._html_search_regex(
61 (r'<h(\d
)[^
>]+class="(?:video_title_text|videoTitle|video_title)[^"]*">(?P<title>(?:(?!\1).)+)</h\1>',
62 r'(?:videoTitle|title)\s*:\s*(["\'])(?P
<title
>(?
:(?
!\
1).)+)\
1',),
63 webpage, 'title
', group='title
',
64 default=None) or self._og_search_title(webpage)
67 sources = self._parse_json(
69 r'sources\s
*:\s
*({.+?
})', webpage, 'source
', default='{}'),
70 video_id, fatal=False)
71 if sources and isinstance(sources, dict):
72 for format_id, format_url in sources.items():
76 'format_id
': format_id,
77 'height
': int_or_none(format_id),
79 medias = self._parse_json(
81 r'mediaDefinition
["\']?\s*:\s*(\[.+?}\s*\])', webpage,
82 'media definitions', default='{}'),
83 video_id, fatal=False)
84 if medias and isinstance(medias, list):
86 format_url = url_or_none(media.get('videoUrl'))
89 if media.get('format') == 'hls' or determine_ext(format_url) == 'm3u8':
90 formats.extend(self._extract_m3u8_formats(
91 format_url, video_id, 'mp4',
92 entry_protocol='m3u8_native', m3u8_id='hls',
95 format_id = media.get('quality')
98 'format_id': format_id,
99 'height': int_or_none(format_id),
102 video_url = self._html_search_regex(
103 r'<source src="(.+?
)" type="video
/mp4
">', webpage, 'video URL')
104 formats.append({'url': video_url})
105 self._sort_formats(formats)
107 thumbnail = self._og_search_thumbnail(webpage)
108 upload_date = unified_strdate(self._search_regex(
109 r'<span[^>]+>(?:ADDED|Published on) ([^<]+)<',
110 webpage, 'upload date', default=None))
111 duration = int_or_none(self._og_search_property(
112 'video:duration', webpage, default=None) or self._search_regex(
113 r'videoDuration\s*:\s*(\d+)', webpage, 'duration', default=None))
114 view_count = str_to_int(self._search_regex(
115 (r'<div[^>]*>Views</div>\s*<div[^>]*>\s*([\d,.]+)',
116 r'<span[^>]*>VIEWS</span>\s*</td>\s*<td>\s*([\d,.]+)',
117 r'<span[^>]+\bclass=["\']video_view_count
[^
>]*>\s
*([\d
,.]+)'),
118 webpage, 'view count
', default=None))
120 # No self-labeling, but they describe themselves as
121 # "Home of Videos Porno"
124 return merge_dicts(info, {
127 'thumbnail
': thumbnail,
128 'upload_date
': upload_date,
129 'duration
': duration,
130 'view_count
': view_count,
131 'age_limit
': age_limit,