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)
47 (('video
-deleted
-info
', '>This video has been removed
'), 'has been removed
'),
48 (('private_video_text
', '>This video
is private
', '>Send a friend request to its owner to be able to view it
'), 'is private
'),
51 for patterns, message in ERRORS:
52 if any(p in webpage for p in patterns):
54 'Video
%s %s' % (video_id, message), expected=True)
56 info = self._search_json_ld(webpage, video_id, default={})
58 if not info.get('title
'):
59 info['title
'] = self._html_search_regex(
60 (r'<h(\d
)[^
>]+class="(?:video_title_text|videoTitle)[^"]*">(?P<title>(?:(?!\1).)+)</h\1>',
61 r'(?:videoTitle|title)\s*:\s*(["\'])(?P
<title
>(?
:(?
!\
1).)+)\
1',),
62 webpage, 'title
', group='title
',
63 default=None) or self._og_search_title(webpage)
66 sources = self._parse_json(
68 r'sources\s
*:\s
*({.+?
})', webpage, 'source
', default='{}'),
69 video_id, fatal=False)
70 if sources and isinstance(sources, dict):
71 for format_id, format_url in sources.items():
75 'format_id
': format_id,
76 'height
': int_or_none(format_id),
78 medias = self._parse_json(
80 r'mediaDefinition\s
*:\s
*(\
[.+?\
])', webpage,
81 'media definitions
', default='{}'),
82 video_id, fatal=False)
83 if medias and isinstance(medias, list):
85 format_url = url_or_none(media.get('videoUrl
'))
88 format_id = media.get('quality
')
91 'format_id
': format_id,
92 'height
': int_or_none(format_id),
95 video_url = self._html_search_regex(
96 r'<source src
="(.+?)" type="video/mp4">', webpage, 'video URL
')
97 formats.append({'url
': video_url})
98 self._sort_formats(formats)
100 thumbnail = self._og_search_thumbnail(webpage)
101 upload_date = unified_strdate(self._search_regex(
102 r'<span
[^
>]+>(?
:ADDED|Published on
) ([^
<]+)<',
103 webpage, 'upload date
', default=None))
104 duration = int_or_none(self._og_search_property(
105 'video
:duration
', webpage, default=None) or self._search_regex(
106 r'videoDuration\s
*:\s
*(\d
+)', webpage, 'duration
', default=None))
107 view_count = str_to_int(self._search_regex(
108 (r'<div
[^
>]*>Views
</div
>\s
*<div
[^
>]*>\s
*([\d
,.]+)',
109 r'<span
[^
>]*>VIEWS
</span
>\s
*</td
>\s
*<td
>\s
*([\d
,.]+)',
110 r'<span
[^
>]+\bclass
=["\']video_view_count[^>]*>\s*([\d,.]+)'),
111 webpage, 'view count', default=None))
113 # No self-labeling, but they describe themselves as
114 # "Home of Videos Porno
"
117 return merge_dicts(info, {
120 'thumbnail': thumbnail,
121 'upload_date': upload_date,
122 'duration': duration,
123 'view_count': view_count,
124 'age_limit': age_limit,