]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/extremetube.py
Imported Upstream version 2013.11.11
[youtubedl] / youtube_dl / extractor / extremetube.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 ExtremeTubeIE(InfoExtractor):
12 _VALID_URL = r'^(?:https?://)?(?:www\.)?(?P<url>extremetube\.com/video/.+?(?P<videoid>[0-9]+))(?:[/?&]|$)'
13 _TEST = {
14 u'url': u'http://www.extremetube.com/video/music-video-14-british-euro-brit-european-cumshots-swallow-652431',
15 u'file': u'652431.mp4',
16 u'md5': u'1fb9228f5e3332ec8c057d6ac36f33e0',
17 u'info_dict': {
18 u"title": u"Music Video 14 british euro brit european cumshots swallow",
19 u"uploader": u"unknown",
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'<h1 [^>]*?title="([^"]+)"[^>]*>\1<', webpage, u'title')
34 uploader = self._html_search_regex(r'>Posted by:(?=<)(?:\s|<[^>]*>)*(.+?)\|', webpage, u'uploader', fatal=False)
35 video_url = compat_urllib_parse.unquote(self._html_search_regex(r'video_url=(.+?)&amp;', webpage, u'video_url'))
36 path = compat_urllib_parse_urlparse(video_url).path
37 extension = os.path.splitext(path)[1][1:]
38 format = path.split('/')[5].split('_')[:2]
39 format = "-".join(format)
40
41 return {
42 'id': video_id,
43 'title': video_title,
44 'uploader': uploader,
45 'url': video_url,
46 'ext': extension,
47 'format': format,
48 'format_id': format,
49 'age_limit': 18,
50 }