]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/keezmovies.py
b50da420cbe15d4f7acc90f5c0a3f3eb163c5107
[yt-dlp.git] / yt_dlp / extractor / keezmovies.py
1 import re
2
3 from .common import InfoExtractor
4 from ..aes import aes_decrypt_text
5 from ..compat import compat_urllib_parse_unquote
6 from ..utils import (
7 determine_ext,
8 format_field,
9 int_or_none,
10 str_to_int,
11 strip_or_none,
12 url_or_none,
13 )
14
15
16 class KeezMoviesIE(InfoExtractor):
17 _VALID_URL = r'https?://(?:www\.)?keezmovies\.com/video/(?:(?P<display_id>[^/]+)-)?(?P<id>\d+)'
18 _TESTS = [{
19 'url': 'https://www.keezmovies.com/video/arab-wife-want-it-so-bad-i-see-she-thirsty-and-has-tiny-money-18070681',
20 'md5': '2ac69cdb882055f71d82db4311732a1a',
21 'info_dict': {
22 'id': '18070681',
23 'display_id': 'arab-wife-want-it-so-bad-i-see-she-thirsty-and-has-tiny-money',
24 'ext': 'mp4',
25 'title': 'Arab wife want it so bad I see she thirsty and has tiny money.',
26 'thumbnail': None,
27 'view_count': int,
28 'age_limit': 18,
29 }
30 }, {
31 'url': 'http://www.keezmovies.com/video/18070681',
32 'only_matching': True,
33 }]
34
35 def _extract_info(self, url, fatal=True):
36 mobj = self._match_valid_url(url)
37 video_id = mobj.group('id')
38 display_id = (mobj.group('display_id')
39 if 'display_id' in mobj.groupdict()
40 else None) or mobj.group('id')
41
42 webpage = self._download_webpage(
43 url, display_id, headers={'Cookie': 'age_verified=1'})
44
45 formats = []
46 format_urls = set()
47
48 title = None
49 thumbnail = None
50 duration = None
51 encrypted = False
52
53 def extract_format(format_url, height=None):
54 format_url = url_or_none(format_url)
55 if not format_url or not format_url.startswith(('http', '//')):
56 return
57 if format_url in format_urls:
58 return
59 format_urls.add(format_url)
60 tbr = int_or_none(self._search_regex(
61 r'[/_](\d+)[kK][/_]', format_url, 'tbr', default=None))
62 if not height:
63 height = int_or_none(self._search_regex(
64 r'[/_](\d+)[pP][/_]', format_url, 'height', default=None))
65 if encrypted:
66 format_url = aes_decrypt_text(
67 video_url, title, 32).decode('utf-8')
68 formats.append({
69 'url': format_url,
70 'format_id': format_field(height, None, '%dp'),
71 'height': height,
72 'tbr': tbr,
73 })
74
75 flashvars = self._parse_json(
76 self._search_regex(
77 r'flashvars\s*=\s*({.+?});', webpage,
78 'flashvars', default='{}'),
79 display_id, fatal=False)
80
81 if flashvars:
82 title = flashvars.get('video_title')
83 thumbnail = flashvars.get('image_url')
84 duration = int_or_none(flashvars.get('video_duration'))
85 encrypted = flashvars.get('encrypted') is True
86 for key, value in flashvars.items():
87 mobj = re.search(r'quality_(\d+)[pP]', key)
88 if mobj:
89 extract_format(value, int(mobj.group(1)))
90 video_url = flashvars.get('video_url')
91 if video_url and determine_ext(video_url, None):
92 extract_format(video_url)
93
94 video_url = self._html_search_regex(
95 r'flashvars\.video_url\s*=\s*(["\'])(?P<url>http.+?)\1',
96 webpage, 'video url', default=None, group='url')
97 if video_url:
98 extract_format(compat_urllib_parse_unquote(video_url))
99
100 if not formats:
101 if 'title="This video is no longer available"' in webpage:
102 self.raise_no_formats(
103 'Video %s is no longer available' % video_id, expected=True)
104
105 if not title:
106 title = self._html_search_regex(
107 r'<h1[^>]*>([^<]+)', webpage, 'title')
108
109 return webpage, {
110 'id': video_id,
111 'display_id': display_id,
112 'title': strip_or_none(title),
113 'thumbnail': thumbnail,
114 'duration': duration,
115 'age_limit': 18,
116 'formats': formats,
117 }
118
119 def _real_extract(self, url):
120 webpage, info = self._extract_info(url, fatal=False)
121 if not info['formats']:
122 return self.url_result(url, 'Generic')
123 info['view_count'] = str_to_int(self._search_regex(
124 r'<b>([\d,.]+)</b> Views?', webpage, 'view count', fatal=False))
125 return info