logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

spankbang.py (7229B)


  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. parse_duration,
  9. parse_resolution,
  10. str_to_int,
  11. url_or_none,
  12. urlencode_postdata,
  13. urljoin,
  14. )
  15. class SpankBangIE(InfoExtractor):
  16. _VALID_URL = r'''(?x)
  17. https?://
  18. (?:[^/]+\.)?spankbang\.com/
  19. (?:
  20. (?P<id>[\da-z]+)/(?:video|play|embed)\b|
  21. [\da-z]+-(?P<id_2>[\da-z]+)/playlist/[^/?#&]+
  22. )
  23. '''
  24. _TESTS = [{
  25. 'url': 'http://spankbang.com/3vvn/video/fantasy+solo',
  26. 'md5': '1cc433e1d6aa14bc376535b8679302f7',
  27. 'info_dict': {
  28. 'id': '3vvn',
  29. 'ext': 'mp4',
  30. 'title': 'fantasy solo',
  31. 'description': 'dillion harper masturbates on a bed',
  32. 'thumbnail': r're:^https?://.*\.jpg$',
  33. 'uploader': 'silly2587',
  34. 'timestamp': 1422571989,
  35. 'upload_date': '20150129',
  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 = re.match(self._VALID_URL, url)
  69. video_id = mobj.group('id') or mobj.group('id_2')
  70. webpage = self._download_webpage(
  71. url.replace('/%s/embed' % video_id, '/%s/video' % video_id),
  72. video_id, headers={'Cookie': 'country=US'})
  73. if re.search(r'<[^>]+\b(?:id|class)=["\']video_removed', webpage):
  74. raise ExtractorError(
  75. 'Video %s is not available' % video_id, 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. r'%s(?P<id>[^\s=]+)\s*=\s*(["\'])(?P<url>(?:(?!\2).)+)\2'
  99. % STREAM_URL_PREFIX, webpage):
  100. extract_format(mobj.group('id', 'url'))
  101. if not formats:
  102. stream_key = self._search_regex(
  103. r'data-streamkey\s*=\s*(["\'])(?P<value>(?:(?!\1).)+)\1',
  104. webpage, 'stream key', group='value')
  105. stream = self._download_json(
  106. 'https://spankbang.com/api/videos/stream', video_id,
  107. 'Downloading stream JSON', data=urlencode_postdata({
  108. 'id': stream_key,
  109. 'data': 0,
  110. }), headers={
  111. 'Referer': url,
  112. 'X-Requested-With': 'XMLHttpRequest',
  113. })
  114. for format_id, format_url in stream.items():
  115. if format_url and isinstance(format_url, list):
  116. format_url = format_url[0]
  117. extract_format(format_id, format_url)
  118. self._sort_formats(formats, field_preference=('preference', 'height', 'width', 'fps', 'tbr', 'format_id'))
  119. info = self._search_json_ld(webpage, video_id, default={})
  120. title = self._html_search_regex(
  121. r'(?s)<h1[^>]*>(.+?)</h1>', webpage, 'title', default=None)
  122. description = self._search_regex(
  123. r'<div[^>]+\bclass=["\']bottom[^>]+>\s*<p>[^<]*</p>\s*<p>([^<]+)',
  124. webpage, 'description', default=None)
  125. thumbnail = self._og_search_thumbnail(webpage, default=None)
  126. uploader = self._html_search_regex(
  127. (r'(?s)<li[^>]+class=["\']profile[^>]+>(.+?)</a>',
  128. r'class="user"[^>]*><img[^>]+>([^<]+)'),
  129. webpage, 'uploader', default=None)
  130. duration = parse_duration(self._search_regex(
  131. r'<div[^>]+\bclass=["\']right_side[^>]+>\s*<span>([^<]+)',
  132. webpage, 'duration', default=None))
  133. view_count = str_to_int(self._search_regex(
  134. r'([\d,.]+)\s+plays', webpage, 'view count', default=None))
  135. age_limit = self._rta_search(webpage)
  136. return merge_dicts({
  137. 'id': video_id,
  138. 'title': title or video_id,
  139. 'description': description,
  140. 'thumbnail': thumbnail,
  141. 'uploader': uploader,
  142. 'duration': duration,
  143. 'view_count': view_count,
  144. 'formats': formats,
  145. 'age_limit': age_limit,
  146. }, info
  147. )
  148. class SpankBangPlaylistIE(InfoExtractor):
  149. _VALID_URL = r'https?://(?:[^/]+\.)?spankbang\.com/(?P<id>[\da-z]+)/playlist/(?P<display_id>[^/]+)'
  150. _TEST = {
  151. 'url': 'https://spankbang.com/ug0k/playlist/big+ass+titties',
  152. 'info_dict': {
  153. 'id': 'ug0k',
  154. 'title': 'Big Ass Titties',
  155. },
  156. 'playlist_mincount': 40,
  157. }
  158. def _real_extract(self, url):
  159. mobj = re.match(self._VALID_URL, url)
  160. playlist_id = mobj.group('id')
  161. display_id = mobj.group('display_id')
  162. webpage = self._download_webpage(
  163. url, playlist_id, headers={'Cookie': 'country=US; mobile=on'})
  164. entries = [self.url_result(
  165. urljoin(url, mobj.group('path')),
  166. ie=SpankBangIE.ie_key(), video_id=mobj.group('id'))
  167. for mobj in re.finditer(
  168. r'<a[^>]+\bhref=(["\'])(?P<path>/?[\da-z]+-(?P<id>[\da-z]+)/playlist/%s(?:(?!\1).)*)\1'
  169. % re.escape(display_id), webpage)]
  170. title = self._html_search_regex(
  171. r'<h1>([^<]+)\s+playlist\s*<', webpage, 'playlist title',
  172. fatal=False)
  173. return self.playlist_result(entries, playlist_id, title)