]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/sexu.py
[cleanup] Upgrade syntax
[yt-dlp.git] / yt_dlp / extractor / sexu.py
CommitLineData
bbd5f2de 1from .common import InfoExtractor
2
3
4class SexuIE(InfoExtractor):
5 _VALID_URL = r'https?://(?:www\.)?sexu\.com/(?P<id>\d+)'
6 _TEST = {
7 'url': 'http://sexu.com/961791/',
8 'md5': 'ff615aca9691053c94f8f10d96cd7884',
9 'info_dict': {
10 'id': '961791',
11 'ext': 'mp4',
437f68d8 12 'title': 'md5:4d05a19a5fc049a63dbbaf05fb71d91b',
c58e7406 13 'description': 'md5:2b75327061310a3afb3fbd7d09e2e403',
bbd5f2de 14 'categories': list, # NSFW
ec85ded8 15 'thumbnail': r're:https?://.*\.jpg$',
bbd5f2de 16 'age_limit': 18,
17 }
18 }
19
20 def _real_extract(self, url):
3fa5bb38 21 video_id = self._match_id(url)
bbd5f2de 22 webpage = self._download_webpage(url, video_id)
23
e7bd1737
S
24 jwvideo = self._parse_json(
25 self._search_regex(r'\.setup\(\s*({.+?})\s*\);', webpage, 'jwvideo'),
26 video_id)
27
28 sources = jwvideo['sources']
29
bbd5f2de 30 formats = [{
e7bd1737
S
31 'url': source['file'].replace('\\', ''),
32 'format_id': source.get('label'),
f5521ea2
S
33 'height': int(self._search_regex(
34 r'^(\d+)[pP]', source.get('label', ''), 'height',
35 default=None)),
e7bd1737 36 } for source in sources if source.get('file')]
bbd5f2de 37 self._sort_formats(formats)
38
39 title = self._html_search_regex(
3fa5bb38 40 r'<title>([^<]+)\s*-\s*Sexu\.Com</title>', webpage, 'title')
bbd5f2de 41
3fa5bb38
PH
42 description = self._html_search_meta(
43 'description', webpage, 'description')
bbd5f2de 44
e7bd1737 45 thumbnail = jwvideo.get('image')
bbd5f2de 46
3fa5bb38
PH
47 categories_str = self._html_search_meta(
48 'keywords', webpage, 'categories')
bbd5f2de 49 categories = (
50 None if categories_str is None
51 else categories_str.split(','))
52
53 return {
54 'id': video_id,
55 'title': title,
56 'description': description,
57 'thumbnail': thumbnail,
58 'categories': categories,
59 'formats': formats,
60 'age_limit': 18,
61 }