]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/spankbang.py
Annotate changelog with bug being closed.
[youtubedl] / youtube_dl / extractor / spankbang.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7 ExtractorError,
8 orderedSet,
9 parse_duration,
10 parse_resolution,
11 str_to_int,
12 url_or_none,
13 urlencode_postdata,
14 )
15
16
17 class SpankBangIE(InfoExtractor):
18 _VALID_URL = r'https?://(?:[^/]+\.)?spankbang\.com/(?P<id>[\da-z]+)/(?:video|play|embed)\b'
19 _TESTS = [{
20 'url': 'http://spankbang.com/3vvn/video/fantasy+solo',
21 'md5': '1cc433e1d6aa14bc376535b8679302f7',
22 'info_dict': {
23 'id': '3vvn',
24 'ext': 'mp4',
25 'title': 'fantasy solo',
26 'description': 'dillion harper masturbates on a bed',
27 'thumbnail': r're:^https?://.*\.jpg$',
28 'uploader': 'silly2587',
29 'age_limit': 18,
30 }
31 }, {
32 # 480p only
33 'url': 'http://spankbang.com/1vt0/video/solvane+gangbang',
34 'only_matching': True,
35 }, {
36 # no uploader
37 'url': 'http://spankbang.com/lklg/video/sex+with+anyone+wedding+edition+2',
38 'only_matching': True,
39 }, {
40 # mobile page
41 'url': 'http://m.spankbang.com/1o2de/video/can+t+remember+her+name',
42 'only_matching': True,
43 }, {
44 # 4k
45 'url': 'https://spankbang.com/1vwqx/video/jade+kush+solo+4k',
46 'only_matching': True,
47 }, {
48 'url': 'https://m.spankbang.com/3vvn/play/fantasy+solo/480p/',
49 'only_matching': True,
50 }, {
51 'url': 'https://m.spankbang.com/3vvn/play',
52 'only_matching': True,
53 }, {
54 'url': 'https://spankbang.com/2y3td/embed/',
55 'only_matching': True,
56 }]
57
58 def _real_extract(self, url):
59 video_id = self._match_id(url)
60 webpage = self._download_webpage(
61 url.replace('/%s/embed' % video_id, '/%s/video' % video_id),
62 video_id, headers={'Cookie': 'country=US'})
63
64 if re.search(r'<[^>]+\bid=["\']video_removed', webpage):
65 raise ExtractorError(
66 'Video %s is not available' % video_id, expected=True)
67
68 formats = []
69
70 def extract_format(format_id, format_url):
71 f_url = url_or_none(format_url)
72 if not f_url:
73 return
74 f = parse_resolution(format_id)
75 f.update({
76 'url': f_url,
77 'format_id': format_id,
78 })
79 formats.append(f)
80
81 STREAM_URL_PREFIX = 'stream_url_'
82
83 for mobj in re.finditer(
84 r'%s(?P<id>[^\s=]+)\s*=\s*(["\'])(?P<url>(?:(?!\2).)+)\2'
85 % STREAM_URL_PREFIX, webpage):
86 extract_format(mobj.group('id', 'url'))
87
88 if not formats:
89 stream_key = self._search_regex(
90 r'data-streamkey\s*=\s*(["\'])(?P<value>(?:(?!\1).)+)\1',
91 webpage, 'stream key', group='value')
92
93 sb_csrf_session = self._get_cookies(
94 'https://spankbang.com')['sb_csrf_session'].value
95
96 stream = self._download_json(
97 'https://spankbang.com/api/videos/stream', video_id,
98 'Downloading stream JSON', data=urlencode_postdata({
99 'id': stream_key,
100 'data': 0,
101 'sb_csrf_session': sb_csrf_session,
102 }), headers={
103 'Referer': url,
104 'X-CSRFToken': sb_csrf_session,
105 })
106
107 for format_id, format_url in stream.items():
108 if format_id.startswith(STREAM_URL_PREFIX):
109 extract_format(
110 format_id[len(STREAM_URL_PREFIX):], format_url)
111
112 self._sort_formats(formats)
113
114 title = self._html_search_regex(
115 r'(?s)<h1[^>]*>(.+?)</h1>', webpage, 'title')
116 description = self._search_regex(
117 r'<div[^>]+\bclass=["\']bottom[^>]+>\s*<p>[^<]*</p>\s*<p>([^<]+)',
118 webpage, 'description', fatal=False)
119 thumbnail = self._og_search_thumbnail(webpage)
120 uploader = self._search_regex(
121 r'class="user"[^>]*><img[^>]+>([^<]+)',
122 webpage, 'uploader', default=None)
123 duration = parse_duration(self._search_regex(
124 r'<div[^>]+\bclass=["\']right_side[^>]+>\s*<span>([^<]+)',
125 webpage, 'duration', fatal=False))
126 view_count = str_to_int(self._search_regex(
127 r'([\d,.]+)\s+plays', webpage, 'view count', fatal=False))
128
129 age_limit = self._rta_search(webpage)
130
131 return {
132 'id': video_id,
133 'title': title,
134 'description': description,
135 'thumbnail': thumbnail,
136 'uploader': uploader,
137 'duration': duration,
138 'view_count': view_count,
139 'formats': formats,
140 'age_limit': age_limit,
141 }
142
143
144 class SpankBangPlaylistIE(InfoExtractor):
145 _VALID_URL = r'https?://(?:[^/]+\.)?spankbang\.com/(?P<id>[\da-z]+)/playlist/[^/]+'
146 _TEST = {
147 'url': 'https://spankbang.com/ug0k/playlist/big+ass+titties',
148 'info_dict': {
149 'id': 'ug0k',
150 'title': 'Big Ass Titties',
151 },
152 'playlist_mincount': 50,
153 }
154
155 def _real_extract(self, url):
156 playlist_id = self._match_id(url)
157
158 webpage = self._download_webpage(
159 url, playlist_id, headers={'Cookie': 'country=US; mobile=on'})
160
161 entries = [self.url_result(
162 'https://spankbang.com/%s/video' % video_id,
163 ie=SpankBangIE.ie_key(), video_id=video_id)
164 for video_id in orderedSet(re.findall(
165 r'<a[^>]+\bhref=["\']/?([\da-z]+)/play/', webpage))]
166
167 title = self._html_search_regex(
168 r'<h1>([^<]+)\s+playlist</h1>', webpage, 'playlist title',
169 fatal=False)
170
171 return self.playlist_result(entries, playlist_id, title)