]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/keezmovies.py
[ie/box] Fix formats extraction (#8649)
[yt-dlp.git] / yt_dlp / extractor / keezmovies.py
CommitLineData
5b11143d 1import re
2
3from .common import InfoExtractor
8652770b 4from ..aes import aes_decrypt_text
3052a30d 5from ..compat import compat_urllib_parse_unquote
db9bd526 6from ..utils import (
8652770b 7 determine_ext,
e0ddbd02 8 format_field,
8652770b
S
9 int_or_none,
10 str_to_int,
11 strip_or_none,
3052a30d 12 url_or_none,
db9bd526 13)
5b11143d 14
43df5a7e 15
5b11143d 16class KeezMoviesIE(InfoExtractor):
8652770b
S
17 _VALID_URL = r'https?://(?:www\.)?keezmovies\.com/video/(?:(?P<display_id>[^/]+)-)?(?P<id>\d+)'
18 _TESTS = [{
1792bc3a
PV
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',
43df5a7e 21 'info_dict': {
1792bc3a
PV
22 'id': '18070681',
23 'display_id': 'arab-wife-want-it-so-bad-i-see-she-thirsty-and-has-tiny-money',
9f281cac 24 'ext': 'mp4',
1792bc3a
PV
25 'title': 'Arab wife want it so bad I see she thirsty and has tiny money.',
26 'thumbnail': None,
8652770b
S
27 'view_count': int,
28 'age_limit': 18,
5b11143d 29 }
8652770b 30 }, {
1792bc3a 31 'url': 'http://www.keezmovies.com/video/18070681',
8652770b
S
32 'only_matching': True,
33 }]
5b11143d 34
1792bc3a 35 def _extract_info(self, url, fatal=True):
5ad28e7f 36 mobj = self._match_valid_url(url)
8652770b 37 video_id = mobj.group('id')
e15ad9ef
S
38 display_id = (mobj.group('display_id')
39 if 'display_id' in mobj.groupdict()
40 else None) or mobj.group('id')
5b11143d 41
8652770b
S
42 webpage = self._download_webpage(
43 url, display_id, headers={'Cookie': 'age_verified=1'})
5b11143d 44
8652770b
S
45 formats = []
46 format_urls = set()
5b11143d 47
8652770b
S
48 title = None
49 thumbnail = None
50 duration = None
51 encrypted = False
db9bd526 52
8652770b 53 def extract_format(format_url, height=None):
3052a30d
S
54 format_url = url_or_none(format_url)
55 if not format_url or not format_url.startswith(('http', '//')):
8652770b
S
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,
a70635b8 70 'format_id': format_field(height, None, '%dp'),
8652770b
S
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:
b7da73eb 102 self.raise_no_formats(
8652770b
S
103 'Video %s is no longer available' % video_id, expected=True)
104
8652770b
S
105 if not title:
106 title = self._html_search_regex(
107 r'<h1[^>]*>([^<]+)', webpage, 'title')
108
109 return webpage, {
5b11143d 110 'id': video_id,
8652770b
S
111 'display_id': display_id,
112 'title': strip_or_none(title),
113 'thumbnail': thumbnail,
114 'duration': duration,
115 'age_limit': 18,
db9bd526 116 'formats': formats,
5b11143d 117 }
8652770b
S
118
119 def _real_extract(self, url):
1792bc3a
PV
120 webpage, info = self._extract_info(url, fatal=False)
121 if not info['formats']:
122 return self.url_result(url, 'Generic')
8652770b
S
123 info['view_count'] = str_to_int(self._search_regex(
124 r'<b>([\d,.]+)</b> Views?', webpage, 'view count', fatal=False))
125 return info