]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/extremetube.py
c5677c82b8306293d51862e0be514da7ed4433c6
[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 compat_urllib_request
7 from ..utils import (
8 int_or_none,
9 str_to_int,
10 )
11
12
13 class ExtremeTubeIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?extremetube\.com/(?:[^/]+/)?video/(?P<id>[^/#?&]+)'
15 _TESTS = [{
16 'url': 'http://www.extremetube.com/video/music-video-14-british-euro-brit-european-cumshots-swallow-652431',
17 'md5': '344d0c6d50e2f16b06e49ca011d8ac69',
18 'info_dict': {
19 'id': 'music-video-14-british-euro-brit-european-cumshots-swallow-652431',
20 'ext': 'mp4',
21 'title': 'Music Video 14 british euro brit european cumshots swallow',
22 'uploader': 'unknown',
23 'view_count': int,
24 'age_limit': 18,
25 }
26 }, {
27 'url': 'http://www.extremetube.com/gay/video/abcde-1234',
28 'only_matching': True,
29 }, {
30 'url': 'http://www.extremetube.com/video/latina-slut-fucked-by-fat-black-dick',
31 'only_matching': True,
32 }, {
33 'url': 'http://www.extremetube.com/video/652431',
34 'only_matching': True,
35 }]
36
37 def _real_extract(self, url):
38 video_id = self._match_id(url)
39
40 req = compat_urllib_request.Request(url)
41 req.add_header('Cookie', 'age_verified=1')
42 webpage = self._download_webpage(req, video_id)
43
44 video_title = self._html_search_regex(
45 r'<h1 [^>]*?title="([^"]+)"[^>]*>', webpage, 'title')
46 uploader = self._html_search_regex(
47 r'Uploaded by:\s*</strong>\s*(.+?)\s*</div>',
48 webpage, 'uploader', fatal=False)
49 view_count = str_to_int(self._html_search_regex(
50 r'Views:\s*</strong>\s*<span>([\d,\.]+)</span>',
51 webpage, 'view count', fatal=False))
52
53 flash_vars = self._parse_json(
54 self._search_regex(
55 r'var\s+flashvars\s*=\s*({.+?});', webpage, 'flash vars'),
56 video_id)
57
58 formats = []
59 for quality_key, video_url in flash_vars.items():
60 height = int_or_none(self._search_regex(
61 r'quality_(\d+)[pP]$', quality_key, 'height', default=None))
62 if not height:
63 continue
64 f = {
65 'url': video_url,
66 }
67 mobj = re.search(
68 r'/(?P<height>\d{3,4})[pP]_(?P<bitrate>\d+)[kK]_\d+', video_url)
69 if mobj:
70 height = int(mobj.group('height'))
71 bitrate = int(mobj.group('bitrate'))
72 f.update({
73 'format_id': '%dp-%dk' % (height, bitrate),
74 'height': height,
75 'tbr': bitrate,
76 })
77 else:
78 f.update({
79 'format_id': '%dp' % height,
80 'height': height,
81 })
82 formats.append(f)
83 self._sort_formats(formats)
84
85 return {
86 'id': video_id,
87 'title': video_title,
88 'formats': formats,
89 'uploader': uploader,
90 'view_count': view_count,
91 'age_limit': 18,
92 }