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.

184 lines
6.5 KiB

  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. )
  15. class SpankBangIE(InfoExtractor):
  16. _VALID_URL = r'https?://(?:[^/]+\.)?spankbang\.com/(?P<id>[\da-z]+)/(?:video|play|embed)\b'
  17. _TESTS = [{
  18. 'url': 'http://spankbang.com/3vvn/video/fantasy+solo',
  19. 'md5': '1cc433e1d6aa14bc376535b8679302f7',
  20. 'info_dict': {
  21. 'id': '3vvn',
  22. 'ext': 'mp4',
  23. 'title': 'fantasy solo',
  24. 'description': 'dillion harper masturbates on a bed',
  25. 'thumbnail': r're:^https?://.*\.jpg$',
  26. 'uploader': 'silly2587',
  27. 'timestamp': 1422571989,
  28. 'upload_date': '20150129',
  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. def _real_extract(self, url):
  58. video_id = self._match_id(url)
  59. webpage = self._download_webpage(
  60. url.replace('/%s/embed' % video_id, '/%s/video' % video_id),
  61. video_id, headers={'Cookie': 'country=US'})
  62. if re.search(r'<[^>]+\b(?:id|class)=["\']video_removed', webpage):
  63. raise ExtractorError(
  64. 'Video %s is not available' % video_id, expected=True)
  65. formats = []
  66. def extract_format(format_id, format_url):
  67. f_url = url_or_none(format_url)
  68. if not f_url:
  69. return
  70. f = parse_resolution(format_id)
  71. ext = determine_ext(f_url)
  72. if format_id.startswith('m3u8') or ext == 'm3u8':
  73. formats.extend(self._extract_m3u8_formats(
  74. f_url, video_id, 'mp4', entry_protocol='m3u8_native',
  75. m3u8_id='hls', fatal=False))
  76. elif format_id.startswith('mpd') or ext == 'mpd':
  77. formats.extend(self._extract_mpd_formats(
  78. f_url, video_id, mpd_id='dash', fatal=False))
  79. elif ext == 'mp4' or f.get('width') or f.get('height'):
  80. f.update({
  81. 'url': f_url,
  82. 'format_id': format_id,
  83. })
  84. formats.append(f)
  85. STREAM_URL_PREFIX = 'stream_url_'
  86. for mobj in re.finditer(
  87. r'%s(?P<id>[^\s=]+)\s*=\s*(["\'])(?P<url>(?:(?!\2).)+)\2'
  88. % STREAM_URL_PREFIX, webpage):
  89. extract_format(mobj.group('id', 'url'))
  90. if not formats:
  91. stream_key = self._search_regex(
  92. r'data-streamkey\s*=\s*(["\'])(?P<value>(?:(?!\1).)+)\1',
  93. webpage, 'stream key', group='value')
  94. stream = self._download_json(
  95. 'https://spankbang.com/api/videos/stream', video_id,
  96. 'Downloading stream JSON', data=urlencode_postdata({
  97. 'id': stream_key,
  98. 'data': 0,
  99. }), headers={
  100. 'Referer': url,
  101. 'X-Requested-With': 'XMLHttpRequest',
  102. })
  103. for format_id, format_url in stream.items():
  104. if format_url and isinstance(format_url, list):
  105. format_url = format_url[0]
  106. extract_format(format_id, format_url)
  107. self._sort_formats(formats, field_preference=('preference', 'height', 'width', 'fps', 'tbr', 'format_id'))
  108. info = self._search_json_ld(webpage, video_id, default={})
  109. title = self._html_search_regex(
  110. r'(?s)<h1[^>]*>(.+?)</h1>', webpage, 'title', default=None)
  111. description = self._search_regex(
  112. r'<div[^>]+\bclass=["\']bottom[^>]+>\s*<p>[^<]*</p>\s*<p>([^<]+)',
  113. webpage, 'description', default=None)
  114. thumbnail = self._og_search_thumbnail(webpage, default=None)
  115. uploader = self._html_search_regex(
  116. (r'(?s)<li[^>]+class=["\']profile[^>]+>(.+?)</a>',
  117. r'class="user"[^>]*><img[^>]+>([^<]+)'),
  118. webpage, 'uploader', default=None)
  119. duration = parse_duration(self._search_regex(
  120. r'<div[^>]+\bclass=["\']right_side[^>]+>\s*<span>([^<]+)',
  121. webpage, 'duration', default=None))
  122. view_count = str_to_int(self._search_regex(
  123. r'([\d,.]+)\s+plays', webpage, 'view count', default=None))
  124. age_limit = self._rta_search(webpage)
  125. return merge_dicts({
  126. 'id': video_id,
  127. 'title': title or video_id,
  128. 'description': description,
  129. 'thumbnail': thumbnail,
  130. 'uploader': uploader,
  131. 'duration': duration,
  132. 'view_count': view_count,
  133. 'formats': formats,
  134. 'age_limit': age_limit,
  135. }, info
  136. )
  137. class SpankBangPlaylistIE(InfoExtractor):
  138. _VALID_URL = r'https?://(?:[^/]+\.)?spankbang\.com/(?P<id>[\da-z]+)/playlist/[^/]+'
  139. _TEST = {
  140. 'url': 'https://spankbang.com/ug0k/playlist/big+ass+titties',
  141. 'info_dict': {
  142. 'id': 'ug0k',
  143. 'title': 'Big Ass Titties',
  144. },
  145. 'playlist_mincount': 50,
  146. }
  147. def _real_extract(self, url):
  148. playlist_id = self._match_id(url)
  149. webpage = self._download_webpage(
  150. url, playlist_id, headers={'Cookie': 'country=US; mobile=on'})
  151. entries = [self.url_result(
  152. 'https://spankbang.com/%s/video' % video_id,
  153. ie=SpankBangIE.ie_key(), video_id=video_id)
  154. for video_id in orderedSet(re.findall(
  155. r'<a[^>]+\bhref=["\']/?([\da-z]+)/play/', webpage))]
  156. title = self._html_search_regex(
  157. r'<h1>([^<]+)\s+playlist</h1>', webpage, 'playlist title',
  158. fatal=False)
  159. return self.playlist_result(entries, playlist_id, title)