spankwire.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. float_or_none,
  5. int_or_none,
  6. merge_dicts,
  7. str_or_none,
  8. str_to_int,
  9. url_or_none,
  10. )
  11. class SpankwireIE(InfoExtractor):
  12. _VALID_URL = r'''(?x)
  13. https?://
  14. (?:www\.)?spankwire\.com/
  15. (?:
  16. [^/]+/video|
  17. EmbedPlayer\.aspx/?\?.*?\bArticleId=
  18. )
  19. (?P<id>\d+)
  20. '''
  21. _EMBED_REGEX = [r'<iframe[^>]+\bsrc=["\'](?P<url>(?:https?:)?//(?:www\.)?spankwire\.com/EmbedPlayer\.aspx/?\?.*?\bArticleId=\d+)']
  22. _TESTS = [{
  23. # download URL pattern: */<height>P_<tbr>K_<video_id>.mp4
  24. 'url': 'http://www.spankwire.com/Buckcherry-s-X-Rated-Music-Video-Crazy-Bitch/video103545/',
  25. 'md5': '5aa0e4feef20aad82cbcae3aed7ab7cd',
  26. 'info_dict': {
  27. 'id': '103545',
  28. 'ext': 'mp4',
  29. 'title': 'Buckcherry`s X Rated Music Video Crazy Bitch',
  30. 'description': 'Crazy Bitch X rated music video.',
  31. 'duration': 222,
  32. 'uploader': 'oreusz',
  33. 'uploader_id': '124697',
  34. 'timestamp': 1178587885,
  35. 'upload_date': '20070508',
  36. 'average_rating': float,
  37. 'view_count': int,
  38. 'comment_count': int,
  39. 'age_limit': 18,
  40. 'categories': list,
  41. 'tags': list,
  42. },
  43. }, {
  44. # download URL pattern: */mp4_<format_id>_<video_id>.mp4
  45. 'url': 'http://www.spankwire.com/Titcums-Compiloation-I/video1921551/',
  46. 'md5': '09b3c20833308b736ae8902db2f8d7e6',
  47. 'info_dict': {
  48. 'id': '1921551',
  49. 'ext': 'mp4',
  50. 'title': 'Titcums Compiloation I',
  51. 'description': 'cum on tits',
  52. 'uploader': 'dannyh78999',
  53. 'uploader_id': '3056053',
  54. 'upload_date': '20150822',
  55. 'age_limit': 18,
  56. },
  57. 'params': {
  58. 'proxy': '127.0.0.1:8118'
  59. },
  60. 'skip': 'removed',
  61. }, {
  62. 'url': 'https://www.spankwire.com/EmbedPlayer.aspx/?ArticleId=156156&autostart=true',
  63. 'only_matching': True,
  64. }]
  65. def _real_extract(self, url):
  66. video_id = self._match_id(url)
  67. video = self._download_json(
  68. 'https://www.spankwire.com/api/video/%s.json' % video_id, video_id)
  69. title = video['title']
  70. formats = []
  71. videos = video.get('videos')
  72. if isinstance(videos, dict):
  73. for format_id, format_url in videos.items():
  74. video_url = url_or_none(format_url)
  75. if not format_url:
  76. continue
  77. height = int_or_none(self._search_regex(
  78. r'(\d+)[pP]', format_id, 'height', default=None))
  79. m = re.search(
  80. r'/(?P<height>\d+)[pP]_(?P<tbr>\d+)[kK]', video_url)
  81. if m:
  82. tbr = int(m.group('tbr'))
  83. height = height or int(m.group('height'))
  84. else:
  85. tbr = None
  86. formats.append({
  87. 'url': video_url,
  88. 'format_id': '%dp' % height if height else format_id,
  89. 'height': height,
  90. 'tbr': tbr,
  91. })
  92. m3u8_url = url_or_none(video.get('HLS'))
  93. if m3u8_url:
  94. formats.extend(self._extract_m3u8_formats(
  95. m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native',
  96. m3u8_id='hls', fatal=False))
  97. view_count = str_to_int(video.get('viewed'))
  98. thumbnails = []
  99. for preference, t in enumerate(('', '2x'), start=0):
  100. thumbnail_url = url_or_none(video.get('poster%s' % t))
  101. if not thumbnail_url:
  102. continue
  103. thumbnails.append({
  104. 'url': thumbnail_url,
  105. 'preference': preference,
  106. })
  107. def extract_names(key):
  108. entries_list = video.get(key)
  109. if not isinstance(entries_list, list):
  110. return
  111. entries = []
  112. for entry in entries_list:
  113. name = str_or_none(entry.get('name'))
  114. if name:
  115. entries.append(name)
  116. return entries
  117. categories = extract_names('categories')
  118. tags = extract_names('tags')
  119. uploader = None
  120. info = {}
  121. webpage = self._download_webpage(
  122. 'https://www.spankwire.com/_/video%s/' % video_id, video_id,
  123. fatal=False)
  124. if webpage:
  125. info = self._search_json_ld(webpage, video_id, default={})
  126. thumbnail_url = None
  127. if 'thumbnail' in info:
  128. thumbnail_url = url_or_none(info['thumbnail'])
  129. del info['thumbnail']
  130. if not thumbnail_url:
  131. thumbnail_url = self._og_search_thumbnail(webpage)
  132. if thumbnail_url:
  133. thumbnails.append({
  134. 'url': thumbnail_url,
  135. 'preference': 10,
  136. })
  137. uploader = self._html_search_regex(
  138. r'(?s)by\s*<a[^>]+\bclass=["\']uploaded__by[^>]*>(.+?)</a>',
  139. webpage, 'uploader', fatal=False)
  140. if not view_count:
  141. view_count = str_to_int(self._search_regex(
  142. r'data-views=["\']([\d,.]+)', webpage, 'view count',
  143. fatal=False))
  144. return merge_dicts({
  145. 'id': video_id,
  146. 'title': title,
  147. 'description': video.get('description'),
  148. 'duration': int_or_none(video.get('duration')),
  149. 'thumbnails': thumbnails,
  150. 'uploader': uploader,
  151. 'uploader_id': str_or_none(video.get('userId')),
  152. 'timestamp': int_or_none(video.get('time_approved_on')),
  153. 'average_rating': float_or_none(video.get('rating')),
  154. 'view_count': view_count,
  155. 'comment_count': int_or_none(video.get('comments')),
  156. 'age_limit': 18,
  157. 'categories': categories,
  158. 'tags': tags,
  159. 'formats': formats,
  160. }, info)