]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/xvideos.py
Credit @haricharan for einthusan (#3755)
[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/video4588838/biker_takes_his_girl',
17         'md5': '4b46ae6ea5e6e9086e714d883313c0c9',
18         'info_dict': {
19             'id': '4588838',
20             'ext': 'flv',
21             'title': 'Biker Takes his Girl',
22             'age_limit': 18,
23         }
24     }
25
26     def _real_extract(self, url):
27         mobj = re.match(self._VALID_URL, url)
28         video_id = mobj.group(1)
29
30         webpage = self._download_webpage(url, video_id)
31
32         self.report_extraction(video_id)
33
34         mobj = re.search(r'<h1 class="inlineError">(.+?)</h1>', webpage)
35         if mobj:
36             raise ExtractorError('%s said: %s' % (self.IE_NAME, clean_html(mobj.group(1))), expected=True)
37
38         # Extract video URL
39         video_url = compat_urllib_parse.unquote(
40             self._search_regex(r'flv_url=(.+?)&', webpage, 'video URL'))
41
42         # Extract title
43         video_title = self._html_search_regex(
44             r'<title>(.*?)\s+-\s+XVID', webpage, 'title')
45
46         # Extract video thumbnail
47         video_thumbnail = self._search_regex(
48             r'url_bigthumb=(.+?)&amp', webpage, 'thumbnail', fatal=False)
49
50         return {
51             'id': video_id,
52             'url': video_url,
53             'uploader': None,
54             'upload_date': None,
55             'title': video_title,
56             'ext': 'flv',
57             'thumbnail': video_thumbnail,
58             'description': None,
59             'age_limit': 18,
60         }