]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/keezmovies.py
Prepare to upload.
[youtubedl] / youtube_dl / extractor / keezmovies.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7 sanitized_Request,
8 url_basename,
9 )
10
11
12 class KeezMoviesIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www\.)?keezmovies\.com/video/.+?(?P<id>[0-9]+)(?:[/?&]|$)'
14 _TEST = {
15 'url': 'http://www.keezmovies.com/video/petite-asian-lady-mai-playing-in-bathtub-1214711',
16 'md5': '1c1e75d22ffa53320f45eeb07bc4cdc0',
17 'info_dict': {
18 'id': '1214711',
19 'ext': 'mp4',
20 'title': 'Petite Asian Lady Mai Playing In Bathtub',
21 'age_limit': 18,
22 'thumbnail': 're:^https?://.*\.jpg$',
23 }
24 }
25
26 def _real_extract(self, url):
27 video_id = self._match_id(url)
28
29 req = sanitized_Request(url)
30 req.add_header('Cookie', 'age_verified=1')
31 webpage = self._download_webpage(req, video_id)
32
33 # embedded video
34 mobj = re.search(r'href="([^"]+)"></iframe>', webpage)
35 if mobj:
36 embedded_url = mobj.group(1)
37 return self.url_result(embedded_url)
38
39 video_title = self._html_search_regex(
40 r'<h1 [^>]*>([^<]+)', webpage, 'title')
41 flashvars = self._parse_json(self._search_regex(
42 r'var\s+flashvars\s*=\s*([^;]+);', webpage, 'flashvars'), video_id)
43
44 formats = []
45 for height in (180, 240, 480):
46 if flashvars.get('quality_%dp' % height):
47 video_url = flashvars['quality_%dp' % height]
48 a_format = {
49 'url': video_url,
50 'height': height,
51 'format_id': '%dp' % height,
52 }
53 filename_parts = url_basename(video_url).split('_')
54 if len(filename_parts) >= 2 and re.match(r'\d+[Kk]', filename_parts[1]):
55 a_format['tbr'] = int(filename_parts[1][:-1])
56 formats.append(a_format)
57
58 age_limit = self._rta_search(webpage)
59
60 return {
61 'id': video_id,
62 'title': video_title,
63 'formats': formats,
64 'age_limit': age_limit,
65 'thumbnail': flashvars.get('image_url')
66 }