]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/extremetube.py
Annotate changelog with (some) bugs closed.
[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_parse_qs,
8 compat_urllib_request,
9 )
10 from ..utils import (
11 qualities,
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': '344d0c6d50e2f16b06e49ca011d8ac69',
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 flash_vars = compat_parse_qs(self._search_regex(
53 r'<param[^>]+?name="flashvars"[^>]+?value="([^"]+)"', webpage, 'flash vars'))
54
55 formats = []
56 quality = qualities(['180p', '240p', '360p', '480p', '720p', '1080p'])
57 for k, vals in flash_vars.items():
58 m = re.match(r'quality_(?P<quality>[0-9]+p)$', k)
59 if m is not None:
60 formats.append({
61 'format_id': m.group('quality'),
62 'quality': quality(m.group('quality')),
63 'url': vals[0],
64 })
65
66 self._sort_formats(formats)
67
68 return {
69 'id': video_id,
70 'title': video_title,
71 'formats': formats,
72 'uploader': uploader,
73 'view_count': view_count,
74 'age_limit': 18,
75 }