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