]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/extremetube.py
debian/changelog: Start new release.
[youtubedl] / youtube_dl / extractor / extremetube.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7 compat_urllib_parse_urlparse,
8 compat_urllib_request,
9 compat_urllib_parse,
10 )
11
12
13 class ExtremeTubeIE(InfoExtractor):
14 _VALID_URL = r'^(?:https?://)?(?:www\.)?(?P<url>extremetube\.com/.*?video/.+?(?P<videoid>[0-9]+))(?:[/?&]|$)'
15 _TESTS = [{
16 'url': 'http://www.extremetube.com/video/music-video-14-british-euro-brit-european-cumshots-swallow-652431',
17 'md5': '1fb9228f5e3332ec8c057d6ac36f33e0',
18 'info_dict': {
19 'id': '652431',
20 'ext': 'mp4',
21 'title': 'Music Video 14 british euro brit european cumshots swallow',
22 'uploader': 'unknown',
23 'age_limit': 18,
24 }
25 }, {
26 'url': 'http://www.extremetube.com/gay/video/abcde-1234',
27 'only_matching': True,
28 }]
29
30 def _real_extract(self, url):
31 mobj = re.match(self._VALID_URL, url)
32 video_id = mobj.group('videoid')
33 url = 'http://www.' + mobj.group('url')
34
35 req = compat_urllib_request.Request(url)
36 req.add_header('Cookie', 'age_verified=1')
37 webpage = self._download_webpage(req, video_id)
38
39 video_title = self._html_search_regex(
40 r'<h1 [^>]*?title="([^"]+)"[^>]*>', webpage, 'title')
41 uploader = self._html_search_regex(
42 r'>Posted by:(?=<)(?:\s|<[^>]*>)*(.+?)\|', webpage, 'uploader',
43 fatal=False)
44 video_url = compat_urllib_parse.unquote(self._html_search_regex(
45 r'video_url=(.+?)&amp;', webpage, 'video_url'))
46 path = compat_urllib_parse_urlparse(video_url).path
47 format = path.split('/')[5].split('_')[:2]
48 format = "-".join(format)
49
50 return {
51 'id': video_id,
52 'title': video_title,
53 'uploader': uploader,
54 'url': video_url,
55 'format': format,
56 'format_id': format,
57 'age_limit': 18,
58 }