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