[redtube] Capture and output removed video message (#5281)
[youtube-dl] / youtube_dl / extractor / redtube.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..utils import ExtractorError
5
6
7 class RedTubeIE(InfoExtractor):
8     _VALID_URL = r'http://(?:www\.)?redtube\.com/(?P<id>[0-9]+)'
9     _TEST = {
10         'url': 'http://www.redtube.com/66418',
11         'info_dict': {
12             'id': '66418',
13             'ext': 'mp4',
14             "title": "Sucked on a toilet",
15             "age_limit": 18,
16         }
17     }
18
19     def _real_extract(self, url):
20         video_id = self._match_id(url)
21         webpage = self._download_webpage(url, video_id)
22
23         if any(s in webpage for s in ['video-deleted-info', '>This video has been removed']):
24             raise ExtractorError('Video %s has been removed' % video_id, expected=True)
25
26         video_url = self._html_search_regex(
27             r'<source src="(.+?)" type="video/mp4">', webpage, 'video URL')
28         video_title = self._html_search_regex(
29             r'<h1 class="videoTitle[^"]*">(.+?)</h1>',
30             webpage, 'title')
31         video_thumbnail = self._og_search_thumbnail(webpage)
32
33         # No self-labeling, but they describe themselves as
34         # "Home of Videos Porno"
35         age_limit = 18
36
37         return {
38             'id': video_id,
39             'url': video_url,
40             'ext': 'mp4',
41             'title': video_title,
42             'thumbnail': video_thumbnail,
43             'age_limit': age_limit,
44         }