1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
16 class RedTubeIE(InfoExtractor
):
17 _VALID_URL
= r
'https?://(?:(?:www\.)?redtube\.com/|embed\.redtube\.com/\?.*?\bid=)(?P<id>[0-9]+)'
19 'url': 'http://www.redtube.com/66418',
20 'md5': 'fc08071233725f26b8f014dba9590005',
24 'title': 'Sucked on a toilet',
25 'upload_date': '20110811',
31 'url': 'http://embed.redtube.com/?bgcolor=000000&id=1443286',
32 'only_matching': True,
36 def _extract_urls(webpage
):
38 r
'<iframe[^>]+?src=["\'](?P
<url
>(?
:https?
:)?
//embed\
.redtube\
.com
/\?.*?
\bid
=\d
+)',
41 def _real_extract(self, url):
42 video_id = self._match_id(url)
43 webpage = self._download_webpage(
44 'http
://www
.redtube
.com
/%s' % video_id, video_id)
46 if any(s in webpage for s in ['video
-deleted
-info
', '>This video has been removed
']):
47 raise ExtractorError('Video
%s has been removed
' % video_id, expected=True)
49 info = self._search_json_ld(webpage, video_id, default={})
51 if not info.get('title
'):
52 info['title
'] = self._html_search_regex(
53 (r'<h(\d
)[^
>]+class="(?:video_title_text|videoTitle)[^"]*">(?P<title>(?:(?!\1).)+)</h\1>',
54 r'(?:videoTitle|title)\s*:\s*(["\'])(?P
<title
>(?
:(?
!\
1).)+)\
1',),
55 webpage, 'title
', group='title
',
56 default=None) or self._og_search_title(webpage)
59 sources = self._parse_json(
61 r'sources\s
*:\s
*({.+?}
)', webpage, 'source
', default='{}'),
62 video_id, fatal=False)
63 if sources and isinstance(sources, dict):
64 for format_id, format_url in sources.items():
68 'format_id
': format_id,
69 'height
': int_or_none(format_id),
71 medias = self._parse_json(
73 r'mediaDefinition\s
*:\s
*(\
[.+?\
])', webpage,
74 'media definitions
', default='{}'),
75 video_id, fatal=False)
76 if medias and isinstance(medias, list):
78 format_url = url_or_none(media.get('videoUrl
'))
81 format_id = media.get('quality
')
84 'format_id
': format_id,
85 'height
': int_or_none(format_id),
88 video_url = self._html_search_regex(
89 r'<source src
="(.+?)" type="video/mp4">', webpage, 'video URL
')
90 formats.append({'url': video_url})
91 self._sort_formats(formats)
93 thumbnail = self._og_search_thumbnail(webpage)
94 upload_date = unified_strdate(self._search_regex(
95 r'<span
[^
>]+>(?
:ADDED|Published on
) ([^
<]+)<',
96 webpage, 'upload date
', default=None))
97 duration = int_or_none(self._og_search_property(
98 'video
:duration
', webpage, default=None) or self._search_regex(
99 r'videoDuration\s
*:\s
*(\d
+)', webpage, 'duration
', default=None))
100 view_count = str_to_int(self._search_regex(
101 (r'<div
[^
>]*>Views
</div
>\s
*<div
[^
>]*>\s
*([\d
,.]+)',
102 r'<span
[^
>]*>VIEWS
</span
>\s
*</td
>\s
*<td
>\s
*([\d
,.]+)',
103 r'<span
[^
>]+\bclass
=["\']video_view_count[^>]*>\s*([\d,.]+)'),
104 webpage, 'view count', default=None))
106 # No self-labeling, but they describe themselves as
107 # "Home of Videos Porno
"
110 return merge_dicts(info, {
113 'thumbnail': thumbnail,
114 'upload_date': upload_date,
115 'duration': duration,
116 'view_count': view_count,
117 'age_limit': age_limit,