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