spankbang.py 7.1 KB

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