]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/keezmovies.py
Imported Upstream version 2013.11.11
[youtubedl] / youtube_dl / extractor / keezmovies.py
1 import os
2 import re
3
4 from .common import InfoExtractor
5 from ..utils import (
6 compat_urllib_parse_urlparse,
7 compat_urllib_request,
8 compat_urllib_parse,
9 )
10 from ..aes import (
11 aes_decrypt_text
12 )
13
14 class KeezMoviesIE(InfoExtractor):
15 _VALID_URL = r'^(?:https?://)?(?:www\.)?(?P<url>keezmovies\.com/video/.+?(?P<videoid>[0-9]+))(?:[/?&]|$)'
16 _TEST = {
17 u'url': u'http://www.keezmovies.com/video/petite-asian-lady-mai-playing-in-bathtub-1214711',
18 u'file': u'1214711.mp4',
19 u'md5': u'6e297b7e789329923fcf83abb67c9289',
20 u'info_dict': {
21 u"title": u"Petite Asian Lady Mai Playing In Bathtub",
22 u"age_limit": 18,
23 }
24 }
25
26 def _real_extract(self, url):
27 mobj = re.match(self._VALID_URL, url)
28 video_id = mobj.group('videoid')
29 url = 'http://www.' + mobj.group('url')
30
31 req = compat_urllib_request.Request(url)
32 req.add_header('Cookie', 'age_verified=1')
33 webpage = self._download_webpage(req, video_id)
34
35 # embedded video
36 mobj = re.search(r'href="([^"]+)"></iframe>', webpage)
37 if mobj:
38 embedded_url = mobj.group(1)
39 return self.url_result(embedded_url)
40
41 video_title = self._html_search_regex(r'<h1 [^>]*>([^<]+)', webpage, u'title')
42 video_url = compat_urllib_parse.unquote(self._html_search_regex(r'video_url=(.+?)&amp;', webpage, u'video_url'))
43 if webpage.find('encrypted=true')!=-1:
44 password = self._html_search_regex(r'video_title=(.+?)&amp;', webpage, u'password')
45 video_url = aes_decrypt_text(video_url, password, 32).decode('utf-8')
46 path = compat_urllib_parse_urlparse(video_url).path
47 extension = os.path.splitext(path)[1][1:]
48 format = path.split('/')[4].split('_')[:2]
49 format = "-".join(format)
50
51 age_limit = self._rta_search(webpage)
52
53 return {
54 'id': video_id,
55 'title': video_title,
56 'url': video_url,
57 'ext': extension,
58 'format': format,
59 'format_id': format,
60 'age_limit': age_limit,
61 }