spankwire.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_urllib_parse_unquote,
  6. compat_urllib_parse_urlparse,
  7. compat_urllib_request,
  8. )
  9. from ..utils import (
  10. str_to_int,
  11. unified_strdate,
  12. )
  13. from ..aes import aes_decrypt_text
  14. class SpankwireIE(InfoExtractor):
  15. _VALID_URL = r'https?://(?:www\.)?(?P<url>spankwire\.com/[^/]*/video(?P<videoid>[0-9]+)/?)'
  16. _TESTS = [{
  17. 'url': 'http://www.spankwire.com/Buckcherry-s-X-Rated-Music-Video-Crazy-Bitch/video103545/',
  18. 'md5': '8bbfde12b101204b39e4b9fe7eb67095',
  19. 'info_dict': {
  20. 'id': '103545',
  21. 'ext': 'mp4',
  22. 'title': 'Buckcherry`s X Rated Music Video Crazy Bitch',
  23. 'description': 'Crazy Bitch X rated music video.',
  24. 'uploader': 'oreusz',
  25. 'uploader_id': '124697',
  26. 'upload_date': '20070507',
  27. 'age_limit': 18,
  28. }
  29. },
  30. {
  31. 'url': 'http://www.spankwire.com/Titcums-Compiloation-I/video1921551/',
  32. 'md5': '09b3c20833308b736ae8902db2f8d7e6',
  33. 'info_dict': {
  34. 'id': '1921551',
  35. 'ext': 'mp4',
  36. 'title': 'Titcums Compiloation I',
  37. 'description': 'cum on tits',
  38. 'uploader': 'dannyh78999',
  39. 'uploader_id': '3056053',
  40. 'upload_date': '20150822',
  41. 'age_limit': 18,
  42. }
  43. }]
  44. def _real_extract(self, url):
  45. mobj = re.match(self._VALID_URL, url)
  46. video_id = mobj.group('videoid')
  47. url = 'http://www.' + mobj.group('url')
  48. req = compat_urllib_request.Request(url)
  49. req.add_header('Cookie', 'age_verified=1')
  50. webpage = self._download_webpage(req, video_id)
  51. title = self._html_search_regex(
  52. r'<h1>([^<]+)', webpage, 'title')
  53. description = self._html_search_regex(
  54. r'(?s)<div\s+id="descriptionContent">(.+?)</div>',
  55. webpage, 'description', fatal=False)
  56. thumbnail = self._html_search_regex(
  57. r'playerData\.screenShot\s*=\s*["\']([^"\']+)["\']',
  58. webpage, 'thumbnail', fatal=False)
  59. uploader = self._html_search_regex(
  60. r'by:\s*<a [^>]*>(.+?)</a>',
  61. webpage, 'uploader', fatal=False)
  62. uploader_id = self._html_search_regex(
  63. r'by:\s*<a href="/user/viewProfile\?.*?UserId=(\d+).*?"',
  64. webpage, 'uploader id', fatal=False)
  65. upload_date = unified_strdate(self._html_search_regex(
  66. r'</a> on (.+?) at \d+:\d+',
  67. webpage, 'upload date', fatal=False))
  68. view_count = str_to_int(self._html_search_regex(
  69. r'<div id="viewsCounter"><span>([\d,\.]+)</span> views</div>',
  70. webpage, 'view count', fatal=False))
  71. comment_count = str_to_int(self._html_search_regex(
  72. r'<span\s+id="spCommentCount"[^>]*>([\d,\.]+)</span>',
  73. webpage, 'comment count', fatal=False))
  74. video_urls = list(map(
  75. compat_urllib_parse_unquote,
  76. re.findall(r'playerData\.cdnPath[0-9]{3,}\s*=\s*(?:encodeURIComponent\()?["\']([^"\']+)["\']', webpage)))
  77. if webpage.find('flashvars\.encrypted = "true"') != -1:
  78. password = self._search_regex(
  79. r'flashvars\.video_title = "([^"]+)',
  80. webpage, 'password').replace('+', ' ')
  81. video_urls = list(map(
  82. lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'),
  83. video_urls))
  84. formats = []
  85. for video_url in video_urls:
  86. path = compat_urllib_parse_urlparse(video_url).path
  87. format = path.split('/')[4].split('_')[:2]
  88. if format[0] == 'mp4':
  89. format_id, quality = format
  90. format = "-".join(format)
  91. if quality == 'normal':
  92. height = 180
  93. elif quality == 'high':
  94. height = 240
  95. elif quality == 'ultra':
  96. height = 480
  97. elif quality == '720p':
  98. height = 720
  99. formats.append({
  100. 'url': video_url,
  101. 'format': format,
  102. 'height': height,
  103. 'format_id': format,
  104. })
  105. else:
  106. resolution, bitrate_str = format
  107. format = "-".join(format)
  108. height = int(resolution.rstrip('Pp'))
  109. tbr = int(bitrate_str.rstrip('Kk'))
  110. formats.append({
  111. 'url': video_url,
  112. 'resolution': resolution,
  113. 'format': format,
  114. 'tbr': tbr,
  115. 'height': height,
  116. 'format_id': format,
  117. })
  118. self._sort_formats(formats)
  119. age_limit = self._rta_search(webpage)
  120. return {
  121. 'id': video_id,
  122. 'title': title,
  123. 'description': description,
  124. 'thumbnail': thumbnail,
  125. 'uploader': uploader,
  126. 'uploader_id': uploader_id,
  127. 'upload_date': upload_date,
  128. 'view_count': view_count,
  129. 'comment_count': comment_count,
  130. 'formats': formats,
  131. 'age_limit': age_limit,
  132. }