23d5209d997c1866af408a898a511d0b5f0a92f7
[youtube-dl] / 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     unescapeHTML,
10 )
11 from ..aes import (
12     aes_decrypt_text
13 )
14
15 class KeezMoviesIE(InfoExtractor):
16     _VALID_URL = r'^(?:https?://)?(?:www\.)?(?P<url>keezmovies\.com/video/.+?(?P<videoid>[0-9]+))'
17     _TEST = {
18         u'url': u'http://www.keezmovies.com/video/petite-asian-lady-mai-playing-in-bathtub-1214711',
19         u'file': u'1214711.mp4',
20         u'md5': u'6e297b7e789329923fcf83abb67c9289',
21         u'info_dict': {
22             u"title": u"Petite Asian Lady Mai Playing In Bathtub",
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         return {
52             'id': video_id,
53             'title': video_title,
54             'url': video_url,
55             'ext': extension,
56             'format': format,
57             'format_id': format,
58         }