]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/daftsex.py
[youtube] Add extractor-arg to skip auto-translated subs
[yt-dlp.git] / yt_dlp / extractor / daftsex.py
CommitLineData
4a77fb1d 1# coding: utf-8
2from __future__ import unicode_literals
3
4from .common import InfoExtractor
5from ..compat import compat_b64decode
6from ..utils import (
4a77fb1d 7 int_or_none,
8 js_to_json,
9 parse_count,
10 parse_duration,
497a6c5f 11 traverse_obj,
4a77fb1d 12 try_get,
497a6c5f 13 unified_timestamp,
4a77fb1d 14)
15
16
17class DaftsexIE(InfoExtractor):
18 _VALID_URL = r'https?://(?:www\.)?daftsex\.com/watch/(?P<id>-?\d+_\d+)'
19 _TESTS = [{
497a6c5f
S
20 'url': 'https://daftsex.com/watch/-35370899_456246186',
21 'md5': 'd95135e6cea2d905bea20dbe82cda64a',
22 'info_dict': {
23 'id': '-35370899_456246186',
24 'ext': 'mp4',
25 'title': 'just relaxing',
26 'description': 'just relaxing - Watch video Watch video in high quality',
27 'upload_date': '20201113',
28 'timestamp': 1605261911,
29 'thumbnail': r're:https://[^/]+/impf/-43BuMDIawmBGr3GLcZ93CYwWf2PBv_tVWoS1A/dnu41DnARU4\.jpg\?size=800x450&quality=96&keep_aspect_ratio=1&background=000000&sign=6af2c26ff4a45e55334189301c867384&type=video_thumb',
30 },
31 }, {
4a77fb1d 32 'url': 'https://daftsex.com/watch/-156601359_456242791',
33 'info_dict': {
34 'id': '-156601359_456242791',
35 'ext': 'mp4',
36 'title': 'Skye Blue - Dinner And A Show',
497a6c5f
S
37 'description': 'Skye Blue - Dinner And A Show - Watch video Watch video in high quality',
38 'upload_date': '20200916',
39 'timestamp': 1600250735,
40 'thumbnail': 'https://psv153-1.crazycloud.ru/videos/-156601359/456242791/thumb.jpg?extra=i3D32KaBbBFf9TqDRMAVmQ',
4a77fb1d 41 },
42 }]
43
44 def _real_extract(self, url):
45 video_id = self._match_id(url)
46 webpage = self._download_webpage(url, video_id)
497a6c5f
S
47 title = self._html_search_meta('name', webpage, 'title')
48 timestamp = unified_timestamp(self._html_search_meta('uploadDate', webpage, 'Upload Date', default=None))
49 description = self._html_search_meta('description', webpage, 'Description', default=None)
50
4a77fb1d 51 duration = parse_duration(self._search_regex(
52 r'Duration: ((?:[0-9]{2}:){0,2}[0-9]{2})',
53 webpage, 'duration', fatal=False))
54 views = parse_count(self._search_regex(
55 r'Views: ([0-9 ]+)',
56 webpage, 'views', fatal=False))
57
58 player_hash = self._search_regex(
59 r'DaxabPlayer\.Init\({[\s\S]*hash:\s*"([0-9a-zA-Z_\-]+)"[\s\S]*}',
60 webpage, 'player hash')
61 player_color = self._search_regex(
62 r'DaxabPlayer\.Init\({[\s\S]*color:\s*"([0-9a-z]+)"[\s\S]*}',
63 webpage, 'player color', fatal=False) or ''
64
65 embed_page = self._download_webpage(
66 'https://daxab.com/player/%s?color=%s' % (player_hash, player_color),
67 video_id, headers={'Referer': url})
68 video_params = self._parse_json(
69 self._search_regex(
70 r'window\.globParams\s*=\s*({[\S\s]+})\s*;\s*<\/script>',
71 embed_page, 'video parameters'),
72 video_id, transform_source=js_to_json)
73
74 server_domain = 'https://%s' % compat_b64decode(video_params['server'][::-1]).decode('utf-8')
497a6c5f
S
75
76 cdn_files = traverse_obj(video_params, ('video', 'cdn_files')) or {}
77 if cdn_files:
78 formats = []
79 for format_id, format_data in cdn_files.items():
80 ext, height = format_id.split('_')
81 formats.append({
82 'format_id': format_id,
83 'url': f'{server_domain}/videos/{video_id.replace("_", "/")}/{height}.mp4?extra={format_data.split(".")[-1]}',
84 'height': int_or_none(height),
85 'ext': ext,
86 })
87 self._sort_formats(formats)
88
89 return {
90 'id': video_id,
91 'title': title,
92 'formats': formats,
93 'description': description,
94 'duration': duration,
95 'thumbnail': try_get(video_params, lambda vi: 'https:' + compat_b64decode(vi['video']['thumb']).decode('utf-8')),
96 'timestamp': timestamp,
97 'view_count': views,
98 'age_limit': 18,
99 }
100
101 item = self._download_json(
102 f'{server_domain}/method/video.get/{video_id}', video_id,
103 headers={'Referer': url}, query={
104 'token': video_params['video']['access_token'],
105 'videos': video_id,
106 'ckey': video_params['c_key'],
107 'credentials': video_params['video']['credentials'],
108 })['response']['items'][0]
109
4a77fb1d 110 formats = []
497a6c5f
S
111 for f_id, f_url in item.get('files', {}).items():
112 if f_id == 'external':
113 return self.url_result(f_url)
114 ext, height = f_id.split('_')
115 height_extra_key = traverse_obj(video_params, ('video', 'partial', 'quality', height))
116 if height_extra_key:
117 formats.append({
118 'format_id': f'{height}p',
119 'url': f'{server_domain}/{f_url[8:]}&videos={video_id}&extra_key={height_extra_key}',
120 'height': int_or_none(height),
121 'ext': ext,
122 })
4a77fb1d 123 self._sort_formats(formats)
124
497a6c5f
S
125 thumbnails = []
126 for k, v in item.items():
127 if k.startswith('photo_') and v:
128 width = k.replace('photo_', '')
129 thumbnails.append({
130 'id': width,
131 'url': v,
132 'width': int_or_none(width),
133 })
4a77fb1d 134
135 return {
136 'id': video_id,
137 'title': title,
138 'formats': formats,
497a6c5f
S
139 'comment_count': int_or_none(item.get('comments')),
140 'description': description,
4a77fb1d 141 'duration': duration,
497a6c5f
S
142 'thumbnails': thumbnails,
143 'timestamp': timestamp,
4a77fb1d 144 'view_count': views,
145 'age_limit': 18,
146 }