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.

171 lines
5.7 KiB

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