[xvideos] Capture and output inline error if any
[youtube-dl] / youtube_dl / extractor / xvideos.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7     compat_urllib_parse,
8     ExtractorError,
9     clean_html,
10 )
11
12
13 class XVideosIE(InfoExtractor):
14     _VALID_URL = r'^(?:https?://)?(?:www\.)?xvideos\.com/video([0-9]+)(?:.*)'
15     _TEST = {
16         'url': 'http://www.xvideos.com/video939581/funny_porns_by_s_-1',
17         'file': '939581.flv',
18         'md5': '1d0c835822f0a71a7bf011855db929d0',
19         'info_dict': {
20             "title": "Funny Porns By >>>>S<<<<<< -1",
21             "age_limit": 18,
22         }
23     }
24
25     def _real_extract(self, url):
26         mobj = re.match(self._VALID_URL, url)
27         video_id = mobj.group(1)
28
29         webpage = self._download_webpage(url, video_id)
30
31         self.report_extraction(video_id)
32
33         mobj = re.search(r'<h1 class="inlineError">(.+?)</h1>', webpage)
34         if mobj:
35             raise ExtractorError('%s said: %s' % (self.IE_NAME, clean_html(mobj.group(1))), expected=True)
36
37         # Extract video URL
38         video_url = compat_urllib_parse.unquote(
39             self._search_regex(r'flv_url=(.+?)&', webpage, 'video URL'))
40
41         # Extract title
42         video_title = self._html_search_regex(
43             r'<title>(.*?)\s+-\s+XVID', webpage, 'title')
44
45         # Extract video thumbnail
46         video_thumbnail = self._search_regex(
47             r'url_bigthumb=(.+?)&amp', webpage, 'thumbnail', fatal=False)
48
49         return {
50             'id': video_id,
51             'url': video_url,
52             'uploader': None,
53             'upload_date': None,
54             'title': video_title,
55             'ext': 'flv',
56             'thumbnail': video_thumbnail,
57             'description': None,
58             'age_limit': 18,
59         }