You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

180 lines
6.1 KiB

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