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