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