]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/xvideos.py
Update the changelog.
[youtubedl] / youtube_dl / extractor / xvideos.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..compat import compat_urllib_parse_unquote
7 from ..utils import (
8 clean_html,
9 ExtractorError,
10 determine_ext,
11 )
12
13
14 class XVideosIE(InfoExtractor):
15 _VALID_URL = r'https?://(?:www\.)?xvideos\.com/video(?P<id>[0-9]+)(?:.*)'
16 _TEST = {
17 'url': 'http://www.xvideos.com/video4588838/biker_takes_his_girl',
18 'md5': '4b46ae6ea5e6e9086e714d883313c0c9',
19 'info_dict': {
20 'id': '4588838',
21 'ext': 'flv',
22 'title': 'Biker Takes his Girl',
23 'age_limit': 18,
24 }
25 }
26
27 def _real_extract(self, url):
28 video_id = self._match_id(url)
29 webpage = self._download_webpage(url, video_id)
30
31 mobj = re.search(r'<h1 class="inlineError">(.+?)</h1>', webpage)
32 if mobj:
33 raise ExtractorError('%s said: %s' % (self.IE_NAME, clean_html(mobj.group(1))), expected=True)
34
35 video_title = self._html_search_regex(
36 r'<title>(.*?)\s+-\s+XVID', webpage, 'title')
37 video_thumbnail = self._search_regex(
38 r'url_bigthumb=(.+?)&amp', webpage, 'thumbnail', fatal=False)
39
40 formats = []
41
42 video_url = compat_urllib_parse_unquote(self._search_regex(
43 r'flv_url=(.+?)&', webpage, 'video URL', default=''))
44 if video_url:
45 formats.append({'url': video_url})
46
47 player_args = self._search_regex(
48 r'(?s)new\s+HTML5Player\((.+?)\)', webpage, ' html5 player', default=None)
49 if player_args:
50 for arg in player_args.split(','):
51 format_url = self._search_regex(
52 r'(["\'])(?P<url>https?://.+?)\1', arg, 'url',
53 default=None, group='url')
54 if not format_url:
55 continue
56 ext = determine_ext(format_url)
57 if ext == 'mp4':
58 formats.append({'url': format_url})
59 elif ext == 'm3u8':
60 formats.extend(self._extract_m3u8_formats(
61 format_url, video_id, 'mp4',
62 entry_protocol='m3u8_native', m3u8_id='hls', fatal=False))
63
64 self._sort_formats(formats)
65
66 return {
67 'id': video_id,
68 'formats': formats,
69 'title': video_title,
70 'thumbnail': video_thumbnail,
71 'age_limit': 18,
72 }