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