]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/xtube.py
982619922d8ef5fdd0f260902b0253f5dce024dd
[youtubedl] / youtube_dl / extractor / xtube.py
1 from __future__ import unicode_literals
2
3 import os
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 compat_urllib_parse_urlparse,
9 compat_urllib_request,
10 )
11
12 class XTubeIE(InfoExtractor):
13 _VALID_URL = r'^(?:https?://)?(?:www\.)?(?P<url>xtube\.com/watch\.php\?v=(?P<videoid>[^/?&]+))'
14 _TEST = {
15 'url': 'http://www.xtube.com/watch.php?v=kVTUy_G222_',
16 'file': 'kVTUy_G222_.mp4',
17 'md5': '092fbdd3cbe292c920ef6fc6a8a9cdab',
18 'info_dict': {
19 "title": "strange erotica",
20 "description": "surreal gay themed erotica...almost an ET kind of thing",
21 "uploader": "greenshowers",
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('videoid')
29 url = 'http://www.' + mobj.group('url')
30
31 req = compat_urllib_request.Request(url)
32 req.add_header('Cookie', 'age_verified=1')
33 webpage = self._download_webpage(req, video_id)
34
35 video_title = self._html_search_regex(r'<div class="p_5px[^>]*>([^<]+)', webpage, 'title')
36 video_uploader = self._html_search_regex(r'so_s\.addVariable\("owner_u", "([^"]+)', webpage, 'uploader', fatal=False)
37 video_description = self._html_search_regex(r'<p class="video_description">([^<]+)', webpage, 'description', fatal=False)
38 video_url= self._html_search_regex(r'var videoMp4 = "([^"]+)', webpage, 'video_url').replace('\\/', '/')
39 path = compat_urllib_parse_urlparse(video_url).path
40 extension = os.path.splitext(path)[1][1:]
41 format = path.split('/')[5].split('_')[:2]
42 format[0] += 'p'
43 format[1] += 'k'
44 format = "-".join(format)
45
46 return {
47 'id': video_id,
48 'title': video_title,
49 'uploader': video_uploader,
50 'description': video_description,
51 'url': video_url,
52 'ext': extension,
53 'format': format,
54 'format_id': format,
55 'age_limit': 18,
56 }