spankbang.py 7.0 KB

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