logo

youtube-dl

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

spankwire.py (6475B)


  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. float_or_none,
  6. int_or_none,
  7. merge_dicts,
  8. str_or_none,
  9. str_to_int,
  10. url_or_none,
  11. )
  12. class SpankwireIE(InfoExtractor):
  13. _VALID_URL = r'''(?x)
  14. https?://
  15. (?:www\.)?spankwire\.com/
  16. (?:
  17. [^/]+/video|
  18. EmbedPlayer\.aspx/?\?.*?\bArticleId=
  19. )
  20. (?P<id>\d+)
  21. '''
  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. @staticmethod
  66. def _extract_urls(webpage):
  67. return re.findall(
  68. r'<iframe[^>]+\bsrc=["\']((?:https?:)?//(?:www\.)?spankwire\.com/EmbedPlayer\.aspx/?\?.*?\bArticleId=\d+)',
  69. webpage)
  70. def _real_extract(self, url):
  71. video_id = self._match_id(url)
  72. video = self._download_json(
  73. 'https://www.spankwire.com/api/video/%s.json' % video_id, video_id)
  74. title = video['title']
  75. formats = []
  76. videos = video.get('videos')
  77. if isinstance(videos, dict):
  78. for format_id, format_url in videos.items():
  79. video_url = url_or_none(format_url)
  80. if not format_url:
  81. continue
  82. height = int_or_none(self._search_regex(
  83. r'(\d+)[pP]', format_id, 'height', default=None))
  84. m = re.search(
  85. r'/(?P<height>\d+)[pP]_(?P<tbr>\d+)[kK]', video_url)
  86. if m:
  87. tbr = int(m.group('tbr'))
  88. height = height or int(m.group('height'))
  89. else:
  90. tbr = None
  91. formats.append({
  92. 'url': video_url,
  93. 'format_id': '%dp' % height if height else format_id,
  94. 'height': height,
  95. 'tbr': tbr,
  96. })
  97. m3u8_url = url_or_none(video.get('HLS'))
  98. if m3u8_url:
  99. formats.extend(self._extract_m3u8_formats(
  100. m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native',
  101. m3u8_id='hls', fatal=False))
  102. self._sort_formats(formats, ('height', 'tbr', 'width', 'format_id'))
  103. view_count = str_to_int(video.get('viewed'))
  104. thumbnails = []
  105. for preference, t in enumerate(('', '2x'), start=0):
  106. thumbnail_url = url_or_none(video.get('poster%s' % t))
  107. if not thumbnail_url:
  108. continue
  109. thumbnails.append({
  110. 'url': thumbnail_url,
  111. 'preference': preference,
  112. })
  113. def extract_names(key):
  114. entries_list = video.get(key)
  115. if not isinstance(entries_list, list):
  116. return
  117. entries = []
  118. for entry in entries_list:
  119. name = str_or_none(entry.get('name'))
  120. if name:
  121. entries.append(name)
  122. return entries
  123. categories = extract_names('categories')
  124. tags = extract_names('tags')
  125. uploader = None
  126. info = {}
  127. webpage = self._download_webpage(
  128. 'https://www.spankwire.com/_/video%s/' % video_id, video_id,
  129. fatal=False)
  130. if webpage:
  131. info = self._search_json_ld(webpage, video_id, default={})
  132. thumbnail_url = None
  133. if 'thumbnail' in info:
  134. thumbnail_url = url_or_none(info['thumbnail'])
  135. del info['thumbnail']
  136. if not thumbnail_url:
  137. thumbnail_url = self._og_search_thumbnail(webpage)
  138. if thumbnail_url:
  139. thumbnails.append({
  140. 'url': thumbnail_url,
  141. 'preference': 10,
  142. })
  143. uploader = self._html_search_regex(
  144. r'(?s)by\s*<a[^>]+\bclass=["\']uploaded__by[^>]*>(.+?)</a>',
  145. webpage, 'uploader', fatal=False)
  146. if not view_count:
  147. view_count = str_to_int(self._search_regex(
  148. r'data-views=["\']([\d,.]+)', webpage, 'view count',
  149. fatal=False))
  150. return merge_dicts({
  151. 'id': video_id,
  152. 'title': title,
  153. 'description': video.get('description'),
  154. 'duration': int_or_none(video.get('duration')),
  155. 'thumbnails': thumbnails,
  156. 'uploader': uploader,
  157. 'uploader_id': str_or_none(video.get('userId')),
  158. 'timestamp': int_or_none(video.get('time_approved_on')),
  159. 'average_rating': float_or_none(video.get('rating')),
  160. 'view_count': view_count,
  161. 'comment_count': int_or_none(video.get('comments')),
  162. 'age_limit': 18,
  163. 'categories': categories,
  164. 'tags': tags,
  165. 'formats': formats,
  166. }, info)