Release 2024.12.06
[yt-dlp3.git] / yt_dlp / extractor / spankbang.py
blob05f0bb1468ed6905ff17c3256e43946810180f2d
1 import re
3 from .common import InfoExtractor
4 from ..utils import (
5 ExtractorError,
6 determine_ext,
7 merge_dicts,
8 parse_duration,
9 parse_resolution,
10 str_to_int,
11 url_or_none,
12 urlencode_postdata,
13 urljoin,
17 class SpankBangIE(InfoExtractor):
18 _VALID_URL = r'''(?x)
19 https?://
20 (?:[^/]+\.)?spankbang\.com/
21 (?:
22 (?P<id>[\da-z]+)/(?:video|play|embed)\b|
23 [\da-z]+-(?P<id_2>[\da-z]+)/playlist/[^/?#&]+
25 '''
26 _TESTS = [{
27 'url': 'https://spankbang.com/56b3d/video/the+slut+maker+hmv',
28 'md5': '2D13903DE4ECC7895B5D55930741650A',
29 'info_dict': {
30 'id': '56b3d',
31 'ext': 'mp4',
32 'title': 'The Slut Maker HMV',
33 'description': 'Girls getting converted into cock slaves.',
34 'thumbnail': r're:^https?://.*\.jpg$',
35 'uploader': 'Mindself',
36 'uploader_id': 'mindself',
37 'timestamp': 1617109572,
38 'upload_date': '20210330',
39 'age_limit': 18,
41 }, {
42 # 480p only
43 'url': 'http://spankbang.com/1vt0/video/solvane+gangbang',
44 'only_matching': True,
45 }, {
46 # no uploader
47 'url': 'http://spankbang.com/lklg/video/sex+with+anyone+wedding+edition+2',
48 'only_matching': True,
49 }, {
50 # mobile page
51 'url': 'http://m.spankbang.com/1o2de/video/can+t+remember+her+name',
52 'only_matching': True,
53 }, {
54 # 4k
55 'url': 'https://spankbang.com/1vwqx/video/jade+kush+solo+4k',
56 'only_matching': True,
57 }, {
58 'url': 'https://m.spankbang.com/3vvn/play/fantasy+solo/480p/',
59 'only_matching': True,
60 }, {
61 'url': 'https://m.spankbang.com/3vvn/play',
62 'only_matching': True,
63 }, {
64 'url': 'https://spankbang.com/2y3td/embed/',
65 'only_matching': True,
66 }, {
67 'url': 'https://spankbang.com/2v7ik-7ecbgu/playlist/latina+booty',
68 'only_matching': True,
71 def _real_extract(self, url):
72 mobj = self._match_valid_url(url)
73 video_id = mobj.group('id') or mobj.group('id_2')
74 country = self.get_param('geo_bypass_country') or 'US'
75 self._set_cookie('.spankbang.com', 'country', country.upper())
76 webpage = self._download_webpage(
77 url.replace(f'/{video_id}/embed', f'/{video_id}/video'),
78 video_id, impersonate=True)
80 if re.search(r'<[^>]+\b(?:id|class)=["\']video_removed', webpage):
81 raise ExtractorError(
82 f'Video {video_id} is not available', expected=True)
84 formats = []
86 def extract_format(format_id, format_url):
87 f_url = url_or_none(format_url)
88 if not f_url:
89 return
90 f = parse_resolution(format_id)
91 ext = determine_ext(f_url)
92 if format_id.startswith('m3u8') or ext == 'm3u8':
93 formats.extend(self._extract_m3u8_formats(
94 f_url, video_id, 'mp4', entry_protocol='m3u8_native',
95 m3u8_id='hls', fatal=False))
96 elif format_id.startswith('mpd') or ext == 'mpd':
97 formats.extend(self._extract_mpd_formats(
98 f_url, video_id, mpd_id='dash', fatal=False))
99 elif ext == 'mp4' or f.get('width') or f.get('height'):
100 f.update({
101 'url': f_url,
102 'format_id': format_id,
104 formats.append(f)
106 STREAM_URL_PREFIX = 'stream_url_'
108 for mobj in re.finditer(
109 rf'{STREAM_URL_PREFIX}(?P<id>[^\s=]+)\s*=\s*(["\'])(?P<url>(?:(?!\2).)+)\2', webpage):
110 extract_format(mobj.group('id', 'url'))
112 if not formats:
113 stream_key = self._search_regex(
114 r'data-streamkey\s*=\s*(["\'])(?P<value>(?:(?!\1).)+)\1',
115 webpage, 'stream key', group='value')
117 stream = self._download_json(
118 'https://spankbang.com/api/videos/stream', video_id,
119 'Downloading stream JSON', data=urlencode_postdata({
120 'id': stream_key,
121 'data': 0,
122 }), headers={
123 'Referer': url,
124 'X-Requested-With': 'XMLHttpRequest',
127 for format_id, format_url in stream.items():
128 if format_url and isinstance(format_url, list):
129 format_url = format_url[0]
130 extract_format(format_id, format_url)
132 info = self._search_json_ld(webpage, video_id, default={})
134 title = self._html_search_regex(
135 r'(?s)<h1[^>]+\btitle=["\']([^"]+)["\']>', webpage, 'title', default=None)
136 description = self._search_regex(
137 r'<div[^>]+\bclass=["\']bottom[^>]+>\s*<p>[^<]*</p>\s*<p>([^<]+)',
138 webpage, 'description', default=None)
139 thumbnail = self._og_search_thumbnail(webpage, default=None)
140 uploader = self._html_search_regex(
141 r'<svg[^>]+\bclass="(?:[^"]*?user[^"]*?)">.*?</svg>([^<]+)', webpage, 'uploader', default=None)
142 uploader_id = self._html_search_regex(
143 r'<a[^>]+href="/profile/([^"]+)"', webpage, 'uploader_id', default=None)
144 duration = parse_duration(self._search_regex(
145 r'<div[^>]+\bclass=["\']right_side[^>]+>\s*<span>([^<]+)',
146 webpage, 'duration', default=None))
147 view_count = str_to_int(self._search_regex(
148 r'([\d,.]+)\s+plays', webpage, 'view count', default=None))
150 age_limit = self._rta_search(webpage)
152 return merge_dicts({
153 'id': video_id,
154 'title': title or video_id,
155 'description': description,
156 'thumbnail': thumbnail,
157 'uploader': uploader,
158 'uploader_id': uploader_id,
159 'duration': duration,
160 'view_count': view_count,
161 'formats': formats,
162 'age_limit': age_limit,
163 }, info,
167 class SpankBangPlaylistIE(InfoExtractor):
168 _VALID_URL = r'https?://(?:[^/]+\.)?spankbang\.com/(?P<id>[\da-z]+)/playlist/(?P<display_id>[^/]+)'
169 _TEST = {
170 'url': 'https://spankbang.com/ug0k/playlist/big+ass+titties',
171 'info_dict': {
172 'id': 'ug0k',
173 'title': 'Big Ass Titties',
175 'playlist_mincount': 40,
178 def _real_extract(self, url):
179 mobj = self._match_valid_url(url)
180 playlist_id = mobj.group('id')
182 webpage = self._download_webpage(
183 url, playlist_id, headers={'Cookie': 'country=US; mobile=on'})
185 entries = [self.url_result(
186 urljoin(url, mobj.group('path')),
187 ie=SpankBangIE.ie_key(), video_id=mobj.group('id'))
188 for mobj in re.finditer(
189 r'<a[^>]+\bhref=(["\'])(?P<path>/?[\da-z]+-(?P<id>[\da-z]+)/playlist/[^"\'](?:(?!\1).)*)\1',
190 webpage)]
192 title = self._html_search_regex(
193 r'<em>([^<]+)</em>\s+playlist\s*<', webpage, 'playlist title',
194 fatal=False)
196 return self.playlist_result(entries, playlist_id, title)