]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/daftsex.py
[LnkIE] Add extractor (#2408)
[yt-dlp.git] / yt_dlp / extractor / daftsex.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..compat import compat_b64decode
6 from ..utils import (
7 get_elements_by_class,
8 int_or_none,
9 js_to_json,
10 parse_count,
11 parse_duration,
12 try_get,
13 )
14
15
16 class DaftsexIE(InfoExtractor):
17 _VALID_URL = r'https?://(?:www\.)?daftsex\.com/watch/(?P<id>-?\d+_\d+)'
18 _TESTS = [{
19 'url': 'https://daftsex.com/watch/-156601359_456242791',
20 'info_dict': {
21 'id': '-156601359_456242791',
22 'ext': 'mp4',
23 'title': 'Skye Blue - Dinner And A Show',
24 },
25 }]
26
27 def _real_extract(self, url):
28 video_id = self._match_id(url)
29 webpage = self._download_webpage(url, video_id)
30 title = get_elements_by_class('heading', webpage)[-1]
31 duration = parse_duration(self._search_regex(
32 r'Duration: ((?:[0-9]{2}:){0,2}[0-9]{2})',
33 webpage, 'duration', fatal=False))
34 views = parse_count(self._search_regex(
35 r'Views: ([0-9 ]+)',
36 webpage, 'views', fatal=False))
37
38 player_hash = self._search_regex(
39 r'DaxabPlayer\.Init\({[\s\S]*hash:\s*"([0-9a-zA-Z_\-]+)"[\s\S]*}',
40 webpage, 'player hash')
41 player_color = self._search_regex(
42 r'DaxabPlayer\.Init\({[\s\S]*color:\s*"([0-9a-z]+)"[\s\S]*}',
43 webpage, 'player color', fatal=False) or ''
44
45 embed_page = self._download_webpage(
46 'https://daxab.com/player/%s?color=%s' % (player_hash, player_color),
47 video_id, headers={'Referer': url})
48 video_params = self._parse_json(
49 self._search_regex(
50 r'window\.globParams\s*=\s*({[\S\s]+})\s*;\s*<\/script>',
51 embed_page, 'video parameters'),
52 video_id, transform_source=js_to_json)
53
54 server_domain = 'https://%s' % compat_b64decode(video_params['server'][::-1]).decode('utf-8')
55 formats = []
56 for format_id, format_data in video_params['video']['cdn_files'].items():
57 ext, height = format_id.split('_')
58 extra_quality_data = format_data.split('.')[-1]
59 url = f'{server_domain}/videos/{video_id.replace("_", "/")}/{height}.mp4?extra={extra_quality_data}'
60 formats.append({
61 'format_id': format_id,
62 'url': url,
63 'height': int_or_none(height),
64 'ext': ext,
65 })
66 self._sort_formats(formats)
67
68 thumbnail = try_get(video_params,
69 lambda vi: 'https:' + compat_b64decode(vi['video']['thumb']).decode('utf-8'))
70
71 return {
72 'id': video_id,
73 'title': title,
74 'formats': formats,
75 'duration': duration,
76 'thumbnail': thumbnail,
77 'view_count': views,
78 'age_limit': 18,
79 }